[go: up one dir, main page]

0% found this document useful (0 votes)
5 views8 pages

DSP Lab Report 5

The document outlines a lab report on Discrete Fourier Transform (DFT) and its properties, detailing tasks performed using MATLAB, including circular shift, time-shifting property, duality property, circular convolution, and convolution property of DFT. Each task includes pseudo-code, MATLAB code, and discussions on the results, emphasizing the verification of DFT properties through graphical comparisons. The report concludes with a critical analysis highlighting strengths and areas for improvement in the lab's approach and implementation.

Uploaded by

Roman Roman
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)
5 views8 pages

DSP Lab Report 5

The document outlines a lab report on Discrete Fourier Transform (DFT) and its properties, detailing tasks performed using MATLAB, including circular shift, time-shifting property, duality property, circular convolution, and convolution property of DFT. Each task includes pseudo-code, MATLAB code, and discussions on the results, emphasizing the verification of DFT properties through graphical comparisons. The report concludes with a critical analysis highlighting strengths and areas for improvement in the lab's approach and implementation.

Uploaded by

Roman Roman
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/ 8

EEE-324 Digital Signal Processing

Lab#5: Discrete Fourier Transform and its Properties

Name Roman Bin Ehsan


Reg no# FA22-BEE-258
Class BEE-6A
Instructor Dr. Bakhtiar Ali
Lab Tasks
Task#1: Write MATLAB function for circular shift by first writing its pseudo-code of the
procedure explained in the In-Lab section and then writing its code.

Pseudo code:
3. Shift Right (if `k > 0`):
1. Function Definition: - Output `y = [last k elements of x, first N-k
- Input: array `x`, shift `k`. elements of x]`
4. Shift Left (if `k < 0`):
2. Adjust Shift: - Set `k = |k|`
- Set `N = length(x)` - Output `y = [elements from k+1 to end of
- Set `k = k mod N` x, first k elements of x]`
5. Return Output `y`

MATLAB Function Code:


function [ y ] = circularshift( x,k ) k = abs(k)
N=length(x); y = [x(k+1:end), x(1:k)];
k=mod(k,N); y = x;
if k>0 end
y=[x(end-k+1:end), x(1:end-k)]; end
else if k<0

Task Code:
x = [1 2 3 4] title('origianl signal')
k = -2; subplot(212)
y = circularshift(x,k) stem(y,n,'linewidth',2)
subplot(211) title('shifted signal')
stem(x,n,'linewidth',2)
Graph:

Figure 1:Plot of Circular shift


Discussion:

This MATLAB task shifts the numbers in a list in a circular way. The function circularshift(x,
k) moves the elements by k positions. If k is negative, it shifts left; if positive, it shifts right.
In this example, [1 2 3 4] is shifted left by 2 places, so it becomes [3 4 1 2]. The graphs
show the original and shifted signals to compare the changes.

Task#2: Verify the time shifting property of DFT by first writing a pseudo code of the RHS
and LHS followed by the MATLAB code. Use the circular shift function designed above for
shifting in time domain. Compare the result by sub-plotting LHS and RHS of the following
equation.

Pseudo Code:

LHS: RHS:
i. Two signals ‘x’ and ‘n’ are given i. Take Fourier transform of signal
ii. Save the length of n in w2. ‘x’ and save it in variable y2.
iii. Use the circshift function ii. Multiply y2 with exponential
designed in task 1. function (e-j(2pi/N)2) as given in the
iv. In a single command take RHS of the mentioned equation.
discrete Fourier transform (of iii. Limit the signal between pi and –
circularly shifted variable b) pi using line space command.
using ‘fft’ command, then take iv. Plot its discrete graph with title
its absolute value. “RHS”.
v. Limit the signal between pi and –
pi using line space command.
vi. Plot its discrete graph with title
“LHS”.

Code:

x=[1 2 3 4] title('LHS') ;
n=[-2 -1 0 1] y2=fft(x)
w2=length(n) RHS=y2.*exp(-1i .*(2.*pi./w2).*2)
b=circshift(x,n) w1=linspace(-pi,pi,length(y2))
LHS =abs(fft(b)) subplot(2,1,2)
n1=linspace(-pi,pi,length(LHS)) stem(w1,abs(RHS))
subplot(2,1,1) title('RHS') ;
stem(n1,LHS)

Graph:
Figure 2:Plot of time shifting property of DFT

Discussion:

To check this property, we first shift the sequence x(n)x(n) by l samples using the
circularshift function. Then, we find the DFT of the shifted sequence, which represents the
Left-Hand Side (LHS) of the equation. Next, we calculate the DFT of the original sequence
and multiply it by the phase shift term e−j(2π/N)k, which represents the Right-Hand Side
(RHS).
Finally, we compare the LHS and RHS by plotting their magnitudes and phases.
The plots show that both sides are the same, confirming that shifting a sequence in time
causes a phase shift in the frequency domain. This proves the time-shifting property of the
DFT.

Task#3: Verify the duality property of DFT by first writing a pseudo code of the RHS and
LHS followed by the MATLAB code. Compare the result by sub-plotting LHS and RHS of the
following equation.

Pseudo Code:

LHS: RHS:
i. An original signal ‘x’ is given with i. Take fourier transform of signal ‘x’,
limit 1:5. then absolute of that fourier transform
ii. Flip the signal ‘x’ using fliplr all in a single line.
function, save it in ‘x1’. ii. Limit the function using linespace
iii. Multiply flipped signal with a scalar command.
value, save it in variable ‘m’. iii. Plot its discrete graph.
iv. Take fourier transform of the flipped
signal using FFT command.
v. Limit is given using line space
command.
vi. Plot its discrete graph.

