Lab 5
Lab 5
C O N T E N T S:
1
Discrete Time Fourier Series (DTFS):
A periodic sequence 𝑥(𝑛) is periodic with a fundamental period of N provided that it satisfies
the condition
𝑥 (𝑛) = 𝑥(𝑛 + 𝑁)
The Fourier series representation for 𝑥(𝑛) consists of N harmonically related exponential functions
𝑒 𝑗2𝜋𝑘𝑛/𝑁 , 𝑘 = 0,1,2, … . 𝑁 − 1
𝑁−1
𝑗2𝜋𝑘𝑛
𝑥 (𝑛) = ∑ 𝑐𝑘 𝑒 𝑁
𝑘=0
Where 𝑐𝑘 are the discrete Fourier series co-efficients, which are given by,
𝑁−1
𝑗2𝜋𝑘𝑛
𝑐𝑘 = ∑ 𝑥(𝑛) 𝑒 − 𝑁
𝑛=0
2𝜋
−𝑗
Suppose 𝑊𝑁 = 𝑒 𝑁
𝑁−1
𝑥 (𝑛) = ∑ 𝑐𝑘 𝑊𝑁−𝑛𝑘
𝑘=0
And
𝑁−1
𝑐𝑘 = ∑ 𝑥 (𝑛) 𝑊𝑁𝑛𝑘
𝑛=0
2
From the above equation, it is clear that to compute all Discrete Fourier co-efficients, two nested
for…end loops would be required. This is clearly inefficient in MATLAB. An efficient implementation in MATLAB
would be to use a matrix-vector multiplication. Let 𝒄 and 𝑿 denote the column vectors corresponding to the
primary (one) period of the Fourier series co-efficients and the input sequence respectively. So, we can write
the above equations as
𝑪 = 𝑾𝑵 𝑿
And
1
𝑿= 𝑾 ∗𝑪
𝑁 𝑵
Where the matrix 𝑾𝑵 is given by
𝟏 𝟏 … 𝟏
𝟏 𝑊𝑁1 … 𝑊𝑁𝑁−1
𝑾𝑵 = [𝑊𝑁𝑘𝑛 , 𝑘 ≤𝑁−1 ,𝑛 ≤ 𝑁−1 ]= ⋮ ⋮ ⋱ ⋮
(𝑁−1)2
[𝟏 𝑊𝑁𝑁−1 … 𝑊𝑁 ]
Program 1:
𝑥 (𝑛) = {… , 0 , 1,2,3,0,1,2,3,0,1,2,3, … }
>> x=[0,1,2,3];
>> N=4;
>> n=[0:N-1];
>> k=[0:N-1];
>> WN=exp(-j*2*pi/N);
3
>> nk=n'*k;
Program 2:
>> Ck=[6,-2+2j,-2,-2-2j];
>> N=4;
>> n=[0:N-1];
>> k=[0:N-1];
>> WN=exp(-j*2*pi/N);
>> nk=n'*k;
Where 𝑤 is the real frequency variable. The Fourier Transform representation of a sequence is unique and is
continuous function of 𝑤. The original sequence can be computed from its transform representation by using
the following IDTFT formula
4
1 ∞
𝑥 (𝑛) = ∫ 𝑋(𝑒 𝑗𝑤 ) 𝑒 𝑗𝑤𝑛 𝑑𝑤
2𝜋 −∞
The frequency range of the discrete time signal is unique over the frequency interval of (−𝜋, 𝜋) or, equivalently,
(0,2𝜋). Hence 𝑋(𝑒 𝑗𝑤 ) will be periodic with a period 2𝜋.
If 𝑥(𝑛) is of infinite duration, then MATLAB cannot be used directly to compute 𝑋(𝑒 𝑗𝑤 ) from 𝑥(𝑛). However,
we can use it to evaluate the expression 𝑋(𝑒 𝑗𝑤 ) over (0, 𝜋) frequencies and then plot its magnitude and phase
(or real and imaginary parts).
Program 3:
Determine DTFT of 𝑥(𝑛) = (0.5)𝑛 𝑢(𝑛) at 501 equispaced points between [0, 𝜋]. Plot its magnitude, phase,
real and imaginary parts.
First find 𝑋(𝑒 𝑗𝑤 ) by using the formula, and then determine its different parts.
>> w=[0:0.00628:pi];
>> u=ones(1,501);
>> magX=abs(X);
>> angX=angle(X);
>> realX=real(X);
>> imagX=imag(X);
>> subplot(221)
>> plot(w,magX);
>> subplot(222)
5
>> plot(w,angX)
>> subplot(223)
>> plot(w,realX)
>> subplot(224)
>> plot(w,imagX)
If x(n) is of finite duration, then MATLAB can be used to compute 𝑋(𝑒 𝑗𝑤 ) numerically at any frequency.
The above approach is to compute the DTFT of x(n) using the definition of DTFT. In addition, the DTFT can also
be implemented, as a matrix-vector multiplication operation.
Suppose x(n) has N samples between 𝑛1 ≤ 𝑛 ≤ 𝑛𝑁 (i.e. not necessarily between [0, N-1]) and we want to
𝜋
evaluate 𝑋(𝑒 𝑗𝑤 ) at 𝑤𝑘 = 𝑘, 𝑘 = 0,1, … , 𝑀 which are (M+1) equispaced frequencies between [0,𝜋]. The
𝑀
𝑁
𝜋
−𝑗(𝑀)𝑘𝑛𝑙
𝑋(𝑒 𝑗𝑤𝑘 ) = ∑ 𝑒 𝑥(𝑛𝑙 ) , 𝑘 = 0,1, … , 𝑀
𝑙=1
When {𝑥(𝑛𝑙 )} and {𝑋(𝑒 𝑗𝑤𝑘 )} are arranged as column vector x and X, respectively. So, we can write,
𝑿 = 𝑾𝒙
𝜋
−𝑗( )𝑘𝑛𝑙
𝑾= {𝑒 𝑀 ; 𝑛1 ≤ 𝑛 ≤ 𝑛𝑁 , 𝑘 = 0,1, … , 𝑀}
In addition if we arrange {k} and {𝑛𝑙 } as row vectors 𝒌 and 𝒏 respectively then
𝜋 𝑇
𝑿𝑇 = 𝒙𝑇 [𝑒𝑥𝑝(−𝑗 𝒏 𝒌)]
𝑀
6
Note that 𝒏𝑇 𝒌 is an 𝑁 × (𝑀 + 1) matrix.
>> k=[0:M];
>> n=[n1:n2];
Program 4:
Determine the DTFT of the following finite duration sequence 501 equi-spaced frequencies between [0,π].
x(n) = {1,2,3,4,5}
>> x=1:5;
>> n=-1:3;
>> k=0:500;
7
LAB TASKS: [Q-Marks: 10; CLO-1; PLO-4; P-1]
Task 1: Let x(n) be periodic signal with fundamental period N=50, where one period is given by
−0.3𝑛
𝑛𝑒 , 0 ≤ 𝑛 ≤ 25
𝑥 (𝑛) = {
0 , 26 ≤ 𝑛 ≤ 49
Task 2: Identify the periodic sequence given by the following DFS coefficients.
Ck = [0,j,-2j,-j] N=4
Task 3: Choose DTFT to represent the following sequence in frequency domain. Also, plot the magnitude and
angle.