0
$\begingroup$

We have an expression shown in red bellow for non ideal DAC ZOH,which links the sampling frequency to the amplitude loss of the input signal. I took $f_b=1kHz$ and $f_{noise}=4kHz$ $f_{in}=f_b+f_{noise}.$ Our ADC is a sinc function with $x=10kHz$ so I did a convolution for out_put_ADC=conv(fin,sinc). And basically that is the point i got stuck with the MATLAB code shown bellow. If everything was correct till this point how to implement the DAC so we will witness the amplitude deterioration formula of ZOH as a function of sampling frequency? Thanks.

enter image description here

x=0.0001:0.0001:1; %10KHz ADC sampling

ADC_response = sinc(x);

fb=1e3;  %1Khz frequency

f_noise=4e3;  %1Khz frequency

yb=sin(2*pi*fb*x); %1Khz frequency sine input signal

yf_noise=sin(2*pi*4*fb*x); %4Khz frequency sine input noise

y_in=yb+yf_noise;%total signal going into the ADC

ADC_out=conv(y_in,ADC_response);%signal after ADC
$\endgroup$
6
  • $\begingroup$ Before answering the question, I am wondering why you simulate the ADC as Sinc Function? According to the bible of DSP written by A. Oppenheim, ADC seems to be a cascade of quantizer and sampler. $\endgroup$ – Po-wei Huang Apr 25 '20 at 15:29
  • $\begingroup$ Here is my experiment on ADC/DAC (quantizer is temporary skipped) poweidsplearningpath.blogspot.com/2020/04/… $\endgroup$ – Po-wei Huang Apr 25 '20 at 15:30
  • $\begingroup$ In your case, x seems to be continuous time (t), not samples number such as n (1,2,3,4). I cannot understand the usage of sinc(x), yb = sin(2*pifbx)?!? Maybe you can try my link. An analog input signal is initially given. An then I sample the continuous into discrete time via down sample. $\endgroup$ – Po-wei Huang Apr 25 '20 at 15:37
  • $\begingroup$ I need to create a ZOH signal from my sampled signal after ADC. How do i create this continues step picture with sinc function? Thanks. [code] x=0.0001:0.0001:1; %10KHz ADC sampling yb=sin(2*pifbx); %1Khz frequency sine input signal yf_noise=sin(2*pi*4*fb*x); %4Khz frequency sine input noise y_in=yb+yf_noise;%total signal going into the ADC [/code] $\endgroup$ – rocko445 Apr 25 '20 at 15:43
  • $\begingroup$ What you mean may be the 'anti-aliasing' filter in front of ADC, because ADC is not a filter. In fact, you cannot simply simulate the ADC output via a convolution like ADC_out=conv(y_in,ADC_response); So, in your code you have sampled the signal, and the quantization effect is ignored. What you want is the ZOH signal, am I right? $\endgroup$ – Po-wei Huang Apr 25 '20 at 15:53
1
$\begingroup$

Here is the entire simulation code. First, to verify the spectrum response of ZOH, I replaced the DAC_output with an impulse signal. So I can directly check if the simulation confirms the theory or not. ( As ZOH is a kind of LTI filter, the spectrum of impulse response represents the frequency response of this system. You can try other input signals like the one you originally provided.)

Input test signal: enter image description here

Output Spectrum: Note that theory spectrum entirely cover the simulated spectrum.

enter image description here

Ps. DAC is simulated via an up sampling and a convolution with hold filter, h = ones(1, sample_hold)

A very high pseudo analog sample frequency should be given because there is no real 'analog' in computer simulation.

You can alter different Tp or Ts (not lower than analog pseudo freq.). These codes should work.

There are some rooms for improvement about the ADC process you provided in question. You can refer the my blog.

clear all;
close all;

end_time = 2e-2;
x=0.0001:0.0001:end_time; %10KHz ADC sampling 

ADC_response = sinc(x); %% Please check the frequency response!!

fb=1e3;  %1Khz frequency

f_noise=4e3;  %1Khz frequency

yb=sin(2*pi*fb*x); %1Khz frequency sine input signal

yf_noise=sin(2*pi*4*fb*x); %4Khz frequency sine input noise

y_in=yb+yf_noise;%total signal going into the ADC

ADC_out=conv(y_in,ADC_response);%signal after ADC

%% Started here.

% ADC_out = ADC_out(1:length(y_in)); % trim for same length

ADC_out = zeros(1,length(y_in));
ADC_out(length(y_in)/2) = 1; % impulse

%% pseudo analog frequency & ZOH simulation
% parameters
analog_sampling_rate = 1e8; % 100 MHz.
digital_sampling_rate = 1e4; % according to question.

%% Important Time Parameters
Ts = 1/digital_sampling_rate; % 1e-4 as given.
Tp = 2e-5; % ZOH time in analog unit (sec), tunnable. 
hold_sample = round(Tp*analog_sampling_rate); 
%  This indicates how many samples need to be hold in this pesudo analog simulation.

%% DAC Processing 
t = 0:1/analog_sampling_rate:end_time-1/analog_sampling_rate; % pseudo analog time.

% upsampling
y_up = upsample(ADC_out,analog_sampling_rate/digital_sampling_rate);

% zero order hold filter
h = ones(1,hold_sample); % zero order hold

% filter your signal
y_zoh = filter(h,1,y_up);
y_zoh(1:floor(mean(grpdelay(h))))=[];
y_zoh = [y_zoh zeros(1,floor(mean(grpdelay(h))))];

%% Time domain plot
figure;
plot(x,ADC_out);
hold on;
plot(t,y_zoh);    
legend('yb','y_zoh');

%% Freq response of discrete time signal and freq unit conversion
d_N = length(ADC_out);
d_F = fft(ADC_out,d_N);
d_freq_step = digital_sampling_rate/d_N;
d_freq = -digital_sampling_rate/2:d_freq_step:digital_sampling_rate/2-d_freq_step;
d_freq = d_freq(d_N/2+1:end)';

%% Freq response of psudo analog time signal and freq unit conversion
c_N = length(y_zoh);
c_F = fft(y_zoh,c_N);
c_freq_step = analog_sampling_rate/c_N;
c_freq = -analog_sampling_rate/2:c_freq_step:analog_sampling_rate/2-c_freq_step;
c_freq = c_freq(c_N/2+1:end)';

%% Theory transform of DAC Transfer function.

c_thy_F = abs(sinc(c_freq*Tp)*Tp/Ts); %% For verification.

%% Plot Freq domain comparison.

figure;
plot(d_freq,abs(d_F(1:d_N/2))/d_N);
xlabel('Freq. (Hz)');

figure;
plot(c_freq,abs(c_F(1:c_N/2))*d_N/c_N);
hold on;
plot(c_freq,c_thy_F);
xlabel('Freq. (Hz)');
legend('simulated','theory');
$\endgroup$
1
  • $\begingroup$ Hello, how does zero padding and FIR filter reconstructs our analog signal? Thanks. %% DAC % up sample / DAC x_up = upsample(x_d,analog_fps/digital_fps); % LPF (Reconstruction Filters) h = intfilt(analog_fps/digital_fps,4,0.9); $\endgroup$ – rocko445 Apr 28 '20 at 17:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.