Write a program to compute the N-point inverse-DFT (IDFT) of a sequence. DO not use the inbuilt command. Test your program on the DFTs of the sequences in the previous part.
close all;
clear all;
t = (-1:1:10);
unitstep = t>=4;
x=unitstep;
L=length(x);
D_x=zeros(1,L);
Inv_D_x=zeros(1,L);
i=sqrt(-1);
for k=0:L-1
for n=0:L-1
D_x(k+1)=D_x(k+1)+(x(n+1)*exp((-i)*2*pi*k*n/L));
end
end
t=0:L-1;
subplot(2,2,1);
stem(t,x);
title('Original signal x[n]')
ylabel ('Amplitude');
grid
xlabel ('Time (sec)');
MAG=abs(D_x);
t=0:L-1;
subplot(2,2,2);
stem(t,MAG);
title('Magnitude Response')
ylabel ('Amplitude');
grid
xlabel ('Samples (K)');
Phi=angle(D_x);
t=0:L-1;
subplot(2,2,3);
stem(t,Phi);
title('Phase Response')
ylabel ('Phase');
grid
xlabel ('Samples (K)');
for n=0:L-1
for k=0:L-1
Inv_D_x(n+1)=Inv_D_x(n+1)+(D_x(k+1)*exp(i*2*pi*k*n/L));
end
end
Inv_D_x=Inv_D_x./L;
t=0:L-1;
subplot(2,2,4);
stem(t,Inv_D_x);
title('Inverse DFT signal x_hat[n]')
ylabel ('Amplitude');
grid
xlabel ('Time ');
Comments
Leave a comment