ch04 5.pdf

In the name of Allah
Chapter 4&5
freqs:
The function freqs(b,a) can be used to calculate and plot frequency
response, where the vectors b and a contain the coefficients of a linear
constant-coefficient differential equation respectively. The ordering of the
coefficients in b and a is exactly the same as the ordering required for the
input to lsim (see tutorials of chapter 2).
If no output argument is supplied to freqs(b, a) the magnitude and phase of
H (ωi ) will be automatically plotted.
Note that the frequency axes and magnitude axis are scaled logarithmically
And only a finite interval of the frequency response is plotted.
If you desire H (ωi ) at particular values of ω, or would like to plot H (ωi ) over
a different range of frequencies than is automatically selected you can supply
these frequencies as inputs. For example, executing
>>w=linspace(0,3*pi);
>>H=freqs(b,a,w);
>> plot(w,abs(H))
Functions semilogy & semilogx and residue may be helpful.
fourier :
F = fourier(f) is the Fourier transform of the symbolic scalar f with default
independent variable x. The default return is a function of w. The Fourier
transform is applied to a function of x and returns a function of w.
Example :
>> f=sym('exp(-2*x)*Heaviside(x)');
>> fourier(f)
ans =
1/(2+i*w)
☺see also ifourier
freqz:
The command [H omega] = freqz( b, a, N ) computes the frequency
response H( ejω ) at N evenly spaced frequencies between 0 and π,
(i.e., ωk = (π / N) k for 0 ≤ k ≤ N -1). The coefficient vectors a and b
specify the difference equation using the same format as before ( see
previous PDFs ). For the above command, freqz returns H( ejω ) in H and the
frequencies ωk in omega. Including the ‘whole’ option as:
[H omega] = freqz( b, a, N, ‘whole’ )
computes the samples of the frequency response at N evenly spaced
frequencies from 0 to 2π.
Example:
Assume that y[ n ] – 0.8 y[ n - 1 ] = 2 x[ n ] – x[ n – 2 ]
>> a = [1, -0.8];
>> b = [ 2, 0, -1 ];
>> [H omega] = freqz( b, a, 4 )
H =
5.0000
2.8200-1.3705i
1.8293-1.4634i
0.9258-0.9732i
omega =
0
0.7854
1.5708
2.3562
You can see page 360 in the textbook, eq. (80-5) just to confirm this result.
☺see also freqzplot
fft:
First read exercise number 5-41 in textbook. If x is a vector containing x[n]
for 0 ≤ n ≤ M − 1 and N ≥ M then X=fft(x,N) compotes N evenly spaced
samples of the DTFT of x and stores these samples in the vector X .
ω k = 2πk / N for k = 0,..., N - 1 If N < M , then the MATLAB function fft truncates x
to its first N samples before computing the DTFT, thus yielding incorrect values
fore the samples of the DTFT.
Computer based exercises:
1-Plot frequency response of system y ' (t ) + 3 y (t ) = 3 x (t ) using plot and
freqs functions on interval [-4*pi,4*pi].Plot both phase and magnitude in
a single figure.
Name your mfile as p4_1.m
2a) Define symbolic expressions x1and x2 to represent the following
continuous-time signals
x (t ) = (1 / 2)e
1
x (t ) = e
2
− 4t
− 2t
u (t )
u (t )
You well need to use the function Heaviside to represent the unit step function
u(t) in
>> x1=sym(‘(1/2)*exp(-2*t)*Heaviside(t)‘);
>> x2=sym(‘exp(-4*t)*Heaviside(t)’);
b) For x1 and x2 defined in part (a), analytically compute the value of their CTFTs
evaluated at w=0, i.e., X(wi) at w=0. You should not compute X(wi) to do this. How
is the CTFT at w=0 related to the time-domain signals?
c) Which of the signals defined above decays faster in the time domain? Based on
this, which do you expect to decay more rapidly in frequency?
d) Use the function fourier to compute the CTFTs of x1(t) and x2 (t).Use ezplot to
generate plots of the magnitudes of X1(wi) and X2(wi). Do these plots confirm your
answers to part b and c?
name your file as : p4_2.m
3Use plot and fft to estimate frequency response of function
x[ n ] = u[ n ] − u[ n − 11] for N=100 samples of DTFT. Plot it in interval [-π,π].
Function fftshift can be useful to swap the second half of the vector X with the
first half.
Name your mfile as ch5_1.m
Name your zipped file as your student ID.
Deadline: 1382/10/6
[email protected]