MATLAB program to find DFT and IDFT using matlab functions

Program Code
%DFT and IDFT using matlab functions
clc;
close all;
clear all;
x=input('Please enter the sequence x(n)=');
N=input('Please enter the length of the DFT N=');
X=fft(x,N);
n=0:length(x)-1;
subplot(311);
stem(n,x);
title('Input Sequence');
subplot(323);
n=0:length(X)-1;
stem(n,X);
disp('DFT of input sequence is ');
disp(X);
title('DFT');
subplot(324);
stem(n,abs(X));
title('Magnitude spectrum');
subplot(325);
stem(n,angle(X));
title('Phase spectrum');
xr=ifft(x,N);
subplot(326);
stem(n,abs(xr));
title('IDFT');
disp('IDFT of input sequence is ');
disp(xr);
Example of Output
Please enter the sequence x(n)=[1 2 3 4 5 6 7 8 9]
Please enter the length of the DFT N=6
DFT of input sequence is 
  Columns 1 through 4

  21.0000 + 0.0000i      -3.0000 + 5.1962i       -3.0000 + 1.7321i       -3.0000 + 0.0000i

  Columns 5 through 6

  -3.0000 - 1.7321i          -3.0000 - 5.1962i

IDFT of input sequence is 
  Columns 1 through 4

   3.5000 + 0.0000i       -0.5000 - 0.8660i         -0.5000 - 0.2887i       -0.5000 + 0.0000i

  Columns 5 through 6

  -0.5000 + 0.2887i         -0.5000 + 0.8660i
______________________________

6 comments:

  1. Respected Sir,
    subplot(311) divides the picture window into thee equal parts and plots the output in one of the three parts.
    Here 311 denotes the number of division we make in the picture window of matlab and the division in which the output appear. Similarly 323,324,325 and 326 denotes the number of division we make in the picture window of matlab and the division in which the output appear.
    Thank you for spending your valuable time to visit my simple blog. Please visit my blog again. Wish you all success in life

    ReplyDelete
  2. can u pls explain the whole program
    rohitrajrock1@gmail.com

    ReplyDelete
  3. Replies
    1. Respected Sir,
      Thank you very much for saying a few kind words about my code. Thank you very much for spending your valuable time to visit this humble blog of mine. I am always at your service. You are always welcome to visit this blog http://s5electronicsandcommunication.blogspot.com .
      I wish you happiness, success and good health. I wish your friends and your family happiness, success and good health. Please share the URL of this blog http://s5electronicsandcommunication.blogspot.com with your friends.

      Delete
  4. is the code same for sequence [j j -j -j]?
    what will be the changing in the code

    ReplyDelete

Please write your opinion about this MATLAB program here, only in English.

For sale

For sale
Indian currency Ten-rupee note in good condition. Issued by the Reserve Bank of India between 22 December 1992 and 21 December 1997. Serial number 52T332603 . Those interested to buy, please contact: Anju K, Email: tc9749@gmail.com . Address: 'Sreyas', House no.7/296, Pulliodi, Kathiroor village, Ponniam east PO, via Ponniam west, Thalassery, Kannur, Kerala - 670641, India.