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

Rajeshwari (M.Tech) is the Technical Education Director at WebVidyalayam. She focuses on translating high-level systems engineering into accessible technology courses.

Share
Published by
Rajeshwari Chiluveru

Recent Posts

Samsung TV Red Light Blinking? 4 Fixes (2026 Power Logic Hub)

User Problem Scenario: The Red Light "Panic" You press the power button on your Samsung…

5 days ago

Samsung TV Not Connecting to WiFi: 2026 Easy Fix Guide

Introduction: I Know the Feeling "We’ve all been there. You sit down to watch your…

6 days ago

Samsung TV Restarting During Diagnosis? Fix the Reboot Loop Fast

User Problem Scenario: The "Diagnosis Loop" Paradox Imagine you notice your apps are slow. You…

6 days ago

Samsung TV Optimize Now Not Working? (2026 Fix: Greyed Out, Stuck or Not Responding)

🎓 Technical Module: Memory Maintenance Logic Module: WV-OS-307 Verified 2026 👨‍🏫 Instructor: Vangari Divya (M.Tech)…

1 week ago

Samsung Smart Hub Test Failed? (2026 Fix: DNS, ISP Block & Authentication Error)

 Introduction: The Setup Paradox "There is a specific moment of frustration for every Samsung Smart…

2 weeks ago

Samsung TV Picture Test Not Working? 4 Technical Recovery Fixes

Introduction: Lab Diary & Experience "When your Samsung TV screen begins to flicker or show…

2 weeks ago