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

DFT Synthesis Using Matlab

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

DFT Synthesis Using Matlab

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Lab 5 tasks

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

'MarkerFaceColor', 'r') 0.5


% Original signal in red
0
title('Original Signal') 0 0.5 1 1.5 2 2.5 3
xlabel('n') n
ylabel('x[n]')
subplot(212)
stem(n, real(x_synthesized), 'b', 'MarkerFaceColor', 'b')
% Synthesized signal in blue Comments: Proving DFT synthesis equation means to reconstruct
title('Synthesized Signal') the given discrete signal from its frequency components. It can be
xlabel('n') seen here that a discrete signal was taken and DFT was applied to
ylabel('x_synth[n]');
break it into its frequency components and then for loop was
applied for summation of that DT sinusoids frequency components
to obtain the original signal.

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,

0.0000 + 0.0001i, 1.4141 - 1.4144i, -0.0000 + 3.9999i}

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

figure; Comments: The same frequency components were


stem(n,Xn,'filled','g','LineWid given as obtained in the previous tasks. Inverse DFT
-0.2
th',1.5) 0 1 was applied
2 to reconstruct
3 4the signal
5 using matrix
6 7
xlabel('Index(n)'), Index(n)
ylabel('x(n)'), inversion which takes a great deal of time if the
matrix if of higher order.
Lab 5 tasks

title('Signal in time domain x(n)'),


grid;

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

Comments: Conjugate method was applied in this code to avoid matrix


inversion which is quite hectic. Output remains the same.-0.2 0 1 2 3 4 5 6 7
Index(n)

You might also like