Matlab Code:: % Spectrum Analysis by DFT
Matlab Code:: % Spectrum Analysis by DFT
Matlab Code:: % Spectrum Analysis by DFT
MATLAB CODE :
clc;
clear all;
close all;
a=input('Enter the sequence :');
N=length(a);
disp('The length of the sequence is:');N
for k=1:N
y(k)=0;
for i=1:N
y(k)=y(k)+a(i)*exp((-2*pi*j/N)*((i-1)*(k-1)));
end;
end;
k=1:N
disp('The result is:');y
figure(1);
subplot(211);
stem(k,abs(y(k)));
grid;
xlabel('sample values n-->');
ylabel('Amplitudes-->');
title('Mangnitude response of the DFT of given sequence');
subplot(212);
stem(angle(y(k))*180/pi);
grid;
xlabel('sample values n-->');
ylabel('phase-->');
title('Phase response of the DFT of given sequence');
IDFT:
clc;
clear all;
close all;
a=input('Enter the sequence :');
N=length(a);
disp('The length of the sequence is:');N
for n=1:N
y(n)=0;
for k=1:N
y(n)=y(n)+a(k)*exp((2*pi*j*(k-1)*(n-1))/N);
end;
end;
n=1:N
y1=1/N*y(n);
disp('The result is:');y1
figure(1);
stem(n,y1);
grid;
xlabel('sample values n-->');
ylabel('Amplitudes-->');
title('Magnitude response of the IDFT of given DFT');