DFT Synthesis Using Matlab
DFT Synthesis Using Matlab
1) Prove DFT synthesis equation using DFT output generated from lab task.
x = [1, 2, 3, 0];
N = 4;
Fs = 100; 3
Original Signal
n = [0:1:N-1];
k = [0:1:N-1]; 2.5
WN = exp(-j*2*pi/N); 2
kn = n' * k;
x[n]
1.5
WNkn = WN.^kn;
Xk = x * WNkn; 1
% DFT synthesis equation
0.5
x_synthesized = zeros(1, N);
for nn = 0:N-1 0
0 0.5 1 1.5 2 2.5 3
x_synthesized(nn+1) = (1/N) n
* sum(Xk .* exp(j*2*pi/N * k *
nn)); Synthesized Signal
3
end
2.5
% Plot the original and
synthesized signals 2
x s ynth[n]
figure; 1.5
subplot(211)
stem(n, x, 'r', 1
2) Forward DFT using matrices. Develop a MATLAB code to find the Forward DFT output of the
following time domain sequence by using DFT equation in matrix form. Also plot the
magnitude and phase spectrum. Take 𝐹𝑠 = 1000 𝑠𝑎𝑚𝑝𝑙𝑒𝑠⁄𝑠𝑒𝑐 𝑥(𝑛) = {0.3535, 0.3535, 0.6464,
1.0607 , 0.3535, − 1.0607, − 1.3535 , − 0.3535}
close all,clear all;clc;
x=[0.3535, 0.3535, 0.6464, 1.0607, 0.3535, -1.0607, -1.3535 , -0.3535];
N=8; n=[0:1:N-1]; k=[0:1:N-1]; WN=exp(-j*2*pi/N); nk=n'*k; WNnk=WN.^nk;
Xk=x*WNnk, mag_Xk=abs(Xk);, phase_Xk=angle(Xk);
phase_degrees=rad2deg(phase_Xk);
figure;
subplot(2,1,1), stem(n,mag_Xk,'filled','g','LineWidth',1.5)
xlabel('Index(K)'), ylabel('|X(k)|'),title('Magnitude Plot'),grid;
subplot(2,1,2), stem(n,phase_degrees,'filled','k','LineWidth',1.5)
xlabel('Index(K)'),ylabel('?X(k)'),title('Phase Plot'),grid;
Lab 5 tasks
Magnitude Plot
4
Comments: Forward DFT was
3
applied through matrix
multiplication and the magnitude
|X(k)|
2
and phase spectrums of the given
1
time domain signal was
0
observed.
0 1 2 3 4 5 6 7
Index(K)
Phase Plot
200
100
?X(k)
-100
-200
0 1 2 3 4 5 6 7
Index(K)
Output: { -0.0001 + 0.0000i, 0.0000 - 3.9999i, 1.4141 + 1.4144i -0.0000 - 0.0001i, -0.0001 - 0.0000i,
2. Inverse DFT using Matrix inversion Develop a MATLAB code to find the inverse DFT output of the
following frequency domain sequence by
using IDFT equation in matrix form (use Signal in time domain x(n)
0.15
matrix inversion). 𝑋(𝑘) = {0, 4∠ − 90 ∘ ,
2∠45 ∘ , 0 , 0, 0, 2∠ − 45 ∘ , 4∠90 ∘ }
0.1
close all,clear all;clc;
%values converted from polar
co-ordinates to rectangular co- 0.05
ordinates
Xk=[0,-4i ,1.414+1.414i, 0 , 0,
0, 1.414-1.414i ,4i]; 0
N=8;
x(n)
n=[0:1:N-1];
k=[0:1:N-1]; -0.05
WN=exp(-j*2*pi/N);
nk=n'*k;
WNnk=WN.^nk; -0.1
B=inv(WNnk);
Xk_inv=Xk.';
Xn=(1/N)*(Xk)*B -0.15
3. Inverse DFT using Conjugate method Develop a MATLAB code to find the inverse DFT output of the
following frequency domain sequence by using IDFT equation in matrix form (use conjugate method).
𝑋(𝑘) = {0, 4∠ − 90 ∘ , 2∠45 ∘ , 0 , 0, 0, 2∠ − 45 ∘ , 4∠90 ∘ }
close all,clear all;clc;
Xk=[0, -4i, 1.414+1.414i, 0, 0, 0, 1.414-1.414i, 4i];
N=8;
n=[0:1:N-1];
k=[0:1:N-1];
WN=exp(-j*2*pi/N);
Signal in time domain x(n)
nk=n'*k; 0.15
WNnk=WN.^nk;
B=conj(WNnk); 0.1
Xk_inv=Xk.';
Xn=(1/N)*(Xk)*B 0.05
figure;
stem(n,Xn,'filled','g','LineWidth',1.5) 0
xlabel('Index(n)'),
ylabel('x(n)'), x(n)
-0.05
title('Signal in time domain x(n)'),
grid;
-0.1
-0.15