DIGITAL SIGNAL PROCESSING
Name: AHMAR ARSHAD
Registration Number: FA19-BEE-106
TITLE: LAB REPORT 6
Instructor’s Name: MIAN AHMAD YASSER
Lab#6: To explain Frequency domain analysis of Discrete Time
signals using Discrete Fourier Transform (DFT) on MATLAB
Objectives:
To construct user defined functions for the computation of N-point DFT
using MATLAB.
To identify the properties of discrete time signals in the frequency domain.
To verify the properties of DFT using MATLAB
Requirements:
Software
MATLAB
Methodology:
We must study discrete signals in this lab in the frequency domain and use
discrete Fourier time transformation for that purpose (DTFT). DTFT is
required because working with signals on computers is simpler.
In this lab, we learnt all of the theoretical foundation to clarify the DTFT's
principles and prior experience. The mathematical formulas of DTFT were
added. For a function calculating the DTFT in N-point sequences, I used
this knowledge in the prelab task.
I calculated M-point DTFT for the series in the first lab task. I checked the
properties of DTFT on the built-in functions of MATLAB during the
second lab task. I have verified the linearity, circular time shift, circular
frequency shift, duality, N-Point circular module, and the Parseval’s
relation.
I used DFT to calculate the convolution of two finite sequences in the final
task. I demonstrated my findings correctly.
Results and Conclusion:
After performing the lab, I can get the process of DTFT and its properties in
MATLAB after conducting this lab. I have been taught about DTFT mathematics
and its program application. After that, with the DFT method on MATLAB, I can
compute DTFT for any finite or circular convolution.
Pre-Lab Task:
Task 1:
Solution:
function [ y ] = DFT( x,N,b,K )
if b==1
n=[0:1:N-1] %row vector for n
k=[0:1:K-1] %row vector for k
WN=exp(-j*2*pi/N) %Wn factor
nk=n'*k %creates a N by N matrix of nk values
WNnk=WN.^nk %DFT matrix
y=x*WNnk %row vectors for DFT coefficients
elseif b==0
n=[0:1:N-1]; %row vector for n
k=[0:1:K-1]; %row vector for k
WN=exp(-j*2*pi/N); %Wn factor
nk=n'*k; %creates a N by N matrix of nk values
WNnk=WN.^(-nk); %IDFT matrix
y=(x*WNnk)/N; %row vectors for IDFT values
end
end
Lab Tasks
Task 1:
Solution:
clc
clear all
close all
x=[1:4];
[y1]= FFT_DIT_R2(x)
[y2]=fft(x)
% function
function [ y ] = FFT_DIT_R2(x)
p= nextpow2(length(x)) % checking the size of the
input array
x= [x zeros(1,(2^p)-length(x))] % complementing an array of
zeros if necessary
N= length(x) % computing the array size
S= log2(N) % computing the number of
conversion stages
Half= 1 ; % Setting the initial "Half"
value
x= bitrevorder(x) ;
for stage= 1:S % stages of transformation
stage
for index= 0:(2^stage):(N-1) % series of "butterflies" for each
stage
index
for n= 0:(Half-1) % creating "butterfly" and saving the
results
n
pos= n+index+1 % index of the data sample
pow= (2^(S-stage))*n % part of power of the complex
multiplier
w= exp((-1i)*(2*pi)*pow/N) % complex multiplier
a= x(pos)+x(pos+Half).*w % 1-st part of the "butterfly"
creating operation
b= x(pos)-x(pos+Half).*w % 2-nd part of the "butterfly"
creating operation
x(pos)= a % saving computation of the 1-
st part
x(pos+Half)= b % saving computation of the 2-
nd part
end;
end;
Half= 2*Half % computing the next "Half"
value
end;
y= x; % returning the result from
function
end
Task 2:
Solution:
clc
clear all
close all
%verify properties of DFT
N = 8; % N is length of the sequence
gamma = 0.5;
k = 0:N-1;
g = exp(-gamma*k); h = cos((pi*k)/N);
G = fft(g);
H=fft(h);
% Linearity
x1 = rand(1,11);
x2 = rand(1,11); n = 0:10;
alpha = 0.5;
beta = 0.25;
w = (pi/500)*k;
X1 = x1 * (exp(-j*pi/500)).^(n'*k); % DTFT of x1
X2 = x2 * (exp(-j*pi/500)).^(n'*k); % DTFT of x2
x = alpha*x1 + beta*x2; % Linear combination of x1 & x2
X = x * (exp(-j*pi/500)).^(n'*k); % DTFT of x
% verification
X_check = alpha*X1 + beta*X2; % Linear Combination of X1 & X2
error = max(abs(X-X_check)) % Difference
%Since maximum error between fourier transform of two arrays is less than
%10^-14 so both are identical
% Circular Time Shift
n0 = N/2; % n0 is the amount of shift
x2 = [g(n0+1:N) g(1:n0)];
X2 = fft(x2)
% Circular Frequency Shift
k0 = N/2;
x3 = exp(-j*2*pi*k0*k/N).*g;
X3 = fft(x3)
G3 = [G(k0+1:N) G(1:k0)]
% Duality
x4 = G;
X4 = fft(G)
G4 = N*[g(1) g(8:-1:2)] % This forms N*(g mod(-k))
% N Point Circular Convolution
% To calculate circular convolution between
% g and h use eqn (3.67)
h1 = [h(1) h(N:-1:2)];
T = toeplitz(h',h1);
x5 = T*g';
X5 = fft(x5')
% Modulation
x6 = g.*h;
X6 = fft(x6)
H1 = [H(1) H(N:-1:2)];
T = toeplitz(H.', H1); % .' is the nonconjugate transpose
G6 = (1/N)*T*G.' % Verify G6 = X6.'
Task 3:
Solution:
A)
clc
close all
clear all
g=[3,4'-2,0,1,-4]
h=[1,-3,0,4,-2,3]
c=cconv(g,h)
stem(c)
B)
clc
close all
clear all
n= 0:4;
[x]=sin(pi*n)/2
X=length(x)
r=106;
[yn]=r.^n
Y=length(yn)
y=cconv(x,yn,6)
stem(y)