0% found this document useful (0 votes)
25 views

20BEC1192 DSP 4

This document describes an experiment to compute and visualize the discrete Fourier transform (DFT) and inverse discrete Fourier transform (IDFT) using MATLAB. It includes 4 tasks: 1) Computing DFT and IDFT of a signal using built-in functions, 2) Computing DFT and IDFT without built-in functions, 3) Computing the DFT of a sine wave, and 4) Computing the DFT of the addition of two sine waves. The results are plotted and visualized after each task to observe the transformations between the time and frequency domains.

Uploaded by

Abdul Rauf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

20BEC1192 DSP 4

This document describes an experiment to compute and visualize the discrete Fourier transform (DFT) and inverse discrete Fourier transform (IDFT) using MATLAB. It includes 4 tasks: 1) Computing DFT and IDFT of a signal using built-in functions, 2) Computing DFT and IDFT without built-in functions, 3) Computing the DFT of a sine wave, and 4) Computing the DFT of the addition of two sine waves. The results are plotted and visualized after each task to observe the transformations between the time and frequency domains.

Uploaded by

Abdul Rauf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

EXPERIMENT - 4

Computation of DFT and IDFT

Name: Ajeetha
Reg No.: 20BEC1192

Aim:

To compute and visualise DFT and IDFT with Matlab visualization.


Apparatus Required: MATLAB
Task-1
Compute DFT and IDFT using built in function
CODE:
%with built-in command

figure(1)
x = input("Enter the discrete time signal: ");
N = length(x);
Y = fft(x,N)
Yi = ifft(Y,N)

subplot(3,1,1)
stem(x)
xlabel("time")
ylabel("amplitude")
title("Input signal")
grid on
subplot(3,1,2)
D = abs(Y);
%magnitude
stem(D)
xlabel("frequency")
ylabel("amplitude")
title("DFT")
grid on
subplot(3,1,3)
stem(Yi)
xlabel("time")
ylabel("amplitude")
title("IDFT")
grid on
OUTPUT:

Task-2
Compute DFT and IDFT without using built in function

CODE:
figure(2)
xk = zeros(1,N);
ixk = zeros(1,N);
i = sqrt(-1);
for k=0:N-1
for n=0:N-1
xk(k+1) = xk(k+1)+ (x(n+1)*exp((-i)*2*pi*k*n/N));
end
end
t=0:N-1;
subplot(3,1,1)
stem(t,x)
xlabel("time")
ylabel("amplitude")
title("Input signal")
grid on
Mag = abs(xk);
t = 0:N-1;
subplot(3,1,2)
stem(t,Mag)
xlabel("frequency")
ylabel("amplitude")
title("DFT without built-in function")
grid on
for n=0:N-1
for k=0:N-1
ixk(n+1) = ixk(n+1)+(xk(k+1)*exp(i*2*pi*k*n/N-1));
end
end

ixk = ixk./N;
t = 0:N-1;
subplot(3,1,3)
stem(t,ixk)
grid on
xlabel("time")
ylabel("amplitude")
title("IDFT withut built-in function")

Output:

Task-3
Compute DFT for sine function
Code:

figure(3)
a = input("Enter amplitude: ");
f = input("Enter frequency: ");
t = 0:0.01:1;
x = a*sin(2*pi*f*t);
X = fft(x);
y = abs(X);
subplot(2,1,1)
plot(t,x)
grid on
xlabel("time")
ylabel("amplitude")
title("Sine signal")
subplot(2,1,2)
plot(y)
grid on
xlabel("frequency")
ylabel("amplitude")
title("FT with mirror image")

Output:

Task-4
Compute DFT for addition of sine functions
Code:

figure(4)
a1 = input("Enter amplitude: ");
f1= input("Enter frequency: ");
t = 0:0.01:1;
x1= a1*sin(2*pi*f1*t)+a*sin(2*pi*f*t);
X1= fft(x1);
y1 = abs(X1);
subplot(2,1,1)
plot(t,x1)
grid on
xlabel("time")
ylabel("amplitude")
title("Sine signal")
subplot(2,1,2)
plot(y1)
xlim([0 50])
grid on
xlabel("frequency")
ylabel("amplitude")
title("FT without mirror image")

Output:
Verification:
Result:
Hence the DFT and IDFT for the given tasks are performed and
visualized through MATLAB.

You might also like