ECE324: DIGITAL SIGNAL PROCESSING LABORATORY
Practical No.:4
Roll No: B-54 Registration No.:11205816_ Name:Shyamveer Singh
Aim: To perform DFT and IDFT of two given signals, Plot the
Magnitude and phase of same.
Mathematical Expressions Required:
1. DFT
2. IDFT
Inputs :
X(n)=[1 2 3 4 5]
X(k)=[2 4 6 8 9]
Program Codes:
1. DFT
function[y]=shyamdft(x)
m=length(x);
xk=zeros(1,m);
for k=0:m-1;
for n=0:m-1;
xk(k+1)=xk(k+1)+x(n+1)*exp((-i)*2*pi*k*n/m);
end
end
y=xk
M=sqrt(real(y).^2+imag(y).^2)
M1=abs(y)
A = atan2(imag(y),real(y))
A1=angle(y)
z=fft(x)
2. IDFT
function[y]=shyamidft(x)
m=length(x);
xk=zeros(1,m);
for k=0:m-1;
for n=0:m-1;
xk(k+1)=xk(k+1)+(1/m)*x(n+1)*exp((i)*2*pi*k*n/m)
;
end
end
y=xk
M=sqrt(real(y).^2+imag(y).^2)
M1=abs(y)
A = atan2(imag(y),real(y))
A1=angle(y)
z=ifft(x)
Outputs/ Graphs/ Plots:
>> x=[1 2 3 4 5]
x=
1
2
3
4
5
>> shyamdft(x)
y=
15.0000
- 3.4410i
M=
15.0000
M1 =
15.0000
A=
0
A1 =
0
z=
15.0000
- 3.4410i
-2.5000 + 3.4410i
-2.5000 + 0.8123i
-2.5000 - 0.8123i
-2.5000
2.1991
2.8274
-2.8274
-2.1991
2.1991
2.8274
-2.8274
-2.1991
4.2533
2.6287
2.6287
4.2533
4.2533
2.6287
2.6287
4.2533
-2.5000 + 3.4410i
-2.5000 + 0.8123i
-2.5000 - 0.8123i
-2.5000
Comparison with inbuilt functions: A= angle or phase, M=magnitude compare with
inbuilt commands abs, angle.
Y is output Compare with Z inbuilt command.
Outputs/ Graphs/ Plots:
2. IDFT
x=[2 4 6 8 9]
x=
2
4
6
8
9
>> shyamidft(x)
y=
5.8000
+ 1.1862i
M=
5.8000
M1 =
5.8000
A=
0
A1 =
0
z=
5.8000-1.0618 - 1.1862i -0.8382 - 0.2074i -0.8382 + 0.2074i -1.0618
+ 1.1862i
Comparison with inbuilt functions:A= angle or phase, M=magnitude compare with
inbuilt commands abs, angle.
Y is output Compare with Z inbuilt command.
-2.3009
-2.8991
2.8991
2.3009
-2.3009
-2.8991
2.8991
2.3009
1.5920
0.8635
0.8635
1.5920
1.5920
0.8635
0.8635
1.5920
-1.0618 - 1.1862i
-0.8382 - 0.2074i
-0.8382 + 0.2074i
-1.0618
Analysis/ Learning outcomes: After performing this experiment we know about the DFT
and IDFT implantation using MATLAB ,and we also know how to plot a phase and
magnitude plot of a signal.
Magnitude And Phase:
Magnitude: M=sqrt(real(y).^2+imag(y).^2)
Compare with inbuilt command abs.
PHASE:A = atan2(imag(y),real(y))
Compare with inbuilt command angle.

DFT and IDFT Matlab Code

  • 1.
    ECE324: DIGITAL SIGNALPROCESSING LABORATORY Practical No.:4 Roll No: B-54 Registration No.:11205816_ Name:Shyamveer Singh Aim: To perform DFT and IDFT of two given signals, Plot the Magnitude and phase of same. Mathematical Expressions Required: 1. DFT 2. IDFT Inputs : X(n)=[1 2 3 4 5] X(k)=[2 4 6 8 9] Program Codes: 1. DFT function[y]=shyamdft(x) m=length(x); xk=zeros(1,m); for k=0:m-1; for n=0:m-1; xk(k+1)=xk(k+1)+x(n+1)*exp((-i)*2*pi*k*n/m); end end y=xk M=sqrt(real(y).^2+imag(y).^2) M1=abs(y) A = atan2(imag(y),real(y)) A1=angle(y) z=fft(x) 2. IDFT function[y]=shyamidft(x) m=length(x); xk=zeros(1,m); for k=0:m-1; for n=0:m-1; xk(k+1)=xk(k+1)+(1/m)*x(n+1)*exp((i)*2*pi*k*n/m) ; end end y=xk M=sqrt(real(y).^2+imag(y).^2) M1=abs(y) A = atan2(imag(y),real(y)) A1=angle(y) z=ifft(x) Outputs/ Graphs/ Plots:
  • 2.
    >> x=[1 23 4 5] x= 1 2 3 4 5 >> shyamdft(x) y= 15.0000 - 3.4410i M= 15.0000 M1 = 15.0000 A= 0 A1 = 0 z= 15.0000 - 3.4410i -2.5000 + 3.4410i -2.5000 + 0.8123i -2.5000 - 0.8123i -2.5000 2.1991 2.8274 -2.8274 -2.1991 2.1991 2.8274 -2.8274 -2.1991 4.2533 2.6287 2.6287 4.2533 4.2533 2.6287 2.6287 4.2533 -2.5000 + 3.4410i -2.5000 + 0.8123i -2.5000 - 0.8123i -2.5000 Comparison with inbuilt functions: A= angle or phase, M=magnitude compare with inbuilt commands abs, angle. Y is output Compare with Z inbuilt command. Outputs/ Graphs/ Plots: 2. IDFT x=[2 4 6 8 9] x= 2 4
  • 3.
    6 8 9 >> shyamidft(x) y= 5.8000 + 1.1862i M= 5.8000 M1= 5.8000 A= 0 A1 = 0 z= 5.8000-1.0618 - 1.1862i -0.8382 - 0.2074i -0.8382 + 0.2074i -1.0618 + 1.1862i Comparison with inbuilt functions:A= angle or phase, M=magnitude compare with inbuilt commands abs, angle. Y is output Compare with Z inbuilt command. -2.3009 -2.8991 2.8991 2.3009 -2.3009 -2.8991 2.8991 2.3009 1.5920 0.8635 0.8635 1.5920 1.5920 0.8635 0.8635 1.5920 -1.0618 - 1.1862i -0.8382 - 0.2074i -0.8382 + 0.2074i -1.0618 Analysis/ Learning outcomes: After performing this experiment we know about the DFT and IDFT implantation using MATLAB ,and we also know how to plot a phase and magnitude plot of a signal. Magnitude And Phase: Magnitude: M=sqrt(real(y).^2+imag(y).^2) Compare with inbuilt command abs. PHASE:A = atan2(imag(y),real(y)) Compare with inbuilt command angle.