5. To find N point DFT and plot its magnitude and phase spectra. To find N point DFT and plot its magnitude and phase spectra.
Code:
//To calculate DFT of the sequence:
clear all;
clc;
close;
x=input(" Input sequence x :- ")
nl=input("length of input sequence :- ")
if length(x)<nl then
x=[x zeros(1,nl-length(x))]
end
n=0:nl-1;
k=0:nl-1;
//dft
Xdft= x*exp(-%i*((2*%pi)/nl)* k'*n); //dft formula
Xdft1=fft(x); // direct Command
//Idft
Xidft = (Xdft*exp(%i*((2*%pi)/nl)* k'*n))/nl; //idft formula
Xidft1=ifft(X); /// direct command
figure(1);
//input sequence
subplot(2,2,1);
a=gca();
a.x_location="origin";
a.y_location="origin";
plot2d3(n,x)
ylabel("x[n]");
xlabel("n");
title("Input sequence");
//DFT sequence 'Xdft'
subplot(2,2,2);
a=gca();
a.x_location="origin";
a.y_location="origin";
plot2d3(k,Xdft)
ylabel("Y[k]");
xlabel("k");
title("DFT sequence");
//IDFT sequence 'Xidft'
subplot(2,2,3);
a=gca();
a.x_location="origin";
a.y_location="origin";
plot2d3(n,Xidft)
ylabel("X[n]");
xlabel("n");
title("IDFT sequence");
disp("Input Sequence x")
disp (x');
disp("DFT Sequence Xdft")
disp ( round(Xdft)');
disp("IDFT Sequence Xidft")
disp ( round(Xidft)');
Comments
Post a Comment