Code:

x=[2,4,6,8,10] subplot(2,1,1)
n=1:5 stem(w1,LHS)
x1=fliplr(x) RHS=abs(fft(x));
m=-1.*x1 ; w2=linspace(-pi,pi,length(RHS))
LHS=abs(fft(m)) subplot(2,1,2)
w1=linspace(-pi,pi,length(LHS)) stem(w2,RHS)
Graph:

Figure 3:Plot for duality property of DFT

Discussion:

This task was about checking the duality property of the Discrete Fourier Transform (DFT).
This property says that if we reverse a time-domain sequence and multiply it by its length
NN, the DFT remains the same as the original sequence. Mathematically, this is written as
DFT{Nx(−n)}=X(k), where x(−n) is the reversed sequence.
To test this, we first reversed the original sequence x(n)x(n) to get x(−n)x(-n) and then
multiplied it by NN. The DFT of this modified sequence gives the Left-Hand Side (LHS) of
the equation, while the DFT of the original sequence gives the Right-Hand Side (RHS). By
comparing the magnitudes of both sides through plots, we confirmed that they match.
This proves that reversing and scaling a sequence gives the same frequency-domain result
as the original sequence's DFT.

Task#4: Write Matlab function for circular convolution by first writing its pseudo-code of
the procedure explained in the In-Lab section and then writing its code.
Pseudo Code:

i. Design a function with single output vi. Use circular conv command to
and two inputs name it circonv ( circularly convolve the original
circular convolution). signal.
ii. Input one signal and save it in ‘x’. vii. Use subplot command to show
iii. Input other signal and save it in ‘h’. difference between original and
iv. Give limit ‘n’. circularly shifted signal.
v. Plot its graph to show linear
convolution.
Code:

function [y]= circonv (x,h,n) stem(n,x)


x=[1 2 3 4] y=conv(x,h,length(x))
h=[2 3 4 5] subplot(2,1,2)
n=-1:2 stem(n,y)
subplot(2,1,1) end
Graph:

Figure 4:Plot of convolution using pseudo code

Discussion:

The given MATLAB code defines a function named circonv to perform circular convolution
on two sequences, x = [1 2 3 4] and h = [2 3 4 5]. It sets a time vector n = -1:2 for plotting.
The first subplot shows the original sequence x using a stem plot, while the second subplot
displays the circular convolution result, computed using the conv function. This function
efficiently calculates and visualizes the convolution output. For better flexibility, it would
be useful to allow x and h as inputs instead of fixing their values in the code.
Task#5: Verify the convolution property of DFT by first writing a pseudo code of the RHS
and LHS followed by the MATLAB code. Use the circular convolution function developed in
task-4 to compute convolution in time domain. Compare the result by sub-plotting LHS and
RHS of the following equation.

Pseudo Code:
LHS: RHS:
i. Take signal one and save it in ‘x1’. i. Take fourier transform of signal ‘x1’,
ii. Take signal two and save it in ‘x2’. then its absolute value.
iii. Circularly convolve both signals and ii. Save it in variable ‘a’.
save it variable ‘c’. iii. Take fourier transform of signal ‘x2’,
iv. Take fourier transform of ‘c’ and take then take its absolute value.
its absolute value. iv. Save it in variable ‘b’.
v. Plot its discrete graph. v. Convolve ‘a’ and ‘b’.
vi. Plot its discrete graph.

MATLAB Code:

x1=[1 3 5] title('LHS') ;
n1=-1:1 a=abs(fft(x1))
x2=[2 4 6] b=abs(fft(x2))
n2=[0:2] r=a.*b;
c=cconv(x1,x2,length(x1)) w2=linspace(-pi,pi,length(r))
y=abs(fft(c)) subplot(2,1,2)
w1=linspace(-pi,pi,length(y)) stem(w2,r)
subplot(2,1,1) title('RHS');
stem(w1,y)

Graph:

Figure 5:Plot for convolution property of DFT


Discussion:

This task aimed to verify the convolution property of the Discrete Fourier Transform (DFT),
which states that the DFT of the convolution of two sequences is the same as the product
of their individual DFTs. To confirm this, pseudocode was written for both sides of the
equation: the right-hand side (RHS) involved computing the DFTs of both sequences and
multiplying them, while the left-hand side (LHS) involved performing circular convolution
in the time domain and then taking its DFT. The pseudocode was then implemented in
MATLAB using suitable functions for DFT and circular convolution. Finally, the results of
the LHS and RHS were compared by plotting them. If the two plots match, it confirms the
correctness of the DFT implementation and its efficiency in performing convolution.

Critical Analysis:
The lab on Discrete Fourier Transform (DFT) and its Properties provided a structured
approach to understanding key DFT concepts, including time-shifting, duality,
convolution, and circular convolution. Each task involved theoretical derivations followed
by MATLAB implementation, ensuring a practical understanding of these properties. The
use of graphical comparisons helped verify results, making it easier to observe how
transformations affect signals. However, some MATLAB implementations had hard-coded
inputs, limiting flexibility. Allowing user-defined inputs would have improved adaptability
for different test cases. Additionally, errors in the initial circular convolution
implementation highlighted the need for a more structured approach to function design.

While the lab successfully demonstrated DFT properties, some areas needed
improvement. A numerical error analysis, such as computing the mean squared error
between theoretical and computed results, could provide a more quantitative verification
rather than relying solely on visual comparisons. The duality property also required a
more detailed explanation, as simply reversing and scaling a sequence without proper
derivation may not be intuitive for all students. Overall, the lab was effective in reinforcing
DFT concepts, but incorporating more flexible coding practices, numerical validation, and
deeper explanations would enhance the learning experience.

You might also like