You are on page 1of 30

1.

Aims and Objectives


To apply MATLAB commands as tool and perform the following Digital Signal Processing (DSP) Techniques and systems. a) b) c) d) e) f) Plot signals Implement the convolution of signals. Draw the frequency response curves. Plot the zeros and poles. Processing signals in the z-domain. Design Butterworth Low-Pass and High-Pass filter.

2. Requirements
This lab work specifically requires only the MATLAB & software only.

3. Introduction to MATLAB
MATLAB (matrix laboratory) is a numerical computing environment and fourth-generation programming language. Developed by MathWorks, MATLAB allows matrix manipulations, plotting of functions and data, implementation of algorithms, creation of user interfaces, and interfacing with programs written in other languages, including C, C++, Java, and Fortran. Although MATLAB is intended primarily for numerical computing, an optional toolbox uses the MuPAD symbolic engine, allowing access to symbolic computing capabilities. An additional package, Simulink, adds graphical multi-domain simulation and Model-Based Design for dynamic and embedded systems. In 2004, MATLAB had around one million users across industry and academia. MATLAB users come from various backgrounds of engineering, science, and economics. MATLAB is widely used in academic and research institutions as well as industrial enterprises. The MATLAB application is built around the MATLAB language. The simplest way to execute MATLAB code is to type it in the Command Window, which is one of the elements of the MATLAB Desktop. When code is entered in the Command Window, MATLAB can be used as an interactive mathematical shell. Sequences of commands can be saved in a text file, typically using the MATLAB Editor, as a script or encapsulated into a function, extending the commands available.

http://www.quora.com/Mathematics-Software/What-are-the-advantages-and-disadvantages-ofMatlab-versus-Mathematica-versus-Maple Matlab Strong:


huge linear algebra and numerical algorithms easy to learn script language suitable for fast mock up GUI and prototyping. possibly to integration C functions lots of free extensions for any needs (chemical/architecture/flotation etc)

Weak:

slow interpretor lack of library name conventions lack of object orientated features in my opinion use to many memmory

4. Experiments & Results


1) (a) Generate and plot a sampled sinusoidal periodic signal for the given specifications using MATLAB. Frequency Fo = 262 Hz Amplitude A = 2 V Sampling frequency FS = 8 kHz Phase parameter = /4 Figure 1-a-i : The programs written in the MATLAB command window to generate a sinusoidal periodic signal.

Figure 1-a-ii : The resulting waveform after executing all of the commands in Figure 1-a-i.

(b) Generate a non-sinusoidal periodic signal (sawtooth waveform) for the same Specification given in Question 1(a). Figure 1-b-i : The programs written command window to generate non-sinusoidal (sawtooth) periodic signal.

Figure 1-b-ii : Sawtooth waveform generated after executing all the commands shown in Figure 1-b-i.

2) Draw the magnitude and phase response curve using freqz command in MATLAB for the following transfer function: a) H(z) = 1 0.5z-1 1 + 0.5z-2

Figure 2-a-i : The programs written in the MATLAB command window to generate phase response curve.

Figure 2-a-ii : Resulting waveforms after executing all the commands above. 1 + 1.1z-1 1 0.1z-2

b) H(z) =

Figure 2-b-i : The programs written in the MATLAB command window to generate phase response curve.

Figure 2-b-ii : Resulting waveforms after executing all the commands above.

3) Plot the zeroes and poles for the transfer functions given in Question 2. Figure 3-a-i : The programs written in the MATLAB command window to generate the zeroes and poles plot diagram.

Figure 3-a-ii : The zeroes and poles plot diagram generated.

Figure 3-b-i : The programs written in the MATLAB command window to generate the zeroes and poles plot diagram.

Figure 3-b-ii : The zeroes and poles plot diagram generated.

4) The MATLAB commands for generating an impulse sequence is given below: function [x,n]=impseq(n0,n1,n2) n=[n1:n2]; x=[(n-n0)==0];

Figure 4 : The zeroes and poles plot diagram generated.

(a) What does the command x=[(n-n0)==0]do? Explain what each command do and its meaning. function [x,n]=impseq(n0,n1,n2) n=[n1:n2]; => => Generates x(n)= delta(n-n0); n1<=n<=n2 [x,n] = impseq(n0,n1,n2) if ((n0 < n1) | (n0 > n2) | (n1 > n2)) error('arguments must satisfy n1 <= n0 <= n2') end x = [zeros(1,(n0-n1)), 1, zeros(1,(n2-n0))]

x=[(n-n0)==0];

=>

(b) Use the function to generate the stem plot of the following sequence: (n) + (n 7) (n 3) Figure 4-b-i : The commands entered in the MATLAB command window to generate the stem plot diagram.

Figure 4-b-ii : The stem plot generated based on the commands above.

