Digital Signal Processing a.y. 2007-2008
Matlab Laboratory # 1 Discrete-time signals and systems Giacinto Gelli
[email protected]
Giacinto Gelli
DSP Course – 1 / 5
Discrete-time signals • Discrete-time signal x[n] ⇒ represented by a pair of Matlab vectors n (time) and x (amplitude)
• Example: n = [-3,-2,-1,0,1,2,3]; x = [2,1,-1,0,1,4,3]; • Graphical representation: command stem(n,x) (not plot! check the difference!)
• Exercises: (a) Generate/plot x[n] = RN [n] (rectangular window in 0 ≤ n ≤ N − 1). (b) Generate/plot x[n] = u[n]. (c) Generate/plot x[n] = δ[n]. (d) Generate/plot x[n] = A(α)n u[n] (the 6 cases on a single figure using subplot. (e) Generate/plot x[n] = A cos(ω0 n + φ) (check frequency/time periodicity). Giacinto Gelli
DSP Course – 2 / 5
Signal operations • Operations on two or more signals require that the signal be defined on the same time interval.
• Time-shifting and reflection operates only on the vector n. • Exercises: (a) Given the signal x[n], write a Matlab function [y,n] = time shift(x,n,n0) for evaluating y[n − n0 ] for arbitrary values of n0 ∈ Z. Test it with the signal x[n] = (0.9)n u[n] for −5 ≤ n ≤ 20 and n0 = ±10, plot the results and comment. (b) Given the signal x[n], write a Matlab function [y,n] = time reverse(x,n) for evaluating y[n] = x[−n] (use the command fliplr or flipud). Test it with the signal x[n] = R3 [n], plot the results and commment.
Giacinto Gelli
DSP Course – 3 / 5
Discrete-time systems and convolution (1/2) • Convolution y[n] = x[n] ∗ h[n] is performed using the command y =
conv(x,h). • Limitations: (a) x[n] and h[n] must be finite-length sequences or must be truncated ⇒ can be used only for FIR filters (for the general case use the command filter instead). (b) The command conv does not allow one to specify the time-interval.
Giacinto Gelli
DSP Course – 4 / 5
Discrete-time systems and convolution (2/2) • Exercises: (a) Write a Matlab script for evaluating the convolution between h[n] = RN (n) and x[n] = an u[n] for N = 4 and a = 0.8 (a critical point is truncation of the infinite-length x[n], try to find an appropriate criterion). Plot the results and comment. (b) The command conv can alos be used for poynomial multiplication. Use it to perform multiplication between the two polynomials P1 (z −1 ) = 1 − 21 z −1 and P2 (z −1 ) = 1 + 43 z −1 . Check with the analytical solution.
Giacinto Gelli
DSP Course – 5 / 5