Lab Report # 7
Lab Report # 7
TECHNOLOGY ISLAMABAD
LAB REPORT # 07
MULTI RATE SIGNAL PROSESSING
COURSE INSTRUCTOR:
SIR MUMTAZ ALI
SUBMITTED TO:
SIR MUBIN SABIR
SUBMITTED BY:
MUHAMMAD SHAHZAD AKHTAR
SP08-BET-062
TASK NO 1:
Use your sinegen function to generate a sinewave with f=3kHz and fs=8kHz.
Calculate its fft with zero frequency component in the middle.Plot it on a properly
scaled w-axis
(a)Code:
fm=3000;
fs=8000;
N=1000;
[y,t]=singen(fm,fs,N);
subplot(211)
plot(t,y), legend('Sinusoid')
y1=fft(y);
w=fs/2*(linspace(-1,1,length(y1)));
subplot(212)
plot(w,fftshift(abs(y1))), legend('fft')
xlim([-4000 4000])
function [y,n]=singen(fm,fs,N)
n=0:1:N-1;
y=sin(2*pi*(fm/fs)*n);
Results:
1
Sinusoid
0.5
-0.5
-1
0 100 200 300 400 500 600 700 800 900 1000
500
fft
400
300
200
100
0
-4000 -3000 -2000 -1000 0 1000 2000 3000 4000
TASK NO 2:
Decimate the signal in task 1 with ‘M = 2’ and plot
the resultant signal. Give your observations about
the plots in your reports
Code:
fm=3000;
fs=8000;
N=1000;
[y,t]=singen(fm,fs,N);
subplot(311)
plot(t,y), legend('Sinusoid')
y1=fft(y,512);
w=fs/2*(linspace(-1,1,512));
subplot(312)
plot(w,fftshift(abs(y1))), legend('fft')
R=2;
y2= decimate(y,R);
y3=fft(y2,512);
subplot(313)
w=fs/2*(linspace(-1,1,512));
plot(w,abs(fftshift(y3))),legend('decimated fft')
function [y,n]=singen(fm,fs,N)
n=0:N-1;
y=sin(2*pi*(fm/fs)*n);
Results:
Decimated graph is not correct because the sampling frequency after decimation not
fulfilling the nyqusite criteria.
1
Sinusoid
0
-1
0 100 200 300 400 500 600 700 800 900 1000
300
fft
200
100
0
-4000 -3000 -2000 -1000 0 1000 2000 3000 4000
1.5
decimated fft
1
0.5
-4000 -3000 -2000 -1000 0 1000 2000 3000 4000
TASK NO 3:
Repeat task 2 for following signals:
a) x1[n] = cos(2*pi*f0/fs*n)+cos(2*pi*f1/fs*n)
• f0 = 2kHz; f1 = 6kHz; fs = 10kHz;
b) x2[n] = cos(2*pi*f0/fs*n)+cos(2*pi*f1/fs*n)+ cos(2*pi*f1/fs*n)
• f0 = 2kHz; f1 = 4kHz; f2 = 3kHz; fs = 10kHz;
Explain which components will be aliased & why?
Code:
f0=2e3;
f1=6000;
fs=10e3;
N=1000;
n=0:N-1;
R=2;
subplot(611)
x1=cos(2*pi*f0/fs*n)+cos(2*pi*f1/fs*n);
plot(n,x1), legend('x1')
x2=fft(x1);
subplot(612)
w=fs/2*linspace(-1,1,length(x2));
plot(w,fftshift(abs(x2))),legend('x1(w)')
x3=decimate(x1,R);
x4=fft(x3);
subplot(613)
w=fs/2*linspace(-1,1,length(x4));
plot(w,fftshift(abs(x4))),legend('deci x1(w)')
f0=2e3;
f1=4e3;
f2=3e3;
fs=10e3;
subplot(614)
y=cos(2*pi*f0/fs*n)+cos(2*pi*f1/fs*n)+ cos(2*pi*f2/fs*n);
plot(n,y), legend('x2')
y1=fft(y);
subplot(615)
y2=decimate(y,R);
y3=fft(y2);
w=fs/2*linspace(-1,1,length(y1));
plot(w,fftshift(abs(y1))),legend('x2(w)')
xlim([-5000 5000])
subplot(616)
w=fs/2*linspace(-1,1,length(y3));
plot(w,fftshift(abs(y3))),legend('deci x2(w)')
xlim([-9000 9000])
Results:
2
0 x1
-2
0 100 200 300 400 500 600 700 800 900 1000
1000
500 x1(w)
0
-5000 -4000 -3000 -2000 -1000 0 1000 2000 3000 4000 5000
400
200 deci x1(w)
0
-5000 -4000 -3000 -2000 -1000 0 1000 2000 3000 4000 5000
5
0 x2
-5
0 100 200 300 400 500 600 700 800 900 1000
1000
500 x2(w)
0
-5000 -4000 -3000 -2000 -1000 0 1000 2000 3000 4000 5000
400
200 deci x2(w)
0
-8000 -6000 -4000 -2000 0 2000 4000 6000 8000
As the frequencies are 2k,6k and fs=10k. So by applying Nyquiste criteria we get to
know that the aliasing will be happened when sampling it, that’s why the 6k frequency
signal is not sampled correctly.
Fs’=fs/2=5k is the new sampling frequency so after sampling the fm=2k will decimate
correctly and the other will not.
As the frequencies are 2k,3k,4k and fs=10k. So its fulfill the Nyquiste criteria, So all the
frequencies will sampled correctly.
Fs’=fs/2=5k is the new sampling frequency so after sampling the fm=2k will decimate
correctly and the other will not.