5) The MATLAB commands for generating a step sequence is given below: function [x,n]=stepseq(n0,n1,n2) n=[n1:n2]; x=[(n-n0)>=0];

(a) Explain the command x=[(n-n0)>=0].

function [x,n]=stepseq(n0,n1,n2) => Generates x(n) = u(n-n0); n1 <= n,n0 <=n=[n1:n2]; x=[(n-n0)>=0]; => [x,n] = stepseq(n0,n1,n2) if ((n0 < n1) | (n0 > n2) | (n1 > n2))

error('arguments must satisfy n1 <= n0 <= n2') end x=[(n-n0)>=0] => x = [zeros(1,(n0-n1)), ones(1,(n2-n0+1))];

Figure 5 : The commands keyed into the command window for the expression u(n-3) u(n-6)

(b) Use the function to generate the stem plot of the following sequence: u(n-3) u(n-6) Figure 5-b-i : The commands keyed into the command window for the expression u(n-3) u(n-6)

Figure 5-b-ii : The stem graph of the expression u(n-3) u(n-6) 6) Determine the convolution, y(n) = x1(n)*x2(n) and do a stem plot for y(n) given: (a) x1 (n) = {4, -2, 1} x2 (n) =

1, 0,

0<n<5 otherwise

For x1(n) n = {0, 1, 2,} x1(n) = {4, -2, 1} For x2(n) n = {0, 1, 2, 3, 4, 5, 6, 7} x2(n) = {1, 1, 1, 1, 1, 1, 0, 0} Calculating convolution the inputs above Inputs x1(n) 4 -2 1 x2(n) 1 4 -2 1 4 1 4 -2 1 2 1 4 -2 1 3 1 4 -2 1 3 1 4 -2 1 3 1 4 -2 1 3 0 0 0 0 -1 0 0 0 0 1 0 0

Convoluted Output

Table 6a Convolution result for Question 6(a)

Figure 6-a-i : The commands to perform convolution process using MATLAB.

Figure 6-a-ii : The stem diagram of indicating the convolution product of y(n).

(b)

x1 (n) = {1, 1, 3, 4, 5} x2 (n) = (n)

For x1(n) n = {0, 1, 2, 3, 4} x1(n) = {1, 1, 3, 4, 5} For x2(n) n = {0, 1, 2,} x1(n) = {4, -2, 1} Calculating convolution the inputs above Inputs 1 1 3 4 5 x2(n) 1 1 1 1 1 1 0 0

x1(n)

Convoluted Output Table 6b Convolution result for Question 6(b)

7) Using MATLAB, determine the partial-fraction expansion of z-transform G(z) given by:

G(z) =

18z3 18z3 + 3z2 + 4z 1

Figure 7 : The calculated results shown in MATLAB command window after inputting the equation above.

8) Design a Butterworth Low-Pass and High-Pass filter using MATLAB for the specifications given below: Pass Band Ripple Stop Band Ripple Pass Band Frequency = Stop Band Frequency = Sampling Frequency = = 0.15dB = 30dB 1500Hz 7000Hz 3000Hz

Figure 8 : The commands entered into MATLAB command window for Low-Pass filter, based on the values above.

Figure 8 : The resulting waveforms of the Low-Pass filter. To build a Butterworth High Pass filter using the same values given earlier, simply modify Line 17 of recent command window as: From: To: [b,a]=butter (n, wn, low, s); [b,a]=butter (n, wn, high, s);

Figure 8 : The commands entered for High-Pass filter after slight modification, using the same values previously.

Figure 8 : The resulting waveforms for High-Pass filter.

5.

Conclusion

Q5c stem diagram result Q6b

Q6b CW

6.

Reference

http://ewh.ieee.org/r1/ct/sps/PDF/MATLAB/chapter3.pdf

function [x,n] = impseq(n0,n1,n2) % Generates x(n) = delta(n-n0); n1 <= n,n0 <= n2 % ----------------------------------------------

% [x,n] = impseq(n0,n1,n2) % if ((n0 < n1) | (n0 > n2) | (n1 > n2)) error('arguments must satisfy n1 <= n0 <= n2') end n = [n1:n2]; %x = [zeros(1,(n0-n1)), 1, zeros(1,(n2-n0))]; x = [(n-n0) == 0];

function [x,n] = stepseq(n0,n1,n2) % Generates x(n) = u(n-n0); n1 <= n,n0 <= n2 % -----------------------------------------% [x,n] = stepseq(n0,n1,n2) % if ((n0 < n1) | (n0 > n2) | (n1 > n2)) error('arguments must satisfy n1 <= n0 <= n2') end n = [n1:n2]; %x = [zeros(1,(n0-n1)), ones(1,(n2-n0+1))]; x = [(n-n0) >= 0];

You might also like