Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.

Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.

Like this document? Why not share!

- Digital Signal Processing Lab Manua... by UR11EC098 60419 views
- digital signal-processing-lab-manual by Ahmed Alshomi 2064 views
- DSP Lab Manual (10ECL57) - VTU Syll... by Ravikiran A 18862 views
- Signal Prosessing Lab Mannual by Jitendra Jangid 12238 views
- Digital signal processing (2nd ed) ... by Ramesh Sundar 24760 views
- Dsp lab manual by Mukul Mohal 2156 views

No Downloads

Total views

11,956

On SlideShare

0

From Embeds

0

Number of Embeds

10

Shares

0

Downloads

1,058

Comments

0

Likes

7

No embeds

No notes for slide

- 1. TABLE OF CONTENTSLAB # 1: INTRODUCTION TO MATLAB ………………………………... 3LAB # 2: BASIC SIGNALS & SYSTEMS …………………………………..11LAB # 3: SAMPLING AND ALIASING ……………………………………15LAB # 4: CONVOLUTION AND FILTERING …………………………… 19LAB # 5: Z TRANSFORM IN MATLAB …………………………………... 30LAB # 6: DISCRETE FOURIER TRANSFORM (DFT) IN MATLAB …….. 37LAB # 7: FIR DIGITAL FILTERS ………………………………………… 40LAB # 8: IIR DIGITAL FILTERS ………………………………….……… 42LAB # 9: FILTER DESIGN USING ANALOG PROTOTYPING ……….… 45LAB # 10: INTRODUCTION TO IMAGE PROCESSING IN MATLAB ….. 49LAB # 11: PERIODIC WAVE GENERATORS …………………………... 57LAB # 12: NOISE REDUCTION & SIGNAL ENHANCEMENT ………… 63LAB # 13: SIGNAL PROCESSING TOOLBOX (PART-1) ……………...... 67LAB # 14: SIGNAL PROCESSING TOOLBOX (PART-2) .……….…........ 72 DSP Lab Manual -2- Zulfiqar Ali
- 2. LAB # 1 : INTRODUCTION TO MATLABOVERVIEW…Over the past few decades, the unbelievable progress in the field of digital signal processing hasaltered the entire meaning of the word ‘impossible’, by thinking the unthinkable and doing theun-doable. With an ever-increasing set of applications, signal processing has crept into almostevery sphere of science, and today, we see the techniques and tools developed by DSP scientistsand engineers being utilized for a better understanding and investigation of the universe, andhence the life. This field of knowledge has helped us to stretch our limits--- the very limits ofthinking and imagination; the most cherish-able outcome of all the knowledge. As our firstcourse on DSP, we’ll try to familiarize ourselves with the concepts and theory of DSP, to have alook at and use the tools to solve the practical problems, and to have a flavor of the problems andthe challenges faced by man in the past, as well as today. MATLAB is the most popular tool used for Digital Signal Processing. It provides one ofthe strongest environments for study and simulation of the real-world problems and theirsolutions, especially in the field of engineering. For Signal Processing, it has a verycomprehensive and easy-to-use toolbox with lots of DSP functions implemented. Moreover, withthe aid of Simulink, we can create much more complex situations very easily, and solve them.In this lab…we would have an introduction to MATLAB and get started with working in itswonderfully simple environment. This lab, as a matter of fact, would lay the foundation for ournext labs. In the following paragraphs, you are provided with a tutorial on MATLAB. In addition,we’ll go over a detailed introduction to MATLAB in our first discussion session. This wouldenable to you to do the simple but useful things in MATLAB.DEFINITION OF VARIABLESVariables are assigned numerical values by typing the expression directly, for example, typinga = 1+2;yields: a = 3;The answer will not be displayed when a semicolon is put at the end of an expression, forexample typea = 1+2; DSP Lab Manual -3- Zulfiqar Ali
- 3. MATLAB utilizes the following arithmetic operators: + addition - subtraction * multiplication / division ^ power operator transposeA variable can be assigned using a formula that utilizes these operators and either numbers orpreviously defined variables. For example, since a was defined previously, the followingexpression is validb = 2*a;To determine the value of a previously defined quantity, type the quantity by itself:byields: b = 6;If your expression does not fit on one line, use an ellipsis (three or more periods at the end of theline) and continue on the next line.c = 1+2+3+...5+6+7;There are several predefined variables which can be used at any time, in the same manner asuser-defined variables: i sqrt(-1) j sqrt(-1) pi 3.1416...For example,y= 2*(1+4*j);yields: y = 2.0000 + 8.0000i; DSP Lab Manual -4- Zulfiqar Ali
- 4. PRE DEFINED FUNCTIONS IN MATLABThere are also a number of predefined functions that can be used when defining a variable. Somecommon functions that are used in this text are: magnitude of a number (absolute abs value for real numbers) Angle of a complex number, in angle radians cosine function, assumes argument is cos in radians sine function, assumes argument is in sin radians exp exponential functionFor example, with y defined as above,c = abs(y);yields: c = 8.2462;c = angle(y);yields: c = 1.3258;With a=3 as defined previously,c = cos(a);yields: c = -0.9900;c = exp(a);yields: c = 20.0855;Note that exp can be used on complex numbers. For example, with y = 2+8i as defined above,c = exp(y);yields: c = -1.0751 + 7.3104i;which can be verified by using Eulers formula:c = exp(2)*cos(8) + j*(exp)2*sin(8); DSP Lab Manual -5- Zulfiqar Ali
- 5. DEFINITION OF MATRICESMATLAB is based on matrix and vector algebra; even scalars are treated as 1x1 matrices.Therefore, vector and matrix operations are as simple as common calculator operations.Vectors can be defined in two ways. The first method is used for arbitrary elementsv = [1 3 5 7];creates a 1x4 vector with elements 1, 3, 5 and 7. Note that commas could have been used in placeof spaces to separate the elements. Additional elements can be added to the vector:v(5)=8;yields the vector v = [1 3 5 7 8]. Previously defined vectors can be used to define a new vector.For example, with ‘v’a= [9 10];b= [v a];creates the vectorb = [1 3 5 7 8 9 10].The second method is used for creating vectors with equally spaced elements:t = 0: 0.1:10;creates a 1x101 vector with the elements 0, .1, .2, .3,...,10. Note that the middle number definesthe increment. If only two numbers are given, then the increment is set to a default of 1k = 0:10;creates a 1x11 vector with the elements 0, 1, 2, ..., 10.Matrices are defined by entering the elements row by row:M = [1 2 4; 3 6 8];creates the matrix.There are a number of special matrices that can be defined:null matrix: DSP Lab Manual -6- Zulfiqar Ali
- 6. M = [ ];nxm matrix of zeros:M = zeros(n,m);nxm matrix of ones:M = ones(n,m);nxn identity matrix:M = eye(n);A particular element of a matrix can be assigned:M(1,2) = 5;places the number 5 in the first row, second column.Operations and functions that were defined for scalars in the previous section can also be used onvectors and matrices. For example,a= [1 2 3];b= [3 4 5];c= a + b;yields: c =[5 7 9];Functions are applied element by element. For example,t=0:10;x=cos(2*t);creates a vector x with elements equal to cos(2t) for t = 0, 1, 2, ..., 10.Operations that need to be performed element-by-element can be accomplished by preceding theoperation by a ".". For example, to obtain a vector x that contains the elements of x(t) = tcos(t) atspecific points in time, you cannot simply multiply the vector t with the vector cos(t). Insteadyou multiply their elements together:t=0:10;x = t .*cos(t);M-FILESM-files are macros of MATLAB commands that are stored as ordinary text files with theextension "m", that is ‘filename.m’. An M-file can be either a function with input and outputvariables or a list of commands. MATLAB requires that the M-file must be stored either in theworking directory or in a directory that is specified in the MATLAB path list. For example, DSP Lab Manual -7- Zulfiqar Ali
- 7. consider using MATLAB on a PC with a user-defined M-file stored in a directory called "MATLABMFILES". Then to access that M-file, either change the working directory bytyping cdmatlabmfiles from within the MATLAB command window or by adding the directoryto the path. Permanent addition to the path is accomplished by editing the MATLABmatlabrc.mfile, while temporary modification to the path is accomplished by typingpath(path,matlabmfiles)from within MATLAB. Or, this can easily be achieved through the path browser. As example ofan M-file that defines a function, create a file in your working directory named yplusx.m thatcontains the following commands:function yplusx(y,x)z=y+xThe following commands typed from within MATLAB demonstrate how this M-file is used:x=2y=3z = yplusx(y,x)All variables used in a MATLAB function are local to that function only. Variables which areused in a script m-file which is not a function are all global variables.MATLAB M-files are most efficient when written in a way that utilizes matrix or vectoroperations. Loops and if statements are available, but should be used sparingly since they arecomputationally inefficient. An example of the use of the command for isfor k=1:10;x(k) = cos(k);endThis creates a 1x10 vector x containing the cosine of the positive integers from 1 to 10. Thisoperation is performed more efficiently with the commandsk= 1:10;x=cos(k);which utilizes a function of a vector instead of a for loop. An if statement can be used to defineconditional statements. An example isif(a<=2);b=1;elseif(a>=4)b=2;elseb=3;The allowable comparisons between expressions are >=, <=, <, >, ==, and ~=. DSP Lab Manual -8- Zulfiqar Ali
- 8. Suppose that you want to run an M-file with different values of a variable T. The followingcommand line within the M-file defines the value:T = input(Input the value of T: )Whatever comment is between the quotation marks is displayed to the screen when the M-file isrunning, and the user must enter an appropriate value.PLOTTING GRAPHSCommands: plot, xlabel, ylabel, title, grid, axis, axes, stem, subplot, zoom, holdThe command most often used for plotting is plot, which creates linear plots of vectors andmatrices; plot(t,y) plots the vector t on the x-axis versus vector y on the y-axis. There are optionson the line type and the color of the plot which are obtained using plot(t,y,option). The linetypeoptions are - solid line (default), -- dashed line, -. dot dash line, : dotted line. The points in ycan be left unconnected and delineated by a variety of symbols: + . * o x. The following colorsare available options: r, g, b, k, y, m etc.For example, plot(t,y,--) uses a dashed line, plot(t,y,*) uses * at all the points defined in t and ywithout connecting the points, and plot(t,y,g) uses a solid green line. The options can also beused together, for example, plot(t,y,g:) plots a dotted green line.To plot two or more graphs on the same set of axes, use the command plot(t1,y1,t2,y2), whichplots y1 versus t1 and y2 versus t2.To label your axes and give the plot a title, typexlabel (‘time (sec)’)ylabel(‘step response’)title(‘my plot’)Finally, add a grid to your plot to make it easier to read. TypegridThe problem that you will encounter most often when plotting functions is that MATLAB willscale the axes in a way that is different than you want them to appear. You can easily overridethe auto scaling of the axes by using the axis command after the plotting commandaxis([xmin xmax ymin ymax]);where xmin, xmax, ymin, and ymax are numbers corresponding to the limits you desire for theaxes. To return to the automatic scaling, simply type axis.For discrete-time signals, use the command stem which plots each point with a small open circleand a straight line. To plot y[k] versus k, typestem(k,y) DSP Lab Manual -9- Zulfiqar Ali
- 9. You can use stem(k,y,filled) to get circles that are filled in.To plot more than one graph on the screen, use the command subplot(mnp) which partitions thescreen into an mxn grid where p determines the position of the particular graph counting theupper left corner as p=1. For example,subplot(211),semilogx(w,magdb);subplot(212),semilogx(w,phase);plots the bode plot with the log-magnitude plot on top and the phase plot below. Titles and labelscan be inserted immediately after the appropriate semilogx command or plot command. Toreturn to a full screen plot, typesubplot(111).SAVING & LOADINGWhen using MATLAB, you may wish to leave the program but save the vectors and matricesyou have defined. To save the file to the working directory, typesave filenamewhere "filename" is a name of your choice. To retrieve the data later, typeload filenameGENERAL INFORMATION • MATLAB is case sensitive so "a" and "A" are two different names. • Comment statements are preceded by a "%". • You can make a keyword search by using the help command. • The number of digits displayed is not related to the accuracy. To change the format of the display, type format short e for scientific notation with 5 decimal places, format long e for scientific notation with 15 significant decimal places and format bank for placing two significant digits to the right of the decimal. • The commands who and whos give the names of the variables that have been defined in the workspace. • The command length(x) returns the length of a vector x and size(x) returns the dimension of the matrix x. DSP Lab Manual - 10 - Zulfiqar Ali
- 10. LAB # 2 : BASIC SIGNALS & SYSTEMSUNIT IMPULSE ⎧1 , if n = 0δ [n ] = ⎨ ⎩ 0 , o th e rw is e 1 0.5 0 -10 -5 0 5 10 ⎧1 if n = nδ [n − n 0 ] = ⎨ 0 ⎩ 0 o th e rw is e 1 0.5 0 -10 -5 0 5 10UNIT STEPU[n] = 1 n≥0 0 otherwise 1 0.5 0 -10 -5 0 5 10 Graph of U [n]U [ n - no ] = 1 n ≥ no 0 otherwise 1 0.5 0 -10 -5 0 5 10 Graph of U [n+5] DSP Lab Manual - 11 - Zulfiqar Ali
- 11. PROBLEM 1:(A) Implement a function for generating and plotting x[ n ] = m δ [ n − n 0 ] fo r a ≤ n ≤ b Try it for (i) n0 = 5, m = 0.9, a = 1, b = 20 (ii) n0 = 0, m = 0.8, a = -15, b = 15 (iii) n0 = 333, m = 1.5, a = 300, b = 350 (iv) n0 = -7, m = 4.5, a = -10, b = 0(B) Implement and plot the following equation. You can use function created in part (A) 4 ∑ l = 0 A l δ [ n − 3 l ]The values are A0=2 , A1=4 , A2=6 , A3=8 , A4=10 & -5 ≤ n ≤ 15PROBLEM 2:(A) Implement a function for generating and plotting x [n] = m U [ n – no ] for a ≤ n ≤ bYou can implement above signal by modifying function in Problem 1 part (A)Try it for (v) n0 = 10, m = 1.9, a = 1, b = 20 (vi) n0 = 0, m = 1.8, a = -20, b = 20 (vii) n0 = 333, m = 0.5, a = 300, b = 350 (viii) n0 = -7, m = 4.5, a = -10, b = 0PROBLEM 3:(A) Generate and plot x 1 [ n ] = s i n (π n / 1 7 ) 0 ≤ n ≤ 25 x 2 [ n ] = s i n (π n / 1 7 ) -1 5 ≤ n ≤ 2 5 x 3 [ n ] = s i n ( 3π n + π / 2 ) -1 0 ≤ n ≤ 1 0(B) Implement a function for DSP Lab Manual - 12 - Zulfiqar Ali
- 12. x [ n ] = A c o s (ω 0 n + φ ) fo r a ≤ n ≤ b Run the above function by giving it the following values A = 2; ω 0 = π / 1 1; φ = 0 ; a = - 2 0 ; b = 2 0PROBLEM 4:Consider a continuous time signal x (t) = A cos (w t + Ф) .We can sample a continuoustime signal at equally spaced time instants T = nTs and get a discrete time signal x[n] = x (nTs).The individual values of x[n] are called samples of continuous time signal. The fixed timeinterval between samples, Ts, can also be expressed as a fixed sampling rate, Fs, in samples persecond.Fs = 1 / Ts (samples / second)If we sample x (t) = A cos (w t + Ф) using this approach, then by using t = nTs we get x[n] = x(nTs) = A cos (w nTs + Ф) = A cos (ŵ n + Ф).Here we have defined ŵ = wTs = w / Fs.The signal x[n] is a discrete time cosine signal, and ŵ is its discrete time frequency. We use a “hat ” over w to denote that this is a new frequency variable. It is a normalized version of thecontinuous time radian frequency with respect to the sampling frequency. (A) Generate and plot the signal x (t) = A cos (w t + Ф) with the following values A=3, Frequency=100 Hz, t = - 0.01: 0.00001: 0.02 and Ф = 0 (B) Generate and plot the Discrete time signal x[n] from the Continuous time signal x (t) using values in part (A) .Use the sampling frequency Fs=2000 (C) Repeat part (B) for Fs=500. NOTE: All the plots should be in the same window as shown in the figure below. Use subplot command for this purpose DSP Lab Manual - 13 - Zulfiqar Ali
- 13. 1 0 -1 -0.01 -0.005 0 0.005 0.01 0.015 0.02 Continuous Time signal X (t) ( f = 100 Hz ) 1 0 -1 -20 -10 0 10 20 30 40 Discrete Time signal X [n] ( Fs = 2000 Hz ) 1 0 -1 -5 0 5 10 Discrete Time signal X [n] ( Fs = 500 Hz )PROBLEM 5:Write MATLAB coding for plotting the following Continuous Time Signals in same window.Use the value of ts = 0.001 and t = -2 : ts : (2 – ts) 1 0.5 0 -2 -1.5 -1 -0.5 0 0.5 1 1.5 2 0 -0.5 -1 -2 -1.5 -1 -0.5 0 0.5 1 1.5 2 DSP Lab Manual - 14 - Zulfiqar Ali
- 14. LAB # 3 : SAMPLING AND ALIASINGPERIODIC SIGNALSA sequence X [n] is said to be periodic when it satisfies the following relation X[n]=X[n+ N]The fundamental period of the signal is defined as the smallest positive value of ‘N’ for whichabove equation holds true.Now consider a signal Y [n] which is formed by the addition of the two signals x1[n] and x2[n]. Y [ n ] = X 1[ n ] + X 2[ n ]If the signal x1[n] is periodic with the fundamental period ‘N1’ and x2[n] is periodic with thefundamental period ‘N2’ , then the signal y[n] will be periodic with the period ‘N’ given by thefollowing relation N= ( N1 x N2 ) __________________________________ ( greatest common divisor ( N1 , N2 ) )THE SAMPLING THEORM“A continuous time signal x (t) with frequencies no higher than Fmax can be reconstructedexactly from its samples x[n] = x (n Ts), if the samples are taken at a rate Fs = 1 / Ts that isgreater than 2Fmax”Fs ≥ 2Fmax The minimum sampling rate of 2Fmax is called the Nyquist Rate .From Sampling theorem itfollows that the reconstruction of a sinusoid is possible if we have at least 2 samples per period.If we don’t sample at a rate that satisfies the sampling theorem then aliasing occursSAMPLING A CONTINUOUS TIME SIGNALFor example we want to sample continuous time signal x = cos (100 π t). The frequency of thissignal is 50 Hz and according to sampling theorem the minimum sampling frequency should be100 samples / sec .But we sample it at a rate much higher than the Nyquist rate so that it hasmany samples over one cycle giving an accurate representation of the sampled discrete timesignal.In the figure below the continuous time signal x = cos (100 π t) is sampled atFs=1000 (samples / second).Therefore it will have Fs / F = 1000 / 50 = 20 (samples per cycle) DSP Lab Manual - 15 - Zulfiqar Ali
- 15. 1 0.5 0 -0.5 -1 0 5 10 15 20 25 30 35 40 x=cos(100*pi*t) sampled with Fs=1000 (samples / sec)CONCEPT OF ALIASINGConsider the general formula for a discrete time sinusoid X = cos ( ŵ π n + Ф ). Now consider x1= cos ( 0.1 π n ) , x2 = cos ( 2.1 π n ) and x3 = cos ( 1.9 π n ) apparently with different values of“ ŵ ”. If we display the graph of these 3 signals over the range n = 0:40 then we see that all theabove 3 signals are equivalent. 1 0 -1 0 5 10 15 20 25 30 35 40 cos(0.1*pi*n) 1 0 -1 0 5 10 15 20 25 30 35 40 cos(2.1*pi*n) 1 0 -1 0 5 10 15 20 25 30 35 40 cos(1.9*pi*n)Therefore the signals x1 , x2 and x3 are different names for the same signal. This phenomenon iscalled aliasing. The signals x2 and x3 are called aliases of the signal x1.Coding for plotting theabove 3 signals is shown belown=1:40;x1=cos(0.1*pi*n);x2=cos(2.1*pi*n);x3=cos(1.9*pi*n);subplot(311);stem(n,x1);grid;xlabel(cos(0.1*pi*n));subplot(312);stem(n,x2);grid;xlabel(cos(2.1*pi*n));subplot(313);stem(n,x3);grid;xlabel(cos(1.9*pi*n)); DSP Lab Manual - 16 - Zulfiqar Ali
- 16. PROBLEM 1:Consider the signal Y=X1+X2 X 1 = cos( n π / 12 ) X 2 = sin( n π / 18 ) (A) Determine the value of ‘ N1 ’ and plot the signal X1 over the range n=0:(2*N1) Verify from graph that there are 2 complete cycles of the signal X1 (B) Determine the value of ‘ N2 ’ and plot the signal X2 over the range n=0:(2*N2) Verify from graph that there are 2 complete cycles of the signal X2 (C) Determine the value of ‘ N ’ and plot the signal y over the range n=0:(3*N) Verify from graph that there are 3 complete cycles of the signal Y (D) Examine graphically that X1 repeats itself after ‘ N1 ’, X2 repeats itself after ‘ N2 ’ and Y repeats itself after ‘ N ’samplesPROBLEM 2:Sample the signal xt = 5*sin (150 π t) to get sampled signal xn = 5*sin (150 π n Ts) such thatthere is no aliasing . Choose an appropriate value of sampling frequency ”fs” and choose ”t”such that the graph contains 4 cycles of the signal and each cycle has 22 samples.Plot both signals xt and xn in the same window.PROBLEM 3:Consider the signals g1t = cos(w1*t), g2t = cos(w2*t) and g3t = cos(w3*t)with the frequencies f1=3 Hz,f2=7 Hz, f3=13 Hz and t = -0.5:0.0005:0.5;Sample the signals g1t, g2t and g3t to get g1n, g2n and g3n respectively. Use samplingfrequency “Fs” values given below. Display all the six signals in the same window using“subplot” command and observe the output for each value of “Fs”. Explain for which values of“Fs” aliasing occurs and why? A. Fs=10 B. Fs=13 C. Fs=26 DSP Lab Manual - 17 - Zulfiqar Ali
- 17. D. Fs=52 E. Fs=80 F. Fs=130PROBLEM 4:Consider a signal X 1 = cos ( 0.25 π n ) over the range n=0:40 .What will be the aliases of thesignal X1.Plot the signal X1 and its 2 aliases all in the same window using “subplot” command.Observe graphically that all the aliases of X1 have the same graph. Actually a signal can haveinfinite number of aliases. DSP Lab Manual - 18 - Zulfiqar Ali
- 18. LAB # 4 : CONVOLUTION AND FILTERINGA linear time invariant (LTI) system is completely characterized by its impulse response h[n].“We can compute the output y[n] due to any input x[n] if know the impulse response of thatsystem”. We say that y[n] is the convolution of x[n] with h[n] and represent this by notation y[n] = x[n] * h[n] = ∑ x[ k ] h[ n – k ] - ∞ ≤ k ≤ +∞ Equation A = h[n] * x[n] = ∑ h[ k ] x[ n – k ] - ∞ ≤ k ≤ +∞The operation of the discrete time convolution takes two sequences x[n] and h[n] and produces athird sequence y[n].Above equation expresses each sample of the output sequence in terms of allthe samples of the input and the impulse response sequences CONVOLUTION IMPLEMENTATION IN MATLABIn Matlab “CONV” function is used for “convolution and polynomial multiplication”.y = conv(x, h) convolves vectors x and h. The resulting vector ‘y’ is of “length(A)+length(B)-1”If ‘x’ and ‘h’ are vectors of polynomial coefficients, convolving them is equivalent tomultiplying the two polynomialsSuppose we want to convolve the 2 signals x[n] and h[n] shown in the figure below. We willwrite their values and then use the Matlab command “conv” to convolve the 2 signals and get theresult of convolution y[n] between x[n] and h[n].This example is on Page 24 of your Text Book 1.5 1 1 0.8 0.5 0.6 0 0.4 -0.5 0.2 -1 0 -5 0 5 -5 0 5 Signal x[n] Impulse Response h[n] 2 1 0 -1 -10 -5 0 5 10 y[n] ( Result of Convolution b/w x[n] and h[n] ) DSP Lab Manual - 19 - Zulfiqar Ali
- 19. The coding for performing the Discrete time convolution between the signal x[n] and its impulseresponse h[n] (shown in the graph above) and getting the desired convolved signal y[n] is givenbelow Example # 1: Convolution Matlab Implementationxn= [0,0,0,1,0,4/3,0,0,-1,0,0];hn= [0,0,0,0,0,1,2/3,1/3,0,0,0];yn=conv(xn,hn);n=-5:5;subplot(221);stem(n,xn,filled);xlabel(Signal x[n]);gridsubplot(222);stem(n,hn,filled);xlabel(Impulse Response h[n]);gridsubplot(223);stem([-10:10],yn,filled);xlabel(y[n] ( Result of Convolution b/w x[n] and h[n]));grid MOVING AVERAGE FILTERThe general moving average system is defined by the equation 1 M2y[ n ] = ----------------- ∑ x [ n – k ] Equation B (M1+M2+1) k = - M1Such a system is often used in smoothing random variations in data.Consider for example a signal s[n] corrupted by a noise d[n], resulting in a measured datasequence given by x[n]x[ n ] = s[ n ] + d[ n ] Equation C ns[n] = 2[ n (0.9) ] Equation DHere the Original Signal is s[n] and d[n] is the unwanted random noise and x[n] is themeasured signal corrupted with noise. We would like to reduce the effect of the noise d[n] andget a better estimate of s[n] from x[n].Noise reduction can be achieved by passing the signal x[n] through a moving average filter thuseliminating the random variations in dataNow let us apply the moving average filter with M1=0 , M2=9 to the signal x[n]to get thefiltered signal y[n].We substitute the values of M1 and M2 in “equation B” giving the followingexpressions DSP Lab Manual - 20 - Zulfiqar Ali
- 20. 9y[ n ] = (1/10) ∑ x [ n – k ] Equation E k=0By using definition of the impulse response if the input x[n] is impulse ∂ [n] then the output y[n]becomes the impulse response h[n] given by following expressionh[ n ] = 0.1( ∂ [ n ] + ∂ [ n – 1 ] + ∂ [ n – 2 ] + ∂ [ n – 3 ] + ∂ [ n – 4 ] + ∂ [ n – 5] +∂ [ n – 6 ] + ∂ [ n – 7] + ∂ [ n – 8 ] + ∂ [ n – 9 ] ) 0.1 0.05 0 0 1 2 3 4 5 6 7 8 9 Impulse Response h[n] of Moving average filter for M1=0 , M2=9Now we have the equation of the impulse response h[n] of the moving average filter with M1 = 0and M2 = 9. So we can convolve the signal x[n] and the impulse response h[n] to get the filteredsignal y[n] .Given below is the coding for filtering the signal x[n] with moving average filterwith M1=0 and M2=9 using the “conv” command of Matlab. Example # 2 : Signal Smoothing Using Moving Average Filtern=1:1:200;sn=2*n.*(0.9.^n);dn=rand(1,length(n))-0.5;xn=sn+dn;M1=0;M2=9;hn=(1/(M1+M2+1))*ones(1,M1+M2+1);yn=conv(xn,hn);subplot(211);plot(n,xn);xlabel(Signal Corrupted with Noise x[n] = s[n] + d[n]);gridsubplot(212);plot(n,yn(1:length(n)));xlabel(Filtered Signal y[n] using Moving Average Filter M1=0 , M2=9);grid DSP Lab Manual - 21 - Zulfiqar Ali
- 21. 10 5 0 -5 0 20 40 60 80 100 120 140 160 180 200 Signal Corrupted with Noise x[n] = s[n] + d[n] 10 5 0 -5 0 20 40 60 80 100 120 140 160 180 200 Filtered Signal y[n] using Moving Average Filter M1=0 , M2=9 FREQUENCY RESPONSE OF THE MOVING AVERAGE FILTERFrom Equation B the general equation of moving average filter is given by 1 M2y[ n ] = __________ ∑ x[n–k] Equation B (M1+M2+1) k = - M1Therefore the Impulse response of the moving average filter can be expressed as 1 M2h[ n ] = ___________ ∑ ∂[n–k] Equation F (M1+M2+1) k = - M1 1 { - M1 ≤ n ≤ M2h[ n ] = __________ Equation G (M1+M2+1) { 0 otherwiseThe frequency response is given by the equation jw +∞ -j w nH (e ) = ∑ h [n] e Equation H n=-∞ DSP Lab Manual - 22 - Zulfiqar Ali
- 22. Therefore substituting the value of “ h[n] ” from “equation G” in “equation H” gives following jw 1 +M2 -j w nH (e )= __________ ∑ e Equation I (M1+M2+1) n = - M1 jw 1 sin[w(M1+M2+1)/2] -j w( M2-M1) / 2H (e ) =___________ e (M1+M2+1) sin(w/2) Equation JThis example is on Page 45 of your Text Book. In this example we will plot the Magnitude andPhase of the frequency response of the moving average filter with M1=0 and M2=4 over therange -2π ≤ w ≤ +2π .Substituting the values of M1 and M2 in “Equation I” above we get thefollowing expression jw 1 +4 -j w nH (e ) = ____ ∑ e Equation K 5 n=0 jw 1 -j w 0 -j w 1 -j w 2 -j w 3 -j w 4H (e ) =______ ( e + e +e + e + e ) 5 Equation M Example # 3: Frequency Response Implementation of Moving Average Filterw=-2*pi:0.01:2*pi;Hejw=(1/5)*(1+exp(-j*w)+exp(-j*w*2)+exp(-j*w*3)+exp(-j*w*4));subplot(211);plot(w,abs(Hejw));xlabel(Magnitude response of Moving Average Filter with M1=0 , M2=4 );subplot(212);plot(w,angle(Hejw));xlabel(Phase Response of Moving Average Filter with M1=0 , M2=4 ); DSP Lab Manual - 23 - Zulfiqar Ali
- 23. 1 0.5 0 -8 -6 -4 -2 0 2 4 6 8 Magnitude response of Moving Average Filter with M1=0 , M2=4 4 2 0 -2 -4 -8 -6 -4 -2 0 2 4 6 8 Phase Response of Moving Average Filter with M1=0 , M2=4 MOVING AVERAGE FILTER ACTS AS LOW PASS FILTERThis example is on Page 45 of your Text BookFrom Equation J jw 1 sin(w(M1+M2+1)/2) -j w( M2-M1) / 2H (e ) = __________ ___________________ e (M1+M2+1) sin(w/2) Equation JTherefore we see that the Magnitude of the frequency response will be zero if the followingcondition is true.Sin(w(M1+M2+1)/2) = Sin( π k )For M1=0 and M2=4 we have the following relationsSin(w5/2)= Sin( π k ) where k is an integerTherefore w5/2= π k w=2 π k / 5 Equation NWe can check that at frequencies given by equation N the magnitude of the frequency responseof moving average filter with M1=0 and M2=4 will be zero. This can be achieved by using thefollowing commands DSP Lab Manual - 24 - Zulfiqar Ali
- 24. k=1:4w= (2*pi*k)/5;Hejw=(1/5)*(1+exp(-j*w)+exp(-j*w*2)+exp(-j*w*3)+exp(-j*w*4));Mag=abs(Hejw)Matlab gives the following answerMag = 1.0e-015 *( 0.0314 0.0666 0.0702 0.1391)“We can see that values of Mag are almost equal to zero. Thus the result is that if we pass anysinusoidal signal with any frequency given by “Equation N” then that sinusoidal signal will becompletely removed by the moving average filter. From the Graph of the magnitude response ofmoving average filter we can easily see that the Higher frequency components (closer to w = pi)are more attenuated than the lower frequency components (closer to w=0).Therefore the MovingAverage Filter acts as a Low Pass Filter. This attenuation of High frequencies suggests that thesystem will smooth out rapid variations in the input sequence. In other words the system is arough approximation to a Low Pass Filter”Now we will pass a signal x[n] = sin (2 π n / 5) + sin (0.1 π n) through the moving average filterwith M1=0 and M2=4 and observe the filtered signal. In this case we note that the signal x[n]consists of 2 frequency components i.e. the lower frequency component sin (0.1 π n ) andthe higher frequency component sin (2 π n / 5).From above discussion we can easily say that the lower frequency component sin (0.1 π n ) willeasily pass through the Moving Average Filter while the higher frequency component of sin (2 π/ 5) will be completely removed by the filter. This can be checked by using the followingcommandsw=[(2*pi)/5 , 0.1*pi];Hejw=(1/5)*(1+exp(-j*w)+exp(-j*w*2)+exp(-j*w*3)+exp(-j*w*4));Mag=abs(Hejw)Matlab gives the following resultMag = 0.0000 0.9040Thus this confirms that the frequency component sin (2 π / 5)will be completely removed by theMoving Average Filter while the frequency component of sin (0.1 π n ) will pass through thefilter and its amplitude will be reduced to 0.9040 DSP Lab Manual - 25 - Zulfiqar Ali
- 25. PLOTTING THE FREQUENCY & IMPULSE RESPONSE USING MATLAB COMMANDS “FREQZ” AND “IMPZ”Matlab provides two commands “ freqz ” and “ impz ” for plotting the frequency response andthe impulse response. Both commands require the vectors ‘b’ and ‘a’ which are given by thefollowing general equation jw -jw -jmw jw B(e) b(1) + b(2)e + .... + b(m+1)e H(e) = ---- = ------------------------------------ jw -jw -jnw A(e) a(1) + a(2)e + .... + a(n+1)e Equation Ob = [ b(1) , b(2) , b(3) , ………………………. b(m+1) ]a = [ a(1) , a(2) , a(3) , ……………………….... a(n+1) ] jw 1 -j w 0 -j w 1 -j w 2 -j w 3 -j w 4H (e ) = _____ ( e +e +e + e + e ) 5 Equation MBy comparing “Equation M” and “Equation O” we can see that the vectors ‘b’ and ‘a’ for theMoving Average Filter with M1=0 and M2=4 have the values given byb = (1/5)*ones(1,5);a=1;The two vectors ‘b’ and ‘a’ are required by the “ freqz ” and the “ impz ” Matlab commands. Seethe help of these commands for more detail DSP Lab Manual - 26 - Zulfiqar Ali
- 26. Example # 4: Moving Average System acts as Low Pass Filterclose all;n=-70:70;xn=sin(2*pi*n/5)+sin(0.1*pi*n);figure;subplot(211);stem(n,xn);xlabel(Input signal x[n]);hn=(1/5)*ones(1,5);yn=conv(xn,hn);subplot(212);stem(yn);xlabel(Output y[n] of Moving Average System (LPF removing sin(2*pi*n/5) component));b=(1/5)*ones(1,5);a=1;w=-2*pi:0.01:2*pi;figure;impz(b,a);xlabel(Impulse Response for Moving average system M1=0 , M2=4);figure;H=freqz(b,a,w);subplot(2,1,1);plot(w,abs(H));xlabel(Moving average system M1=0 , M2=4 (Magnitude of Frequency response));subplot(2,1,2);plot(w,angle(H));xlabel(Moving average system M1=0 , M2=4 (Phase of Frequency response)); Impulse Response 0.2 0.15 A m p lit u d e 0.1 0.05 0 0 0.5 1 1.5 2 2.5 3 3.5 4 Impulse Response for Moving average system M1=0 , M2=4 DSP Lab Manual - 27 - Zulfiqar Ali
- 27. 1 0.5 0 -8 -6 -4 -2 0 2 4 6 8 Moving average system M1=0 , M2=4 (Magnitude of Frequency response) 4 2 0 -2 -4 -8 -6 -4 -2 0 2 4 6 8 Moving average system M1=0 , M2=4 (Phase of Frequency response) 2 1 0 -1 -2 -80 -60 -40 -20 0 20 40 60 80 Input signal x[n] 1 0.5 0 -0.5 -1 0 50 100 150Output y[n] of Moving Average System (LPF removing sin(2*pi*n/5) component)DSP Lab Manual - 28 - Zulfiqar Ali
- 28. PROBLEM # 1:Consider the Ideal Delay system defined by the following equation y[ n ] = x [ n – nd ]Use the following valuesnd=10;n=0:60;xn=cos(n*pi/10).*sin(n*pi/20);w=-2*pi:0.01:2*pi; A) Evaluate the values of the vectors ‘b’ and ‘a’ for this filter using “Equation O” B) Plot the Magnitude and Phase of Frequency Response for this Ideal Delay system using the procedure used in Example # 4 C) Plot the Impulse Response of this Ideal Filter using “ impz ” command. For help on how to use “ impz ” command refer to example # 4 D) Now Filter the signal “xn” through this ideal delay system using the command yn=filter(b,a,xn);The values ‘b’ and ‘a’ are the values calculated in part (A) E) Plot the signal “ xn ” and the Filtered signal “ yn ” in the same window using “subplot” command. The Graphs should look like following. Note in the following graph that the filtered signal “ yn ” is delayed by nd=10 samples to the right .Refer to Page # 41 of your textbook for more help on this Ideal Delay System 1 0.5 0 -0.5 -1 0 10 20 30 40 50 60 70 Original Signal xn = cos(n*pi/10).* sin(n*pi/20); 1 0.5 0 -0.5 -1 0 10 20 30 40 50 60 70 Filtered Signal y[n] after passing through ideal delay system DSP Lab Manual - 29 - Zulfiqar Ali
- 29. LAB # 5 : Z TRANSFORM IN MATLABThe Fourier Transform of a sequence x[n] is defined as jw +∞ -j w nX (e )= ∑ x [n] e Equation A n=-∞The Z Transform of a sequence x[n] is defined as +∞ -nX ( z ) = ∑ x [n] z Equation B n=-∞ jwTherefore the Fourier Transform is X (z) with z = eMatlab provides a function “ ztrans ”for evaluating the Z Transform of a symbolic expression.This is demonstrated by the following Example # 1which uses Equation C to evaluate ZTransform given by Equation DPage # 98 Example 3.1 of book has following expressions nx [n] = a U[n] Equation CX(z ) = z = 1 Equation D ____ ______ -1 z–a 1–az n Example # 1: Z Transform of x [n] = a U[n]Page # 98 Example 3.1 of bookclcsyms a n;xn=1^n;% xn=a^n;Xz=ztrans(xn);disp(x[n] = ) ; pretty(xn);disp(X(z) = ) ; pretty(Xz); DSP Lab Manual - 30 - Zulfiqar Ali
- 30. Page # 100 Example 3.3 of book has following expressions n nx [n] = ( 1/2 ) U[n] + ( - 1/3 ) U[n] Equation EX(z) = 2z ( z – 1 / 12 ) -------------------------- Equation F (z–1/2)(z+1/3) n nExample # 2: Z Transform of x [n] = ( 1/2 ) U[n] + ( - 1/3 ) U[n]Page # 100 Example 3.3 of bookclcsyms n ;xn=(1/2)^n + (-1/3)^n ;Xz=ztrans(xn);disp(x[n] = ) ; pretty(xn);disp(X(z) = ) ; pretty(Xz);disp(X(z) = );[rXz,how]=simple(Xz);pretty(rXz);disp(X(z) = );pretty(simplify(Xz));Page # 113 Example 3.8 of book has following expressionX (z ) = 1 Equation G _____________________ -1 -1 ( 1 – (1/4) z ) ( 1 – (1/2) z )In the following example we calculate the inverse Z Transform of the Equation G by using “iztrans ” Matlab function .The function “ iztrans ” takes the input X(z) and returns the Inverse ZTransform x[n].Then we display the result x[n]using the “ pretty ” function DSP Lab Manual - 31 - Zulfiqar Ali
- 31. Example # 3: Inverse Z Transform of Equation GPage # 113 Example 3.8 of bookclcsyms a z;Xz= 1 /(( 1 - (1/4)*( z^-1 ) ) * ( 1 - (1/2)*( z^-1 ) ));% Xz= 1 /( 1 - a*( z^-1 ) );% Xz=z/(z-a);disp(X(z) = ) ; pretty(Xz);xn=iztrans(Xz);disp(x[n] = ) ; pretty(xn);The general expression of the Z Transform of a sequence g [ n ] is given by the expressionbelow. -1 -2 -n b(1) + b(2) z + b(3) z +……………….+ b(n+1) zG(z) = ___________________________________________ Equation H -1 -2 -m a(1) + a(2) z + a(3) z +……………….+ a(m+1) zHere the coefficients are the values of the following vectorsb = [ b(1) b(2) b(3) ………………. b(n+1) ] Equation Ia = [ a(1) a(2) a(3) ………………. a(m+1) ] Equation JMatlab provides the function “ zplane ” for plotting the zeros and poles of a transfer function.The “ zplane ” function follows the format given in Equation H. Therefore if we know thecoefficients “ b ” & “ a ” given above then we can plot the Zero Pole Plot using “ zplane ”function.Also in the following example “ conv ” function is used for multiplying two polynomials and “poly ” is used to generate the polynomial coefficients from the roots of that polynomial. DSP Lab Manual - 32 - Zulfiqar Ali
- 32. Example # 4:Zero Pole Plot for Equation GPage # 113 Example 3.8 of bookclose all;b=[1];a=[1 (-3/4) (1/8) ];zplane(b,a);grid;title(algebric manipulation for evaluating vector " a ");%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%p1=[1 (-1/4)];p2=[1 (-1/2)];p3=conv(p1,p2);b=1;a=p3;figure;zplane(b,a);grid;title(Using " conv " for evaluating vector " a ");%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%r=[(1/2) (1/4)];p=poly(r);b=1;a=p;figure;zplane(b,a);grid;title(Using " poly " for evaluating vector " a ");[ r , p , k ] = residuez ( b , a ) finds the residues, poles, and direct terms of a partial fractionexpansion of the ratio of two polynomials, b(z) and a(z) given by Equation H. Vectors b and aspecify the coefficients of the polynomials of the discrete-time system b(z) / a(z) in descendingpowers of z.The following example demonstrates the use of Partial Fraction Expansion in Matlab. It uses thefunction “residuez” for finding the values of “ r , p and k ”and requires input as two vectors “ b& a ” given by Equation I and Equation J. The vectors “r , p & k” returned by the function “residuez ” should be inserted in Equation K for finding the partial fraction expansion.X(z ) = r(1) + r(2) +……+ r(n) ________ _____ _________ -1 -1 -1 1 – p(1) z 1 – p(2) z 1 – p(n) z Equation K -1 -2 - (m - n)+ k(1) + k(2) z + k(3) z +……………….+ k(m - n +1) z DSP Lab Manual - 33 - Zulfiqar Ali
- 33. Example # 5:Partial Fraction Expansion for Equation GPage # 113 Example 3.8 of bookclc;b=1;a=[1 (-3/4) (1/8)];[r,p,k]=residuez(b,a)Put the values of r , p and k from above coding into Equation K to get the Partial FractionExpansion for Equation G. Compare the result with the equation given on Page # 113 oftextbook. Thus the values (A1 & A2 given in book) are computed using Matlab. So Matlabprovides very efficient way for computing Partial Fraction expansion of long and tediousMathematical procedure.Page # 115 Example 3.9 of bookConsider a sequence x [ n ] with Z Transform X ( z ) given below -1 -2 ( 1+2z+z )X(z) = ___________________ Equation L -1 -2 ( 1 – (3/2) z + (1/2) z )In the following example we will find the locations of zeros and poles of Equation L using “tf2zp ” function and then plot them using “ zplane ” functionExample # 5:Finding z , p & k from b & aPage # 115 Example 3.9 of bookb=[1 2 1];a=[1 (-3/2) (1/2)];[z,p,k]=tf2zp(b,a)zplane(b,a)Put the values of z , p & k from coding above into the Equation M to find an equivalentexpression for X ( z ) involving Zeros , Poles and Gain. Therefore we have the Equation Lreduced to Equation M k ( z – z(1) ) ( z – z(2) ) …………( z – z(n) )X(z) = _______________________________________ Equation M ( z – p(1) ) ( z – p(2) ) …………( z – p(n) ) DSP Lab Manual - 34 - Zulfiqar Ali
- 34. PROBLEM # 1:Consider the Moving Average System defined by the following equation 1 M2y[ n ] = ___________ ∑ x[n–k] Equation N (M1+M2+1) k = - M1Such a system is often used in smoothing random variations in data and we considered thissystem in previous Lab # 4.Now Take M1 = 0, M2 = 9 A) Evaluate the Z Transform Y ( z ) of the moving average system defined by Equation N. Use the following property Z -no x [ n – no ] z X( z ) Equation O B) Evaluate the values of the vectors ‘b’ and ‘a’ for this filter using “Equations H , I & J ” C) The Transfer function is given by following equation H( z ) = Y( z ) / X( z ) Use “freqz” command & then plot the Magnitude of Transfer Function and Phase of Transfer Function. The command “ freqz ” requires “b , a , w” . The value of w is given by w = -2*pi :0.01:2*pi . The values “b , a” are calculated in part B. D) Plot the Impulse Response of this Filter using “ figure; impz ” command. E) Plot the zeros and poles of the transfer function H( z ) = Y( z ) / X( z ) using the commands “ figure ; zplane( b , a )” F) Now Find the values of “ z , p & k ” from “ b & a ” G) Compare the Locations of Zeros & Poles on the graph plotted in Part D with the values of “ z & p” evaluated in part EPROBLEM # 2:Consider the Z Transform X ( z ) defined by the following expression DSP Lab Manual - 35 - Zulfiqar Ali
- 35. X(z) = z Equation P ______________ 2 (3 z – 4 z + 1) A) Evaluate the values of the vectors ‘b’ and ‘a’ for Equation P using “Equations H , I & J ” B) Evaluate the Partial Fraction expansion for Equation P & reduce it to form given by Equation K. Use the “residuez” command for this purpose C) Plot the Zeros and Poles of X( z ) . D) Compare the Locations for Poles and Zeros from the Graph in Part C with the partial fraction expansion done in part BPROBLEM # 3: -1 -2 -1 -2 -3 A) X1( z ) =2+3 z +4 z and X2( z ) =3 +4 z +5 z +6 z Write the Matlab coding for evaluating X3( z )= X1( z ) X2( z ) Which Matlab function would you use for this purpose? B) Determine the Expression for X3 ( z ) DSP Lab Manual - 36 - Zulfiqar Ali
- 36. LAB # 6 : Discrete Fourier Transform (DFT) In MATLABDISCRETE TIME FOURIER TRANSFORM (DTFT)DTFT of a signal x[n] can be defined as: N − 1 X (ω ) = ∑ n = 0 x [ n ]e − jw nIt gives frequency spectrum of the signal. Since ω is continuous, its range is continuous. So it isimpossible to get a vector in MATLAB which covers entire range of the DTFT.DISCRETE FOURIER TRANSFORM (DFT)N point DFT of a signal x[n] is defined as: N − 1 j ( 2 π ∑ − ) k n X ( K ) = x [ n ]e N n = 0and IDFT can be obtained by the relation: N − 1 1 − j ( 2 π ∑ ) kn x[n ] = X (k )e N N k = 0N point DFT means taking N equidistant samples (Sampling in frequency domain). DFT is asampled version of DTFT.Now you are dividing 2π in N samples. 2 π Width = NIn order to estimate DTFT of the signal, we may take DFT of the signal, while taking largenumber of DFT points.FAST FOURIER TRANSFORM (FFT)FFT is an efficient algorithm of calculation of DFT. It requires much less computation, but itrequires the number of samples to be an integer power of 2. MATLAB provides FFT commandto compute DFT using FFT algorithm DSP Lab Manual - 37 - Zulfiqar Ali
- 37. PROBLEM # 1:The following functions are required in this labrectpuls ,length , abs , fft , ifft , fftshiftRead the help of these Matlab functions understanding the input and output parameters.PROBLEM # 2:Consider the time vector given belowinc = 0.001;t = -0.2+inc:inc:0.2;Plot the magnitude of DFT of Rectangular pulse having width 0.025 and defined for the timegiven above. Use the Matlab functions “ rectpuls ” & “ fft ”.The DFT should be centered aroundzero. Use function “ fftshift ” to shift zero-frequency component to center of spectrumPROBLEM # 3:Consider a continuous time signal xc ( t ) = cos ( 4000 π t ) defined for the time given belowt = -5*To : To/50 : 5*To;Here To is the Time Period of xc ( t ). Plot the signal and the magnitude of DFT for this cosinesignal versus frequency values. Choose a value of “ N ” which is higher than the signal lengthRemember that cosine signal has Fourier Transform given by Xc ( w ) = π ∂ [ ω – ωo ] + π ∂ [ ω + ωo ] .Thus you will get the DFT graph having 2 impulses at +2000 Hertz and -2000 Hertz. DSP Lab Manual - 38 - Zulfiqar Ali
- 38. PROBLEM # 4:Plot the Inverse DFT for problem 3.Graphs for Problem 3 and 4 are shown below 1 0 -1 -2.5 -2 -1.5 -1 -0.5 0 0.5 1 1.5 2 2.5 Cosine Signal xt = cos(4000*pi*t) -3 x 10 300 200 100 0 -50 -40 -30 -20 -10 0 10 20 30 40 50 DFT of cosine ( Frequency Axis in KHz ) 1 0.5 0 -0.5 -1 -2.5 -2 -1.5 -1 -0.5 0 0.5 1 1.5 2 2.5 Inverse Discrete Fourier Transform IDFT -3 x 10 DSP Lab Manual - 39 - Zulfiqar Ali
- 39. LAB # 7 : FIR DIGITAL FILTERS 1. LOW PASS FIR DIGITAL FILTERThe simplest Low Pass FIR filter is the moving average filter with M = 2 and has the transferfunction given by -1 H LP ( z ) = 1+z Equation A _________ 2The above transfer function has a zero at z = - 1 and a pole at z = 0.The pole vector has amagnitude of unity, the radius of the unit circle, for all values of w. On the other hand , as wincreases from 0 to π , the magnitude of the zero vector decreases from a value of 2, the diameterof the unit circle to zero. Hence the magnitude response is a monotonically decreasing functionof w from w = 0 to w = π. The maximum value of the magnitude function is unity at w = 0, andthe minimum value is zero at w = π.The frequency response for this filter is given by jw – jw/2 H LP ( e )= e cos ( w / 2 ) Equation B 2. HIGH PASS FIR DIGITAL FILTERThe simplest High Pass FIR filter is obtained by replacing z with –z in Equation A , resulting in atransfer function -1 H HP ( z ) = 1–z Equation C ________ 2The frequency response for this filter is given by jw – jw/2 H HP ( e )= je sin ( w / 2 ) Equation DThe transfer function given by Equation C has a zero at z = 1 or w = 0 , which is in the stop bandof the filter DSP Lab Manual - 40 - Zulfiqar Ali
- 40. LAB # 8 : IIR DIGITAL FILTERS 1. LOW PASS IIR DIGITAL FILTERA first order Low Pass IIR digital filter has a transfer function given by -1 H LP ( z ) = 1–α ________________________________________ 1+z ________________________________________________________ Equation E -1 2 1– α zwhere | α | < 1 for stability. The above transfer function has a zero at z = -1 i:e w = π , which isin the stop band of the filter. It has a real pole at z = α .As w increases from 0 to π , themagnitude of the zero vector decreases from a value of 2 to 0 , whereas , for a positive value ofα, the magnitude of the pole vector increases from a value of 1 – α to 1 + α . The maximumvalue of the magnitude function is unity at w = 0 , and the minimum value is zero at w = π j0 | H LP ( e )| = 1 jπ | H LP ( e )| = 0 jwTherefore | H LP ( e ) | is a monotonically decreasing function of w from w = 0 to w = πThe 3 dB cutoff frequency is related by the following equation -1 wc = cos 2α Equation F ____________ 2 1+αThe quadratic equation can be solved for α yielding two values. Solving the Equation G givenbelow results in 2 values of α .That value of α should be chosen which results in a stabletransfer function. 2 (1 + α ) cos ( wc ) – 2 α = 0 Equation G DSP Lab Manual - 42 - Zulfiqar Ali
- 41. 2. HIGH PASS IIR DIGITAL FILTERA first order high pass transfer function is given by -1 H HP ( z ) = 1+α 1–z Equation H ______ ______ -1 2 1– α zwhere | α | < 1 for stability. Its 3 dB cutoff frequency is given by Equation F and Equation G 3. BAND PASS IIR DIGITAL FILTERA second order band pass digital filter is described by the transfer function -2 H BP ( z ) = 1 – α 1–z Equation I ________ ___________________ -1 -2 2 1– β (1 + α) z + α zwhich goes to zero at w = 0 and w = π .It assumes a maximum value of unity at w = wo , calledthe center frequency of the band pass filter, where -1 wo = cos ( β ) Equation JThe frequencies wc1 and wc2 where the squared magnitude response goes to ½ are called the3 dB cutoff frequencies, and their difference, Bw , assuming wc2 > wc1 , called the 3 dBbandwidth , is given by -1Bw = wc2 – wc1 = cos 2 α Equation K ________________ 2 1+α 4. BAND STOP IIR DIGITAL FILTER (NOTCH FILTER)A second order band stop digital filter has a transfer function of the form -1 -2 H BS ( z ) = 1 + α 1 – 2β z + z _______ __________________ Equation L -1 -2 2 1– β (1 + α) z + α zHere the magnitude response takes the maximum value of unity at w = 0 and w = π , and goes tozero at w = wo , where wo is given by Equation J. Since the Magnitude response goes to zero atwo , wo is called the notch frequency and the digital filter given above is more commonly callednotch filter DSP Lab Manual - 43 - Zulfiqar Ali
- 42. PROBLEM # 1:Design a first order Low Pass IIR digital filter with a 3 dB cutoff frequency of 0.8 π. Choose avalue of α which results in a stable Transfer function. Plot Magnitude and Phase of FrequencyResponse for this Filter. Also display its pole zero plotPROBLEM # 2:Repeat Problem # 1 for a first order High Pass IIR digital filter with a 3 dB cutoff frequency of0.4 π.PROBLEM # 3:Design a second order Band Pass IIR digital filter with center frequency at 0.5 π and a 3 dBbandwidth of 0.1 π. Choose value of α resulting in stable Transfer Function .Plot Magnitude andPhase of Frequency Response for this Filter. Also display its pole zero plot DSP Lab Manual - 44 - Zulfiqar Ali
- 43. LAB # 9 : FILTER DESIGN USING ANALOG PROTOTYPINGINTRODUCTIONThe traditional approach to design IIR digital filters involves the transformation of an analogfilter into a digital filter meeting prescribed specification because 1. The art of analog filter design is highly advanced and since useful results can be achieved, it is advantageous to utilize the design procedures already developed for analog filters 2. Many useful analog design methods have relatively simple closed-form design formulas. Therefore digital filter design methods based on such analog design formulas are rather simple to implement. 3. In many applications it is of interest to use a digital filter to simulate the performance of an analog linear filterMETHODS OF ANALOG-DIGITAL TRANSFORMATION1. IMPULSE INVARIANCEOne method of transforming an analog filter design to a digital filter design corresponds tochoosing the unit sample response of the digital filter as equally spaced samples of impulseresponse of the analog filter. That is h ( n ) = h a ( n T )2. BILINEAR TRANSFORMThe bilinear transformation is a mathematical mapping of variables. In digital filtering, it is astandard method of mapping the s or analog plane into the z or digital plane. It transforms analogfilters, designed using classical filter design techniques, into their discrete equivalents.The bilinear transformation maps the s-plane into the z-plane by − 2 1 − z 1 s = − T 1 + z 1 DSP Lab Manual - 45 - Zulfiqar Ali
- 44. 1) BUTTERWORTH FILTERButterworth filters are defined by the property that the magnitude response is maximally flat inthe pass band. Another property is that the approximation is monotonic in the pass band and thestop band.The squared magnitude of Butterworth filters is of the form: 2 1 H a ( jΩ ) = 1 + ( jΩ / jΩ c ) 2 N 2) CHEBYSHEV TYPE I FILTERThe Chebyshev type I filter minimizes the absolute difference between the ideal and actualfrequency response over the entire pass band by incorporating an equal ripple of Rp dB in thepass band .Stop band response is maximally flat.The transition from pass band to stop band is more rapid than for the Butterworth filter. DSP Lab Manual - 46 - Zulfiqar Ali
- 45. 3) CHEBYSHEV TYPE II FILTERThe Chebyshev type II filter minimizes the absolute difference between the ideal and actualfrequency response over the entire stop band, by incorporating an equal ripple of Rs dB in thestop band. Pass band response is maximally flat. The stop band does not approach zero asquickly as the type I filter (and does not approach zero at all for even-valued n). The absence ofripple in the pass band, however, is often an important advantage. 4) ELLIPTIC FILTERElliptic filters are equiripple in both the pass band and stop band. They generally meet filterrequirements with the lowest order of any supported filter type. Given a filter order n, pass bandripple Rp in decibels, and stop band ripple Rs in decibels, elliptic filters minimize transitionwidth.Squared magnitude of elliptic filters can be estimated by the following equation: 2 1 H ( j Ω ) = a 1 + ε 2 U N 2 ( Ω )where UN(Ω) is a Jacobian elliptic function. DSP Lab Manual - 47 - Zulfiqar Ali
- 46. PROBLEM 1:Use help command to learn the use of following commands: butter, buttord, cheby1, cheb1ord, cheby2, cheb2ord, ellip, ellipordPROBLEM 2:(i) Generate the following signal with 400 samples & then plot it against time 1 x (t) = c o s(2π × 1 0 t) − c o s(2π × 3 0 t) + 3 1 c o s(2π × 5 0 t) 5( f s = 2 0 0 )(ii) Plot the DFT of the above signal versus frequency. Choose an appropriate value of “ N ”(iii) Remove the highest frequency component of the signal using Butterworth , Chebyshev Type I , Chebyshev Type II and Elliptic filters . Use freqz to plot the frequency response for each of the filters used. Plot DFT of the filtered signal for each case.(iv) Repeat part (iii) to remove the intermediate frequency component.(v) Repeat part (iii) to remove the lowest frequency component.PROBLEM 3:Comment on the results obtained by using different filters DSP Lab Manual - 48 - Zulfiqar Ali
- 47. LAB # 11 : PERIODIC WAVE GENERATORSINTRODUCTIONIt is often desired to generate various types of waveforms, such as periodic square waves,sawtooth signals, sinusoids, and so on. A filtering approach to generating such waveforms is todesign a filter H(z) whose impulse response h(n) is the waveform one wishes to generate. Then,sending an impulse as input will generate the desired waveform at the output.SINUSOIDAL & COSINUSOIDAL GENERATORSThe above filtering approach can be used to generate a (causal) sinusoidal signal of frequency f0and sampled at a rate fs . Denoting the digital frequency by ω 0 = 2 π f 0 / f swe have the z transform pair h (n ) = R n s i n (ω 0 n )u (n ) R s in ω 0 z −1 H (z) = 1 − 2 R c o s ω 0 z −1 + R 2 z − 1And, h (n ) = R n c o s (ω 0 n )u (n ) 1 − R c o s ω z −1 => H ( z ) = 0 1 − 2 R c o s ω 0 z − 2 − 2 1 + R 2 zPERIODIC WAVEFORM GENERATORSSuppose we have to generate a repeating sequence DSP Lab Manual - 57 - Zulfiqar Ali
- 48. { b 0 , b1 , . . . , b D − 1 , b 0 , b1 , . . . , b D − 1 , b 0 , b1 , . . . , b D − 1 , . . . }Using the filtering approach just described above we can accomplish this task. Such a filter musthave the impulse response:h = [b 0 , b1 , ..., b D − 1 ,b 0 , b1 , ..., b D − 1 , b 0 , b1 , ..., b D − 1 , ...]The required impulse response is shown in the following figure:The following filter has the required impulse response: −1 b 0 + b1 z + b 2 z −2 + ... + b D z − ( D −1) H (z) = −1 1 − z−DExciting this filter with an impulse will result in the required sequence.DUAL TONE MULTI FREQUENCY GENERATORA common application of sinusoidal generators is the all-digital touch-tone phone, known asDual-Tone Multi-frequency (DTMF) transmitter/receiver. Each key-pressed on the key padgenerates the sum of two audible sinusoidal tones, that is, the signal y ( n ) = c o s (ω L n ) + c o s (ω H n)where the two frequencies uniquely define the key that was pressed. Following figure shows thepairs of frequencies associated with each key. DSP Lab Manual - 58 - Zulfiqar Ali
- 49. Figure 1: Extended DTMF encoding table for Touch Tone dialing. When any key is pressed thetones of the corresponding column and row are generated and summed. Common householdphones do not have the fourth column.The particular values of the 8 keypad frequencies have been chosen carefully so that they do notinterfere with speech. At the receiving end, the dual-tone signal y(n) must be processed todetermine which pair of frequencies is present. This can be accomplished either by filtering y(n)through a bank of band pass filters tuned at the 8 possible DTMF frequencies or by computingthe DFT of y(n) and determining which pairs of frequency bins contain substantial energy.TELEPHONE TOUCH TONE DIALINGTelephone touch pads generate dual tone multi-frequency (DTMF) signals to dial a telephone.When any key is pressed, the tones of the corresponding column and row are generated andsummed, hence dual tone. As an example, pressing the 5 key generates a signal containing thesum of the two tones 770 Hz and 1336 Hz.The frequencies in figure were chosen (by the design engineers) to avoid harmonics. Nofrequency is an integer multiple of another, the difference between any two frequencies does notequal any of the frequencies, and the sum of any two frequencies does not equal any of thefrequencies. This makes it easier to detect exactly which tones are present in the dial signal in thepresence of non-linear line distortions.DTMF DECODING 1) Divide the signal into shorter time segments representing individual key presses. 2) Filter the individual segments to extract the possible frequency components. Band pass filters can be used to isolate sinusoidal components. 3) Determine which two frequency components are present in each time segment by measuring the size of the output signal from all of the band pass filters. 4) Determine which key was pressed, 0–9, *, #, or A–D for extended DTMF, by converting frequency pairs back into key names according to Fig. 1. DSP Lab Manual - 59 - Zulfiqar Ali
- 50. It is possible to decode DTMF signals using a simple FIR filter bank. The filter bank illustratedin Fig. 2consists of eight band pass filters where each pass only one of the eight possible DTMFfrequencies. The input signal for all the filters is the same DTMF signal.Here is how the system should work: When the input to the filter bank is a DTMF signal, theoutputs from two of the band pass filters (BPFs) should be significantly larger than the rest. If wedetect (or measure) which two are the large ones, then we know the two correspondingfrequencies. These frequencies are then used to determine the DTMF code. A good measure ofthe output levels is the peak value at the filter outputs, because when the BPF is workingproperly it should pass only one sinusoidal signal and the peak value would be the amplitude ofthat sinusoid.Figure 2: Filter bank consisting of band pass filters which pass frequencies corresponding to theeight DTMF component frequencies listed in Fig. 1 DSP Lab Manual - 60 - Zulfiqar Ali
- 51. PROBLEM 1: a) Plot the impulse response of a sinusoidal generator with f 0 = 400 and f s = 8 kHz. (length = 100 samples) b) Cosinusoidal generator with f 0 = 800 and f s = 8 kHz (length = 50 samples)PROBLEM 2:Implement a function gen_dtmf which should generate a DTMF for the digits 1-9. Taken = 1:200 and sampling frequency fs = 4000function [dtmf , n] = gen_dtmf ( key );PROBLEM 3:Given the function gen_dtmf created in Problem # 2 , write a function which should decode thegen_dtmf to an appropriate key.function [ ] = detect_dtmf ( dtmf , n )( Hint : Use Discrete Fourier Transform to check which frequency components are present inthe signal. Then from the frequency components present you can decode the dtmf signal to anappropriate key )PROBLEM 4: A) Plot 12 samples of the impulse response for the transfer function given below. Use impz −1 1 + 2 z + 3 z −2 + 4 z −3 H (z) = 1 − z −4 B) Implement a filter to produce the waveform given below. DSP Lab Manual - 61 - Zulfiqar Ali
- 52. C) Plot the impulse response of the following Transfer Function − 1 1 + 2 z + 3 z − 2 + 4 z − 3 H ( z ) = − 4 1 − 0 .5 zD) Plot the impulse response of the following Transfer Function − 1 − 2 − 3 1 + 0 .5 z + 2 z + 3 z H ( z ) = 1 − z −3 DSP Lab Manual - 62 - Zulfiqar Ali
- 53. LAB # 12 : NOISE REDUCTION & SIGNAL ENHANCEMENTINTRODUCTIONThis lab concerns with removing the additive noise out of the signal. If the noise is additive, thenthe noised signal can be represented as: x[n ] = s[n ] + v[n ]where s[n] is signal and v[n] is noise.There are two possibilities:A) When the frequency spectrum of the desired signal and noise do not overlap.It is easy to extract the desired signal using filtering, as shown in figures: Spectrum of noised signal before filtering Spectrum of the noised signal after filtering DSP Lab Manual - 63 - Zulfiqar Ali
- 54. B) When the frequency spectrum of the desired signal and noise overlap. In this case we could either block the noise to the maximum but get a distorted desired signal or get an undistorted desired signal at the expense of added noise.In practice, ideal filters with such sharp edges are not realizable. Two parameters are in practice 1) Transient Response 2) DelayAs the pole approaches 1, the transition becomes sharper but introduces a delay in the output. ln Εγ eff = →∞ as a → 1 ln aLOW PASS IIR SMOOTHER bH (z) = 1 − az − 1 1− aNRR = 1+ a⇒ NRR + aNRR = 1 − a 1 − NRRa = 1 + NRRNRR < 1 since 0 ≤ a ≤ 1for H (z) w=0 =1 b = 1− a DSP Lab Manual - 64 - Zulfiqar Ali
- 55. HIGH PASS IIR SMOOTHER bH (z) = 1 + a z −1for H ( w) w =π = H ( − 1) = 1 ; b = 1 − a 1− aNRR = 1+ aIIR SMOOTHER WITH PRESCRIBED CUTOFF FREQUENCY b (1 + z − 1 )H (z) = 1 − a z −1 1 − ab = 2 1 − sin w ca= cos w cPROBLEM 1:Generate s[ n ] = 5 ( 400 samples ) v[ n ] = 0.2 * randn (1, 400) x[ n ] = s[ n ] + v[ n ]Design a low pass IIR smoother for the following values of NRR. Apply this filter to x [ n ] toget y [ n ] . Plot y [ n ] , x [ n ] on the same figure i) NRR = 0.05 ii) NRR = 0.01 DSP Lab Manual - 65 - Zulfiqar Ali
- 56. PROBLEM 2:Generate a high frequency signal s [ n ] = ( − 1) n 5 x[ n ] = s[ n ] + v[ n ]Design a high pass IIR smoother for the following values of NRR. Apply this filter to x[ n ] toget y [ n ] . Plot y[n ] , x [ n ] on the same figure i) NRR = 0.05 ii) NRR = 0.01PROBLEM 3:Use IIR smoother with cutoff frequency w c = π x(n) same as Problem 1. Apply this 8 andfilter to x [ n ] to get y [ n ] . Plot y [ n ] , x [ n ] on the same figure DSP Lab Manual - 66 - Zulfiqar Ali
- 57. LAB # 13 : SIGNAL PROCESSING TOOLBOX PART-1INTRODUCTION“SPTool” is an interactive GUI for digital signal processing that can be used to 1) Analyze signals 2) Design filters 3) Analyze (view) filters 4) Filter signals 5) Analyze signal spectraYou can accomplish these tasks using four GUIs that you access from within SPTool: 1) The Signal Browser is for analyzing signals. You can also play portions of signals using your computer’s audio hardware. 2) The Filter Designer is for designing or editing FIR and IIR digital filters. Most of the Signal Processing Toolbox filter design methods available at the command line are also available in the Filter Designer. Additionally, you can design a filter by using the Pole/Zero Editor to graphically place poles and zeros on the z-plane. 3) The Filter Visualization Tool is for analyzing filter characteristics. 4) The Spectrum Viewer is for spectral analysis. You can use the Signal Processing Toolbox Spectral estimation methods to estimate the power spectral density of a signal.SPTOOL DATA STRUCTURESYou can use SPTool to analyze signals, filters, or spectra that you create at the MATLABcommand line. You can bring signals, filters, or spectra from the MATLAB workspace into theSPTool workspace using the Import item under the File menu. Signals, filters, or spectra thatyou create in (or import into) the SPTool workspace exist as MATLAB structures.When you use the Export item under the File menu to save signals, filters, and spectra that youcreate or modify in SPTool, these are also saved as MATLAB structures. DSP Lab Manual - 67 - Zulfiqar Ali
- 58. OPENING SPTOOLTo open SPTool, type sptool at the Matlab command WindowWhen you first open SPTool, it contains a collection of default signals, filters, and spectra. Youcan specify your own preferences for what signals, filters, and spectra you want to see whenSPTool opens.You can access these three GUIs from SPTool by selecting a signal, filter, or spectrum andpressing the appropriate View button: 1) Signal Browser 2) Filter Visualization Tool 3) Spectrum ViewerYou can access the Filter Designer GUI by pressing the New button to create a new filter or theEdit button to edit a selected filter. The Apply button applies a selected filter to a selectedsignal. The Create button opens the Spectrum Viewer and creates the power spectral density ofthe selected signal. The Update button opens the Spectrum Viewer for the selected spectrum.SIGNAL BROWSERYou can use the Signal Browser to display and analyze signals listed in the Signals list box inSPTool. Using the Signal Browser you can: DSP Lab Manual - 68 - Zulfiqar Ali
- 59. 1) Analyze and compare vector or array (matrix) signals. 2) Zoom in on portions of signal data. 3) Measure a variety of characteristics of signal data. 4) Compare multiple signals. 5) Play portions of signal data on audio hardware. 6) Print signal plots.OPENING THE SIGNAL BROWSERTo open the Signal Browser from SPTool: 1) Select one or more signals in the Signals list in SPTool 2) Press the View button under the Signals listThe Signal Browser has the following components: 1) Display region for analyzing signals, including markers for measuring, comparing, or playing signals 2) “panner” that displays the entire signal length, highlighting the portion currently active in the display region DSP Lab Manual - 69 - Zulfiqar Ali
- 60. 3) Marker measurements area 4) Toolbar with buttons for convenient access to frequently used functionsFILTER DESIGNERThe Filter Designer provides an interactive graphical environment for the design of digital IIRand FIR filters based on specifications that you enter on a magnitude or pole-zero plotFILTER TYPESYou can design filters of the following types using the Filter Designer: 1) Bandpass 2) Lowpass 3) Bandstop 4) HighpassFIR FILTER METHODSYou can use the following filter methods to design FIR filters: 1) Equiripple 2) Least squares 3) WindowIIR FILTER METHODSYou can use the following filter methods to design IIR filters: 1) Butterworth 2) Chebyshev Type I 3) Chebyshev Type II 4) EllipticPOLE/ZERO EDITORYou can use the Pole/Zero Editor to design arbitrary FIR and IIR filters by placing and moving DSP Lab Manual - 70 - Zulfiqar Ali
- 61. poles and zeros on the complex z-plane.SPECTRAL OVERLAY FEATUREYou can also superimpose spectra on a filter’s magnitude response to see if the filteringrequirements are met.OPENING THE FILTER DESIGNEROpen the Filter Designer from SPTool by either: 1) Pressing the New button in the Filters list in SPTool 2) Selecting a filter you want to edit from the Filters list in SPTool, and then pressing the Edit buttonThe Filter Designer has the following components: 1) Pull-down Filter menu for selecting a filter from the list in SPTool 2) Sampling Frequency text box 3) Pull-down Algorithm menu for selecting a filter design method or a pole-zero plot display 4) Specifications area for viewing or modifying a filter’s design parameters or pole-zero DSP Lab Manual - 71 - Zulfiqar Ali
- 62. locations5) Plot display region for graphically adjusting filter magnitude responses or the pole-zero locations6) Measurements area for viewing the response characteristics and stability of the current filter DSP Lab Manual - 72 - Zulfiqar Ali
- 63. LAB # 14 : SIGNAL PROCESSING TOOLBOX PART-2FILTER VISUALIZATION TOOLYou can use the Filter Visualization Tool fvtool to analyze the following response characteristicsof selected filters: 1) Magnitude response 2) Phase response 3) Impulse response 4) Step response 5) Group delay 6) Phase delay 7) Pole and zero locations 8) Detailed filter informationFVTool also provides features for 1) Overlaying filter responses 2) Zooming 3) Measuring filter responses 4) Modifying display parameters such as frequency ranges or magnitude unitsIf you start FVTool by clicking the SPTool Filter View button, that FVTool is linked to SPTool.Any changes made in SPTool to the filter are immediately reflected in FVTool. The FVTool titlebar includes “SPTool” to indicate the link. If you start an FVTool by clicking the New button orby selecting File New from within FVTool, that FVTool is a stand-alone version and is notlinked to SPTool.OPENING THE FILTER VISUALIZATION TOOLYou open FVTool from SPTool as follows. 1) Select one or more filters in the Filters list in SPTool. 2) Click the View button under the Filters list. DSP Lab Manual - 73 - Zulfiqar Ali
- 64. When you first open FVTool, it displays the selected filter’s magnitude plot.SPECTRUM VIEWERYou can use the Spectrum Viewer for estimating and analyzing a signal’s power spectral density(PSD). You can use the PSD estimates to understand a signal’s frequency content. The SpectrumViewer provides the following functionality. 1) Analyze and compare spectral density plots. 2) Use different spectral estimation methods to create spectra: 3) Modify power spectral density parameters such as FFT length, window type, and sample frequency. 4) Print spectral plots.OPENING THE SPECTRUM VIEWERTo open the Spectrum Viewer and create a PSD estimate from SPTool: 1) Select a signal from the Signal list box in SPTool. 2) Press the Create button in the Spectra list. 3) Press the Apply button in the Spectrum Viewer. DSP Lab Manual - 74 - Zulfiqar Ali
- 65. To open the Spectrum Viewer with a PSD estimate already listed in SPTool: 1) Select a PSD estimate from the Spectra list box in SPTool. 2) Press the View button in the Spectra list.For example: 1) Select mtlb in the default Signals list in SPTool. 2) Press the Create button in SPTool to open the Spectrum Viewer. 3) Press the Apply button in the Spectrum Viewer to plot the spectrum.The Spectrum Viewer has the following components: 1) Signal identification region that provides information about the signal whose power spectral density estimate is displayed 2) Parameters region for modifying the PSD parameters 3) Display region for analyzing spectra and an Options menu for modifying display characteristics 4) Spectrum management controls 5) A toolbar with buttons for convenient access to frequently used functions DSP Lab Manual - 75 - Zulfiqar Ali
- 66. PROBLEM 1:The following Matlab code generates a signal having three frequency components f1 , f2 & f3.clear all; close all;f1 = 1000; f2 = 2000; f3 = 3000;fs = 40000; ts = 1/fs; t = ts:ts:512*ts;signal = sin(2*pi*f1*t)+0.75*sin(2*pi*f2*t)+sin(2*pi*f3*t);figure; plot(t,signal) ; sptool Signal with Three Frequency components f1 , f2 & f3 3 2 1 0 -1 -2 -3 0 0.002 0.004 0.006 0.008 0.01 0.012 0.014Use Matlab Signal Processing Tool “ sptool ” to do the followingPart A: 1) Import the “signal” into SPTool & view it in Signal Browser 2) Design a Low Pass Filter to extract frequency component “ f1 ” 3) Apply the designed Filter to the “signal” 4) Analyze the “filtered_signal” in the Signal Browser 5) View the Spectrum of “signal” & “filtered_signal” in the Spectrum ViewerPart B:Repeat Part A such that you design a Band Pass Filter to extract frequency component “ f2 ”Part C:Repeat Part A such that you design a High Pass Filter to extract frequency component “ f3 ”Part D:Repeat Part A such that you design a Low Pass Filter to extract two frequency components“ f1 & f2 ” DSP Lab Manual - 76 - Zulfiqar Ali
- 67. PROBLEM 2:The following code generates a Sine signal with some random noise added to it.clear all ; close all;f = 5 ; fs = 1000*f ; ts = 1/fs;t = ts:ts:(6/f);signal = sin(2*pi*f*t)+0.5*rand(1,length(t));figure; plot(t,signal); sptool Sine Signal with random noise 1.5 1 0.5 0 -0.5 -1 0 0.2 0.4 0.6 0.8 1 1.2 1.4Use Signal Processing Tool “ sptool ” to remove the noise variation. Display the original signaland the filtered signal in the Signal Browser. After filtering you should get a signal with very lessrandom noise in it DSP Lab Manual - 77 - Zulfiqar Ali

No public clipboards found for this slide

×
### Save the most important slides with Clipping

Clipping is a handy way to collect and organize the most important slides from a presentation. You can keep your great finds in clipboards organized around topics.

Be the first to comment