Document Sample

Signal Processing ENGD2002 Resit Coursework Year 2008/ 2009 The module is reassessed by an examination only. The students who receive a deferral in Signal processing coursework should resubmit reports for the attached 8 assignments. The following marking scheme will be used Assignment-1 15 Assignment-2 10 Assignment-3 10 Assignment-4 15 Assignment-5 15 Assignment-6 20 Assignment-7 15 Total mark 100% The Laboratory reports should be handed in to the Student support centre in Gateway Building F.A.O. Dr Akil Bashagha before Friday 14th August 2009. Dr Akil Bashagha 1 3/23/2011 School of Engineering and Technology Signal Processing ENGD2002 Assignment-1 Use MATLAB for Function Evaluation MATLAB is short for "matrix laboratory" that was invented in the late 1970s. It is a high-level language for Engineering computation. It can solve technical computing problems faster than with traditional programming languages, such as C, C++, and Fortran. MATLAB is widely used in many applications such as signal processing, control systems and communications. In this assignment, different MATLAB methods will be used to define and evaluate functions. Double click on MATLAB icon and you will see the prompt >>. Type the instructions after the prompt and press the enter key to execute an instruction. If you need some help how to use an instruction, type >> help followed by the instruction. I) Inline functions: MATLAB inline constructs inline function object using the given expression and the input arguments. For example, f= 2x +3 with an argument x can be represented as >> f=inline ('2*x + 3', 'x') The inline function will be f(x) = 2*x + 3 To calculate the value of f for x=5, type >> x=5 followed by >> f(x) The above two steps can be rewritten as one step >> f( 5) Inputs should be written as vectors in order to evaluate the function for multiple values of inputs. Let x is a variable ( -5 x 5). >> x=(-5: 5)’ generate a vector of integers (i.e. -5, -4, …, 0, 1, .. 4, 5). >>f(x) calculates the function for the above values of x. To plot the function, use the plot command >>plot (x, f(x)) To use more points of x, use >>x=(-5: 0.1: 5) generate 100 points of x >>f(x) >>plot (x, f(x)) >> xlabel('x'); >> ylabel('f(x)'); >> grid; Dr Akil Bashagha 2 3/23/2011 Exercise: Repeat the above steps to plot the exponentially damped sinusoid f(t)= e-t . cos (2t) =exp(-t).*cos(2*pi*t) for -5 t 5 using 1 and 0.1 spacing. Repeat the plot for 0 t 5. II) Unit step and Pulse functions: The unit step function is defined as u(t)= 1 for t0 and u(t)=0 for t<0 >> u=inline('t>=0', 't') As explained above, plot the function for -5 t 5. Use suitable spacing intervals of t so that the function is close to a unit step. Use the following instruction to have suitable x and y axes limits of the graph. >> axis([-5 5 -0.2 1.2]) The pulse function p = u(t)- u(t-4) can be calculated using logical operations (e.g. & for AND) and relational operators (e.g. >, >=) as follows >> p=inline('(t>=0) & (t<4)', 't') Plot the pulse function for -5 t 5 Exercise: Plot the pulse function p = u(t)- u(t-4) as a difference between two unit step functions. Calculate u1=inline('t>=0', 't') and u2=inline('t>=4', 't') for t=-5:0.1:5 and then find p=u1(t)-u2(t). III) Scaling and shifting of functions: Consider the following function f(t)= e-t . cos (2t) g(t)=f(t).u(t) Note that MATLAB can not multiply inline objects so construct new inline object for g(t) and plot the function g=inline('exp(-t).* cos (2*pi*t).*(t>=0)') If g(t) is scaled by a and shifted by b then the new function will be g(at+b). Exercise: Plot g(t), g(2*t), g(t+4), g(2*t+4), g(-t+2) and g(2*t+4)+g(-t+2). In your report, include and discuss all the results Dr Akil Bashagha 3 3/23/2011 School of Engineering and Technology Signal Processing ENGD2002 Assignment-2 Second Order Differential Equations Consider the following second order differential equation d2y dy a0 2 a1 a2 y 0 dt dt a0 y ' ' a1 y ' a 2 y 0 It is an important equation that is used in many signal processing problems. We assume the solution to be y=Kext. The values of x can be found by writing down the characteristic equation. a0 x 2 a1 x a 2 0 It is a quadratic equation where the roots can be calculated as a1 a1 4a0 a2 2 x1, 2 2a 0 The solution of the differential equation is y (t ) K1e x1t K 2 e x2t K1 and K2 are constants that depend on the initial values y(0) and y’(0). The Matlab roots command can be used to find the solution, x1and x2. >>roots(A) where A is the input vector of the equation coefficients, A= [a0 a1 a2]. 1. Assume that a0 =1, a1 = 5, a2 =4, use matalb to find the roots of the equation. 2. Find the roots of A if a0 =1, a1 = 4, a2 =5. At the start of each exercise, type >> clear all to clear all the old values. Dr Akil Bashagha 4 3/23/2011 Exercise-1: 1. The transient current of a series RLC circuit of Fig. 1 is similar to the above solution with a0 =1, a1 = R/L, a2 =1/(LC). Find the current if R=400, L=20mH, C= 1F. R L 1 2 V u(t) C Fig. 1 2. Change C to 0.1F and calculate the current. Exercise-2: Consider the operational amplifier circuit of Fig. 2. The output voltage could be calculated from the previous equations where 1 1 1 1 1 a0 1 ; a1 ( ); a2 ; C 2 R1 R2 R3 R1 R2 C1C 2 R2 C1 R3 R1 - C2 OUT input o + Fig. 2 1. Let all the resitor values be the same, R=10k and capacitor values are the same C=1F. Find the roots of the output voltage. In Matlab, define R and C as vectors, R=[1e4 1e4 1e4], C=[1e-6 1e-6]. Then calculate a1 and a2 using the vector elements. For example, >> a2=1/(R(1)*R(2)*C(1)*C(2)) 2. Find the output voltage roots if C1 is changed to 1nF. In your report, include and discuss all the results. Compare the Matlab values with the theoretical values. School of Engineering and Technology Dr Akil Bashagha 5 3/23/2011 Signal Processing ENGD2002 Assignment-3 M-files (Script and Function) Script M-Files: The script file is a series of Matlab commands. These commands will be executed sequentially when the file name is typed in Matlab Command window. The script file is created using Matlab text editor: File/ New/ M-file and should be saved as filename.m. Comments are started with % and will be ignored during the execution of the M-file. Consider the operational amplifier circuit of Fig. 1. The output voltage could be calculated from the previous equations where 1 1 1 1 1 a0 1 ; a1 ( ); a2 ; C 2 R1 R2 R3 R1 R2 C1C 2 R2 C1 R3 R1 - C2 OUT + Fig. 1 Exercise-1: 1. Write the following script M-file. Start from File/ New/ M-file %opampf.m calculate roots of 2nd order equation of Op-Amp circuit %R, C values R=[1e4 1e4 1e4]; C=[1e-6 1e-6]; %coefficient values a0=1; a1=( 1/R(1)+ 1/R(2)+ 1/R(3))/C(2); a2=1/(R(1)*R(2)*C(1)*C(2)); A=[a0 a1 a2]; %the roots of characteristic equation lambda=roots(A); Save the file as opampf1.m To execute the file, type its name opampf in the matalb command window. >>opampf1 To view the roots, type >>lambda Dr Akil Bashagha 6 3/23/2011 2. Find the output voltage if C1 is changed to 1nF. Compare the roots with the previous values of the last assignment. Function M-Files In script files, you need to save and execute the file after changing any paramter. The function file is similar to the script file except the first line will be Function [output1, output2, …]=filename(input1, input2, …) Exercise-2: 1. Write the following function M-file. Start from File/ New/ M-file function [lambda]=opampf2(R,C) %opampf.m %Function M-file calculate roots of 2nd order equation of Op-Amp circuit %inputs: R= length-3 vector of resistances %inputs: C= length-2 vector of capacitances %outputs: lambda= roots of characteristic equation %coefficient values a0=1; a1=( 1/R(1)+ 1/R(2)+ 1/R(3))/C(2); a2=1/(R(1)*R(2)*C(1)*C(2)); A=[a0 a1 a2]; %the roots of chars. equation lambda=roots(A); Save the file as opampf2.m In matlab command, type the values of R and C >> R=[1e4 1e4 1e4]; >> C=[1e-6 1e-6]; To execute the file type its name with the inputs as follows >> lambda=opampf2(R,C) 2. From matlab command, change C1 to 1nF and claculate the new roots In your report, include and discuss all the results. Compare the Matlab values with the theoretical values. Dr Akil Bashagha 7 3/23/2011 School of Engineering and Technology Signal Processing ENGD2002 Assignment-4 Graphical explanation of Convolution Convolution is a complicated combination of multiplication, integration and time- shifting. We can define the convolution between two functions, h(t) and x(t) as the following y(t) h(t) * x( t) y (t ) x( )h(t )d y (t ) x(t )h( )d The variable τ (greek tau) is a dummy variable for integration. For the linear time invariant systems (LTI), x(t) is the input, y(t) is the output and h(t) is the impulse response of the system. The convolution operation can be difficult to perform in the time domain. Therefore, many people prefer to use the Laplace Transform (or another transform) to convert the convolution operation into a multiplication operation (in the frequency domain), through the Convolution Theorem. ( y(t)) ( h(t) * x(t)) Y ( s) H ( s) X ( s) H(s) represent the tranfer function of the LTI system and can be calculated as: Y (s) H (s) X (s) In this assignment, Matlab graphics is used to illustrate the convolution operation in the time domain. In the next exercise, you will write a program to find the output signal of a LTI system for an input signal x(t ) 1.5 sin(t )((u(t ) u(t 1)) The impulse response of the LTI system is given by h(t ) 1.5((u(t ) u(t 1.5)) u(t 2) u(t 2.5) Exercise: 1. Open a new Matlab M-file and write down the following commands. Save the file as convolution1.m. Dr Akil Bashagha 8 3/23/2011 %convolution script M-file graphically demonstrates convolution %creates new figure figure(1) %input x(t)=1.5sin(pi.t)(u(t)-u(t-1)) x=inline('1.5*sin(pi*t).*(t>=0&t<1)'); %impulse response h(t)=1.5(u(t)-u(t-1.5))-u(t-2)+u(t-2.5) h=inline('1.5*(t>=0&t<1.5)-(t>=2&t<2.5)'); %limits of tau dtau=0.005;tau=-1:dtau:4; %limits for time ti=0;tvec=-.25:.1:2.25; %preallocate memory y=NaN*zeros(1,length(tvec)); for t=tvec, ti=ti+1;%time index xh=x(t-tau).*h(tau);%integrand h(tau)*x(t-tau) lxh=length(xh); y(ti)=sum(xh.*dtau);%output, sum of area = integration subplot(2,1,1),plot(tau,h(tau),'b-',tau,x(t-tau),'k--',t,0,'og'); axis([tau(1) tau(end) -2 2.5]); xlabel('\tau');ylabel('x,h,xh');grid; end 2. Use different values of the end limit of time (-0.1, 0, 0.75, 1.5, 2.25, 2.75,3.75) and notice the common area between the two functions. Try to find the area of multiplying the two functions at the above limits. The area represents the function of convolution y(t) for different values of time. 3. Add the following lines to the above program (inside the for loop) and save it as convolution2.m. Run the new code for the above values of t. patch([tau(1:end-1);tau(1:end-1);tau(2:end);tau(2:end)], ... [zeros(1,lxh-1);xh(1:end-1);xh(2:end);zeros(1,lxh-1)],... [.8 .8 .8],'edgecolor','none'); legend('h(\tau)','x(t-\tau)','t','h(\tau)x(t-\tau)','location','eastoutside'); Try to predict the convolution function and draw it as a function of time. 4. Add the following lines to the above program (inside the for loop) and save it as convolution3.m. Run the new code for the above values of t. subplot(2,1,2),plot(tvec, y); axis([tau(1) tau(end) -2 2.5]); xlabel('t');ylabel('y(t)=x(t)*h(t)');grid; Compare the results with the expected convolution function from the previous step. In your report, include and discuss all the results. Compare the Matlab values with the theoretical values. School of Engineering and Technology Signal Processing Dr Akil Bashagha 9 3/23/2011 ENGD2002 Assignment-5 Discrete Time Signals In this assignment, some useful Matlab commands: stem, filter and conv will be used to analyse the discrete-time systems. Discrete Time Signals Stem command is used to plot the discrete-time function f[n] as stems from the x-axis terminated with circles for the data value. Options of stem command will help to use colours and filling of the plots. Consider the discrete-time function f[n]= e-n/5 cos(n/5) u[n] and use the following program to plot the function for -25 n 25. >> f=inline('exp(-n/5).*cos(pi*n/5).*(n>=0)','n') >> n=(-25:25)'; >> stem(n,f(n)); >> xlabel('n');ylabel('f[n]');grid; Exercise-1: 1. Plot the functions f[n] and f[n+1] on one figure as follows >> subplot(2,1,1);stem(n,f(n));xlabel('n');ylabel('f[n]');grid; >> subplot(2,1,2);stem(n,f(n+1));xlabel('n');ylabel('f[n+1]');grid; 2. Plot the functions f[n] and f[-n] on a new figure. 3. Plot the functions f[n] and f[2n] on a new figure 4. Plot the functions f[-2n] and f[-2n+1] on a new figure In your report, Q1. Use the graphs to explain the relationship between f[n] and the other functions of steps 1, 2, and 3. Q2. Explain the relationship between f[n], f[-2n] and f[-2n+1] of step-4. Could you recover f[n] from f[-2n] and f[-2n+1]? Explain that. Discrete time filtering: The discrete-time filtering in time domain is represented by the following constant coefficient linear difference equation: N M a k 0 k y[n k ] bk x[n k ] k 0 If we assume a0 =1 then the output filtered data y[n] is calculated as Dr Akil Bashagha 10 3/23/2011 M N y[n] bk x[n k ] a k y[n k ] k 0 k 1 Therefore, we need the input sequence x[n], the (N+1)-input coefficient vector, B =[b0 b1 b2 b3 … bM], and the (N+1)-output coefficient vector, A=[1 a1 a2 a3 … aN], to calculate y[n]. Exercise-2: The following example of filtering for N=3 is used to calculate the impulse response h[n]. y[n] x[n] y[n 1] y[n 2] Use the filter command as follows >> h = filter (B, A, x(n)); to calculate the impulse response h[n] for an impulse input x[n] for -25 n 25. Use the above equations to find B and A as vectors where A=[1 a1 a2 a3 … aN] and B =[b0 b1 b2 b3 … bM]. 1. Start with inline command to define the input function x[n] as an impulse (‘n==0’) and use stem to plot it. 2. Calculate h[n] using filter command and plot it. 3. Change the input to x[n] = cos(2n/6)u[n] and plot the input and output. 4. Change the input to x[n] = cos(n/6)u[n] and plot the input and output. In you report Q1. What is the order of the system? Q2. Is the system stable or not? Explain why? Q3. Comment on the three inputs of the system. Q4. Use the characteristic equation of the system to compare the impulse response and the outputs from steps-2 and 3. Discrete time convolution: The output of the discrete-time system in the time domain can be obtained as a convolution of the impulse response h[n] and the input x[n], y[n] h[n] * x[n] y[n] h[k ]x[n k ] k The impulse response h[n] of the system y[n] x[n] y[n 1] y[n 2] is given by sin(n / 3) h[n] {cos(n / 3) }u[n] 3 Dr Akil Bashagha 11 3/23/2011 Exercise-3: 1. Use inline to define h[n] and plot it for 0 n 25. 2. Use inline to define x[n] = cos(2n/6)u[n] as before and plot it. 3. Calculate y[n] using conv command and plot it >> y=conv(h(n),x(n)); >> stem(n,y(1:26)) In you report sin(n / 3) Q1. Prove that h(n) {cos(n / 3) }u[n] . 3 Q2. Compare the above results with the results of Exercise-2. In your report, include and discuss all the results. Answer the questions. Compare the Matlab values with the theoretical values. Dr Akil Bashagha 12 3/23/2011 School of Engineering and Technology Signal Processing ENGD2002 Assignment-6 Continuous Time Filters The main objective of this assignment is to study analogue filters in frequency domain. The filter is an electronic circuit used in signal processing to remove the unwanted frequencies and to pass the wanted frequencies. The general form of a transfer function of linear time invariant continuous time LTIC system with input X and output Y is given by M Y (s) b k s M k H ( s) k 0 N a X ( s) k s N k k 0 The numerator and denominator polynomials are of the following form M b s k 0 k M k b0 S M b1 S M 1 b2 S M 2 ... bM 1 S bM N a s k 0 k N k a0 S N a1 S N 1 a2 S N 2 ... a N 1 S a N To calculate H(s) in frequency domain where s=j, the vectors A and B of N+1 and M+1 coefficients are given by A [a0 a1 a2 ... a N ] B [b0 b1 b2 ... bM ] In Matlab, polyval function calculates the polynomial for a range of frequencies =2f where in rad/sec and f in Hz. For example, >>polyval(A,j*) calculates the polynomial for s=j. N a s k 0 k N k a0 S N a1 S N 1 a2 S N 2 ... a N 1 S a N The following Matlab commands are useful for this assignment >> polyval(…) >> abs( … ) >>angle(….) >> semilogx( … ) >> log10(…) Exercise-1: 1. Use Matlab to evaluate and plot the absolute value (using abs(H)) of the following first-order polynomial for 0 f 10Hz. H (s) ( s 10) / 10 Dr Akil Bashagha 13 3/23/2011 2. Repeat the above calculation for H (s) 10 /(s 10) 3. Repeat step-1 and 2 to plot H(s) in decibels (db) against logarithmic x-axis. Exercise-2: There are many different types of analogue and digital filters. A simple example of an analogue filter is the passive continuous time circuit of Fig. 1. The transfer function H(j) and cut off frequency fc are given by 1 H ( j ) 1 jRC 1 fc 2RC R Vin C Vout Fig. 1 1. Design the RC filter shown in Fig. 1 with a cut off frequency of 1 kHz and assume that the capacitor value is 0.1 µF. 2. Plot magnitude of transfer function in db against frequency (use log scale for x axis) for 1Hz f 10 kHz . 3. Plot the phase of transfer function in degrees against frequency (use log scale for x axis) using the Matlab command angle(…). 4. Use Matlab command subplot to plot the magnitude and phase on the same figure. 5. Calculate H(s) after swapping R with C. Follow the above four steps to design, calculate and plot the characteristics of the transfer function. In your report: 1. Calculate the theoretical values of magnitude response of Exercise-1 and compare them with the practical results. 2. Derive the transfer function of the filter of Fig. 1 and its cut off frequency. 3. Derive the transfer function and its cut off frequency after swapping R with C. 4. What type of the filter of Fig.1 and the one after swapping R with C 5. Calculate the theoretical values of magnitude and phase responses and cut off frequency of Exercise-2 and compare that with the practical results and ideal response. 6. Define and comment on the cut-off frequency, -3DB points, and roll-off rate (DB/decade). Dr Akil Bashagha 14 3/23/2011 School of Engineering and Technology Signal Processing ENGD2002 Assignment-7 Discrete Time Filters The main objective of this assignment is to study discrete-time filters in frequency domain. The general form of a transfer function of linear time invariant Discrete time LTID system with input X and output Y is given by M M Y ( z) bk z k b z k k H ( z) k 0 N k 0 N (1) a 1 ak z X ( z) k k k z k 0 k 1 The output response in frequency domain Y(z) is given by Y ( z) H ( z) X ( z) (2) The output response in the time domain y[n] can be obtained as a convolution of the impulse response h[n] and the input x[n], y[n] h[n] * x[n] (3) y[n] h[k ]x[n k ] k 0 The (N+1)-output coefficient vector, A, and the (M+1)-input coefficient vector, B are given by A [1 a1 a2 ... a N ] B [b0 b1 b2 ... bM ] (4) The LTID system of Eq. (1) could also be represented in the time domain as N M y[n] ak y[n k ] bk x[n k ] (5) k 1 k 0 The output y[n] is given by M N y[n] bk x[n k ] a k y[n k ] (6) k 0 k 1 There are two types of digital filter namely finite-impulse response FIR filters and infinite-impulse response IIR filters. In FIR filters, the output coefficients ak (for k=1,…, N) are zeros except a0=1. The output y[n] depends only on the present and the past input samples so that M y[n] bk x[n k ] (7) k 0 M Y ( z ) bk z k X ( z ) (8) k 0 The transfer function H(z)=Y(z) / X(z) is given by M H ( z ) bk z k (9) k 0 Dr Akil Bashagha 15 3/23/2011 The length of the impulse response h[k] of FIR filters is finite and depends on the input coefficients bk. h[k] can be obtained from comparing Eq. (3) with Eq. (7) or by using the inverse Z-transform of Eq. (9) as it equals the input coefficients bk. h[k ] bk B so h[0] b0 h[1] b1 , …, h[ M ] bM (10) The infinite impulse response IIR filter has at least one of the output coefficients ak (for k=1,…, N) is nonzero. The transfer function H(z) will be a ratio of two polynomials as in Eq. (1). The output y[n] as given by Eq. (6) depends on the past output samples as well as the present and the past input values. The IIR filter has a feedback from the output to the input. Exercise-1: The frequency response of the filter is obtained after replacing z by ejT=ej where (2f) is the analogue frequency (rad/ sec) and is the digital frequency (rad). T is the sampling period (T=1/fs). Normally, the range of digital frequency is 0 and the equivalent analogue frequency range is 0f fs/2. 1. Plot the magnitude (db) and phase (°) as functions of digital frequency (rad) for 0 for the following FIR filter. H(z) = 0.0101 + 0.2203 z-1 + 0.5391 z-2 + 0.2203 z-3 + 0.0101 z-4 Use the freqz Matlab command to calculate the transfer function H(z) as >>H=freqz(B,A,wd) where A=1; wd==2fT. Use fs=1kHz and 0f fs/2. 2. Plot both magnitude and phase of the above step in one figure. Exercise-2: The command fir1could be used to design FIR filter by calculating its coefficients as >> B=fir1(M,Wn) M is the order of the filter and Wn is the normalized cut off frequency (cut = *Wn rad). The Matlab command freqz(B,A,wd) with no output arguments plots the magnitude and phase of the filter. 1. Use fir1 to design a filter with M=4 and Wn=0.4. 2. Use freqz without H to plot the FIR filter characteristics and compare the graphs with Exercise-1 above. 3. Design another FIR filter with M=20 and Wn=0.4 and plot its characteristics. Compare the new graphs with the previous ones. Dr Akil Bashagha 16 3/23/2011 Exercise-3: 1. Plot the magnitude (db) and phase (°) of the following transfer function as functions of digital frequency (rad) (0 ) for three different values of p: 0.83, 0.96, 0.99 1 z 2 H ( z) 1 2z 1 2 z 2 2. Write an m-file to plot the magnitude (as a normal value and not in db) and phase (°) for the three values of p on the same graph. Use subplot to divide the figure into two halves. Plot the magnitude for the three values of p in the upper half and the phase in the lower half. In your report, include and discuss all the results and name the types of filters used in the above exercises. Dr Akil Bashagha 17 3/23/2011

DOCUMENT INFO

Shared By:

Categories:

Tags:
Research Group, PhD Research, honours degree, Electronic Engineering, Higher Education, Vendor Management, last name, Delivery Manager, Project Manager, General Manager

Stats:

views: | 30 |

posted: | 3/23/2011 |

language: | English |

pages: | 17 |

OTHER DOCS BY nikeborome

How are you planning on using Docstoc?
BUSINESS
PERSONAL

By registering with docstoc.com you agree to our
privacy policy and
terms of service, and to receive content and offer notifications.

Docstoc is the premier online destination to start and grow small businesses. It hosts the best quality and widest selection of professional documents (over 20 million) and resources including expert videos, articles and productivity tools to make every small business better.

Search or Browse for any specific document or resource you need for your business. Or explore our curated resources for Starting a Business, Growing a Business or for Professional Development.

Feel free to Contact Us with any questions you might have.