Lab 4 Matlab
Lab 4 Matlab
LAB 4
ALIASING
OBJECTIVE:
To investigate sampling of continuous-time signals and the effects of aliasing. This lab covers
sampling and aliasing due to undersampling.
x(t)=sin(ot).
is sampled with the frequency s=2fs, then the discrete-time signal x[n] = x(nTs) is given by
x[n]=sin(onTs).
Question 1:
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.
MATLAB has a function sound() that can convert a discrete signal sequence into continuous-
time sounds. We can use it to demonstrate the effect of aliasing very easily.
Use the method in Question 1 to construct sinusoidal signals with the frequencies 1000Hz,
2000Hz, 3000Hz. 40001Hz, 5000Hz and 6000Hz respectively. Then use the command
sound(x,fs) to “play” these sequences one by one, where x is the sequence and fs is defined as
8192 Hz. Listen to the pitch of the tone every time carefully.
Question 2:
1. Does the pitch of the tone that you hear increase with each increase in the
frequency Q0?
2. If not, can you explain this behavior?
As an example, we introduce the “chirp” phenomena where the instantaneous frequency of some
special signal will increase over time. Consider the signal
1
x (t ) sin o t t 2
2
For Question 3, set o = 2(3000) rad/sec and = 2000 rad/sec2.
Question 3:
1. Store in the vector x the samples of the chirp signal on the interval 0t1, 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.