Program to compute DFT of a given input
clc; % To clear the command window..
disp('Program for computing DFT of a given input signal') x=input('\nEnter the values of input signal : '); subplot(3,2,1) stem(x) xlabel('Time') ylabel('Amplitude') title('INPUT SIGNAL') n=length(x); % function to compute DFT y=fft(x,n); disp('DFT of the input signal is : ') disp(y) subplot(3,2,2) stem(real(y),imag(y)) xlabel('Time') ylabel('Amplitude') title('DFT Of Input Signal')
% Magnitude plot using inbuilt function % Function to find magnitude m=abs(y); disp('Magnitude of DFT using inbuilt function is :') disp(m) subplot(3,2,3) stem(m) xlabel('Time')
ylabel('Amplitude') title('Magnitude plot using inbuilt function ') % Magnitude plot using formula z=sqrt(real(y).^2+imag(y).^2); disp('Magnitude of DFT using formula is :') disp(z) subplot(3,2,4) stem(z) xlabel('Time') ylabel('Amplitude') title('Magnitude plot using formula') % Phase plot using inbuilt function % Function for finding phase a=angle(y); disp('Phase angle of DFT using inbuilt function is :') disp(a) subplot(3,2,5) stem(a) xlabel('Time') ylabel('Phase angle') title('Phase plot using inbuilt function ') % Phase plot using formula b=atan2(imag(y),real(y)); disp('Phase angle of DFT using formula is :') disp(b) subplot(3,2,6) stem(b) xlabel('Time') ylabel('Phase Angle') title('Phase plot using formula ')
COMMAND WINDOW OUTPUT:Program for computing DFT of a given input signal Enter the values of input signal : [1,1,0,0] DFT of the input signal is : 2.0000 1.0000 - 1.0000i 0 Magnitude of DFT using inbuilt function is : 2.0000 1.4142 0 1.4142 Magnitude of DFT using formula is : 2.0000 1.4142 0 1.4142 Phase angle of DFT using inbuilt function is : 0 -0.7854 0 0.7854 Phase angle of DFT using formula is : 0 -0.7854 0 0.7854 FIGURE WINDOW
1.0000 + 1.0000i