Professional Documents
Culture Documents
Introduction:
In order to perform digital processing of analog signals, you need to do analog to discrete
conversion. The first step in A/D conversion is CT to DT conversion, which is the objective of
this lab.
1: Nyquist-Shannon sampling theorem: States that perfect reconstruction of a signal is
possible when the sampling frequency is greater than the twice the maximum frequency of the
signal being sampled. If lower sampling rates are used, the original signals information may not
be completely recovered from the sampled signal.
For example if a signal has an upper band limit of 100 hz, a sampling frequency greater than 200
hz will avoid aliasing and allow theoretically perfect reconstruction.
Fs >= 2 Fmax
2: Aliasing Effect: Aliasing is the phenomenon that results in loss of information when a
CT signal is reconstructed from its sampled values. In principle the original analog signal can be
reconstructed back from the samples and aliasing can be avoided, provided that Nyquist
sampling theorem was not violated while sampling i.e. the sampling rate was at least twice the
frequency of the highest frequency components present in the signal.
Sampling of Sinusoidal signal:
%original analog signal
t=0:0.0005:1;
F=13;
xa=cos(2*pi*F*t);
subplot(2,1,1)
plot(t,xa);
grid on;
xlabel('Time, sec')
ylabel('Amplitude')
title('continuous time original signal')
axis([0 1 -1.2 1.2])
% sampled signal
T=0.1;
n=0:T:1;
xs=cos(2*pi*F*n);
k=0:length(n)-1;
subplot(2,1,2)
stem(k,xs);
grid on;
xlabel('Time index n')
ylabel('Amplitude')
title('Sampled signal')
Aliasing Effect:
%original analog signal
t=0:0.0005:1;
F=13;
xa=cos(2*pi*F*t);
subplot(2,1,1)
plot(t,xa);
grid on;
xlabel('Time, sec')
ylabel('Amplitude')
title('continuous time original signal')
axis([0 1 -1.2 1.2])
% Reconstructed signal with aliasing effect
T=1/(13*1.5);
n=(0:T:1)';
xs=cos(2*pi*F*n);
t=(-0.5:0.004:1.5)';
%Reconstruction low pass filter, implemented in time domain
Ya=sinc((1/T)*t(:,ones(size(n)))-(1/T)*n(:,ones(size(t)))')*xs;
subplot(2,1,2)
plot(n,xs,'o',t,Ya);
grid on;
xlabel('Time seconds')
ylabel('Amplitude')
title('Reconstructed signal')
axis([0 1 -1.2 1.2])
Question 1:
In the above sampling topic plot the sampled signal for the remaining two cases.
1: Take sampling frequency exact 2 times the original frequency.
2: Take sampling frequency 2.5 times the maximum frequency.
Question 2:
Reconstruct the original signal without aliasing. Take sampling frequency of your own choice.
Question 3:
I. Oversampling.
a. Using MATLAB, create a sinusoidal signal with the frequency 1000 Hz.
b. Sample it at 8000 Hz and collect 512 (28) samples.
c. Using a subplot with 2 rows and 2 columns, plot the waveform in the subplot on
the first row and first column.
d. Set the axis so that you get three waves.
e. Convert from the time domain to frequency domain by taking the Fourier
Transform.
f. Plot the FFT vs. frequency.
f=1000; %frequency of the sine wave
fs=8000; %sampling frequency
Ts=1/fs; %sampling time
Ns=512; %512 points
t= [0:Ts:Ts*(Ns-1)]; %50/8000~6.25ms
x=sin(2*pi*f*t); %sine function for 50 samples
subplot(2,2,1),plot(t,x)
grid on; %plot of the sine wave
axis([0,.003,-1.2,1.2]) %set the x,y axis
X=(abs(fft(x,Ns))); %take the FFT
y=X(1:length(X)/2);
f=(1:length(y));
subplot(2,1,2),plot(f*fs/Ns,y);
grid on;
II. Undersampling.
Question 4:
1. Store in the vector x the samples of the chirp signal on the interval 0
t
1, and let T
is the same value as above.
2. Use sound(x,fs) to play the chirp signal contained in x. Can you explain what you
just heard?
3. Can you predict the time at which the played signal has zero (or very low)
frequency? Use a longer x sequence to verify your prediction.
5.1 Enter the code in a script file named sineGen.m and verify that what you get on the plot
really is a sampled 40Hz cosine wave. You should be able to identify the outline of the
sinusoid.
5.2 Now plot the signal using the plot function. This connects the points with a straight line and
can be considered to be a form of signal reconstruction. It is not optimal but it is sufficient
here.
5.3 Modify the code to generate sampled cosines at signal frequencies of 200Hz, 400Hz, 600Hz
and 800Hz, with durations of 1 second but still a sampling frequency, fs, of 1kHz. In each
case, generate plots of the first few oscillations of the signals using stem and plot on the same
figure.
5.4 Add a plot of the signal sampled at 10000Hz (this is highly over sampled and can be viewed
as a good approximation to the analogue signal).
soundsc(interp(x,8),8*fs);
This plays the signal x assuming a sampling frequency of fs (the code actually interpolates the
signal and uses a sampling frequency of 8*fs). Can you explain what you hear?