Matlab

To Plot the DFT/IDFT for the Given Discrete Signal

Theory:

Frequency analysis of discrete time signals is usually performed on digital signal processor, which may be general purpose digital computer or specially designed digital hardware. To perform frequency analysis on discrete time signal, we convert the time domain sequence to an equivalent frequency domain representation. We know that such representation is given by The Fourier transform X(ejw) of the sequence x(n). However, X(ejw) is a continuous function of frequency and therefore, It is not a computationally convenient representation of the sequence. DFT is a powerful computational tool for performing frequency analysis of discrete time signals. The N-point DFT of discrete time sequence x(n) is denoted by X(k) and is defined as.

x(n)= n)

Steps in performing operations:

  • Get the input sequence.
  • We can find the DFT for the input sequence using by direct equation of DFT.
  • Find the IDFT using the direct equation.
  • Let’s plot the DFT and IDFT for the given sequence by using matlab command stem.
  • Display the above outputs.

Program:

clc;

close all;

clear all;

xn=input(‘Enter the sequence x(n)’);

ln=length(xn); %find the length of the sequence

xk=zeros(1,ln); %let’s initialize an array of the same size as that of input sequence

ixk=zeros(1,ln); let’s initialize an array of the same size as that of input sequence

%DFT of the sequence

for k=0:ln-1

 for n=0:ln-1

 xk(k+1)=xk(k+1)+(xn(n+1)*exp((i)*2*pi*k*n/ln));

 end

end

%Plotting input sequence

t=0:ln-1;

subplot(221);

stem(t,xn);

ylabel (‘Amplitude’);

xlabel (‘Time Index’);

title(‘Input Sequence’);

magnitude=abs(xk); % In order to find the magnitudes for the individual DFT points

% plot the magnitude response

t=0:ln-1;

subplot(222);

stem(t,magnitude);

ylabel (‘Amplitude’);

xlabel (‘K’);

title(‘Magnitude Response’);

phase=angle(xk); % In order to find the phases of individual DFT points % plot the magnitude

t=0:ln-1;

subplot(223);

stem(t,phase);

ylabel (‘Phase’);

xlabel (‘K’);

title (‘Phase Response’);

%IDFT of the sequence

for n=0:ln-1

 for k=0:ln-1

 ixk(n+1)=ixk(n+1)+(xk(k+1)*exp(i*2*pi*k*n/ln));

 end

end

ixk=ixk./ln;

%code block to plot the input sequence

t=0:ln-1;

subplot(224);

stem(t,ixk);

ylabel (‘Amplitude’);

xlabel (‘Time Index’);

title (‘IDFT sequence’);

Rajeshwari Chiluveru

Share
Published by
Rajeshwari Chiluveru

Recent Posts

Google Spam Update 2025: Impact, Recovery Guide & SpamBrain Explained

Google released a spam update on 26th of August 2025 and this is affecting a…

2 weeks ago

Google Experiments with Black Sitelink Colors instead of Blue

Google keeps on testing google search display all the time and this time we are…

1 year ago

What are Template Tags in WordPress? How to Use Template Tags

In wordpress if you are developing new or custom wordpress theme or wordpress plugin then…

2 years ago

Google Search Indexing Issues Started on 31st January to February 2024

If you are experiencing indexing issues of your website then you are not alone and…

2 years ago

Create QR Code for Pages & Post using Plugin in WordPress

On your wordpress website if you want to generate qr code for pages and posts…

2 years ago

Add Google Search Console HTML File Upload on WordPress

If you are trying to verify your WordPress website with google search console with html…

2 years ago