You are on page 1of 9

Assignment -1

Course: Digital Signal Processing


Name: Balakrishnan Arumugam
Roll number : 2018PA01046

Q1: Write the Matlab code and compute and plot for following inputs using Matlab

1. |X(k)| and |X(w)| for


1) M=5, N=5;
2) M=5, N=10;
3) M=20, N=10;
Comment on the result.

Solution :
1. M=5, N=5
2. M=5, N=10
3. M=20, N=10

clc; clear; close all


M=5;
N=5;
w=linspace(-2*pi,2*pi,800);
X_dtft=(sin(w*M/2) ./ sin(w/2)) .* exp(-1j * w * (M-1)/2);
P=N;
x=ones(1,M);
Xp=fft(x,P);
w_k=(0:P-1) * (2*pi/P);
X=fft(x);
plot(w,abs(X_dtft))
hold on
plot(w_k,abs(Xp), 'O')
xlabel('-2\pi \leq x \leq 2\pi')
ylabel('|X(k)|,|X(w)|','color','b')
hold off
grid on
grid minor
Solution 2:

clc; clear; close all


M=5;
N=10;
w=linspace(-2*pi,2*pi,800);
X_dtft=(sin(w*M/2) ./ sin(w/2)) .* exp(-1j * w * (M-1)/2);
P=N;
x=ones(1,M);
Xp=fft(x,P);
w_k=(0:P-1) * (2*pi/P);
X=fft(x);
plot(w,abs(X_dtft))
hold on
plot(w_k,abs(Xp), 'O')
xlabel('-2\pi \leq x \leq 2\pi')
ylabel('|X(k)|,|X(w)|','color','b')
hold off
grid on
grid minor
Solution : 3

clc; clear; close all


M=20;
N=10;
w=linspace(-2*pi,2*pi,800);
X_dtft=(sin(w*M/2) ./ sin(w/2)) .* exp(-1j * w * (M-1)/2);
P=N;
x=ones(1,M);
Xp=fft(x,P);
w_k=(0:P-1) * (2*pi/P);
X=fft(x);
plot(w,abs(X_dtft))
hold on
plot(w_k,abs(Xp), 'O')
xlabel('-2\pi \leq x \leq 2\pi')
ylabel('|X(k)|,|X(w)|','color','b')
hold off
grid on
grid minor
Result Interpretation.
1. The approximation improves with taking more samples or applying Zero
padding to the samples.
2. As the value of N increases, which signifies more sampling points , it will have
better approximation & representation in the FFT

---------------------------------------------------------------------------------------

Question2:
X(N)= δ(n)-3 δ(n-1)+5 δ(n-2)+2 δ(n-3)-3 δ(n-5)+ δ(n-7) Find X(K) in matlab using 8 point fft. Compute and
display output of each stage using Radix 2.

clc; clear; close all


x=[1 -3 5 2 0 -3 0 1]
N=length(x);
S=log2(N); Half=N/2; for stage=1:S;
for index=0:(N/(2^(stage-1))):(N-1); for n=0:(Half-1); pos=n+index+1;
pow=(2^(stage-1))*n;
w=exp((-1i)*(2*pi)*pow/N);
a=x(pos)+x(pos+Half); b=(x(pos)-x(pos+Half)).*w;
x(pos)=a; x(pos+Half)=b; end;
end;
Half=Half/2;
x1=bitrevorder(x);
disp(x1);
end;
y=bitrevorder(x);
k=0:N-1;
subplot(2,1,1)
stem(k,abs(y));
xlabel('k')
ylabel('|y|');
title('MAGNITUDE');
subplot(2,1,2)
stem(k,angle(y));
xlabel('K');
ylabel('Angle in radians')
title('PHASE PLOT');

You might also like