Digital Signal Processing Reference
In-Depth Information
Example 1.3. Write a script that will evaluate and plot the magnitude and phase of the DTFT for any
sequence; test it for the sequences
[
1 , 0 , 1
]
,
[
1 , 0,-1
]
, and
[
1 , 0 , 0 , 1
]
.
Such a script should allow one to specify how many samples M of the DTFT to compute over the
interval 0 to , with R = 1 being suitable for real x [ n ]
. Values
of R greater than 2 allow demonstration of periodicity of the DTFT. The code creates an n -by- k matrix
dMat of complex correlators, where each column is a complex correlator of length n and frequency k .
The DTFT is obtained by multiplying the signal vector x on the right by dMat . Each element in the
resulting row vector of frequency responses is obtained as the inner or dot product of the signal vector x
with a column of dMat .
and R = 2 being suitable for complex x [ n ]
function LV_DTF T_Basic(x,M,R)
% LV_DTF T_Basic([1,0,1],300,1)
N = length(x); W = exp(-j*R*pi/M); k = 0:1:M-1;
n = 0:1:N-1; dMat = W.ˆ(n'*k); d = x*dMat; figure(9)
subplot(2,2,1); plot(R*[0:1:M-1]/M,abs(d));
grid; xlabel('Norm Freq'); ylabel('Mag')
subplot(2,2,2); plot(R*[0:1:M-1]/M,angle(d))
grid; xlabel('Norm Freq'); ylabel('Radians')
subplot(2,2,3); plot(R*[0:1:M-1]/M,real(d));
grid; xlabel('Norm Freq'); ylabel('Real')
subplot(2,2,4); plot(R*[0:1:M-1]/M,imag(d))
grid; xlabel('Norm Freq'); ylabel('Imag')
The result from making the call
LV_DTF T_Basic([1,0,1],300,1)
is shown in Fig. 1.2.
A more versatile version of the above code is the script (see exercises below)
LVxDTFT(x,n,M,R,FreqOpt,FigNo)
which, from sequence x having time indices n , computes M frequency samples over the interval ,
which can be computed symmetrically or asymmetrically with respect to frequency zero ( FreqOpt = 1 for
symmetrical, 2 for asymmetrical). The radian frequencies of evaluation would be, for the asymmetrical
option
[
:
:
]
Rπ(
0
1
M
1
)/M
and for the symmetrical option
Rπ(
[−
(M
1 )/ 2
:
1
:
(M
1 )/ 2
]
)/M
( M odd )
Rπ(
[−
M/ 2
+
1
:
1
:
M/ 2
]
)/M
( M even )
The desired figure number is supplied as FigNo , an option allowing you to create different figures
for comparison with each other. A typical call is
Search WWH ::




Custom Search