Dsp Lab -15ecl57 Part_i



Comments



Description

DSP Lab ManualVISVESVARAYA TECHNOLOGICAL UNIVERSITY “JNANASANGAMA” BELAGAVI – 590018 KARNATAKA STATE, INDIA Page | 1 DIGITAL SIGNAL PROCESSING LAB MANUAL SUBJECT CODE: 15ECL57 V SEMESTER E&C ENGINEERING Manual authored by Manual Approved by ANIL B.V. Dr.Ravikumar M.S. Associate Professor Professor and Head DEPT. OF ELECTRONICS AND COMMUNICATION ENGINEERING K.V.G. COLLEGE OF ENGINEERING SULLIA, D.K. - 574327 KARNATAKA STATE, INDIA K.V.G. College of Engineering, Sullia D.K. DSP Lab Manual DSP Lab B.E., V Semester, EC/TC [As per Choice Based Credit System (CBCS) scheme] Page | 2 Subject Code:15ECL57 IA Marks 20 Number of Lecture Hours/Week 01Hr Tutorial (Instructions)+02 Hours Laboratory=03 Exam Marks 80 Exam Hours 03 CREDITS – 02 Laboratory Experiments Following Experiments to be done using MATLAB / SCILAB / OCTAVE or Equivalent: 1. Verification of sampling theorem. 2. Linear and circular convolution of two given sequences, Commutative, Distributive and Associative property of convolution. 3. Auto and cross correlation of two sequences and verification of their properties 4. Solving a given difference equation. 5. Computation of N point DFT of a given sequence and to plot magnitude and phase spectrum (using DFT equation and verify it by built-in routine). 6. (i) Verification of DFT properties (Linearity and Parseval’s theorem, etc.)(ii) DFT computation of square pulse and sinc function etc. 7. Design and implementation of FIR filter to meet given specifications (using different window techniques). 8. Design and implementation of IIR filter to meet given specifications. Following Experiments to be done using DSP kit 9. Linear convolution of two sequences 10. Circular convolution of two sequences 11. N-point DFT of a given sequence 12. Impulse response of first order and second order system 13. Implementation of FIR filter Conduct of Practical Examination: 1. All laboratory experiments are to be included for practical examination. 2. Strictly follow the instructions as printed on the cover page of answer script for breakup of marks. 3. Change of experiment is allowed only once and Marks allotted to the procedure part to be made zero. K.V.G. College of Engineering, Sullia D.K. DSP Lab Manual Page | 3 I - CYCLE EXPERIMENTS Expt. No. Experiment Name 1 Verification of Sampling Theorem 2 a) Linear convolutionof two sequences i) Causal ii) Noncausal b) Circular convolution of two sequences Commutative, Distributive and Associative properties of convolution. 3 a) Auto correlation of two sequences b) Cross correlation of two sequences Verification of the properties of Correlation. 4 a) Solving a difference equation without initial conditions b) Solving a difference equation with initial conditions K.V.G. College of Engineering, Sullia D.K. V. . DSP Lab Manual Page | 4 PART .A MATLAB® PROGRAMS K. Sullia D.G. College of Engineering.K. 3) 𝟐𝝅𝑩(𝒕− ) 𝟐𝑩 The sampling rate FN = 2Fmax = 2BHz is called the Nyquist rate.1) (𝟐𝛑𝐁𝐭) Thus xa(t) may be expressed as 𝒏 𝐱 𝐚 (𝐭) = ∑∞ 𝒏= −∞ 𝐱 𝐚 (𝑭𝒔)𝒈(𝒕 − 𝒏/𝑭𝒔) … (1. Figure 1. then xa(t) can be exactly recovered from its sample values using the interpolation function 𝐬𝐢𝐧(𝟐𝛑𝐁𝐭) 𝒈(𝐭) = … (1. sampling is the mapping of a continuous-time continuous-valued signal to a discrete-time continuous-valued signal. DSP Lab Manual EXPT No: 1 DATE: VERIFICATION OF SAMPLING THEOREM AIM: To execute MATLAB m-file program for the sampling of a composite Page | 5 continuous time signal and to reconstruct it from the samples based on Nyquist Sampling criteria. College of Engineering.2) where xa(𝑛/𝐹𝑠) = xa(nT) ≡ x[n] are the samples of xa(t).G.K. Sullia D. K.1 The sampled continuous time signal Nyquist Sampling Theorem: If the highest frequency contained in an analog signal xa(t) is Fmax = B Hz and the signal is sampled at a rate Fs> 2 Fmax = 2B. When the sampling of xa(t) is performed at the minimum sampling rate Fs = 2B. . the reconstruction formula 𝒏 𝒏 𝒔𝒊𝒏 𝟐𝝅𝑩(𝒕− ) becomes: 𝒙𝒂 (𝐭) = ∑∞ 𝒏= −∞ 𝐱 𝐚 (𝟐𝑩) 𝒏 𝟐𝑩 … (1. THEORY:In signal processing.V. A common example is the conversion of audio signal (a continuous signal) to a sequence of samples (a discrete-time signal). 8) = Acos[ωn]≡ 𝐱[𝐧] … (1. t1 define t from t0 to t1 in steps of Δt x1= A1 cos( 2πF1t ).G.K. xa(t) = A cos(Ωt) = A cos(2πFt) … (1. x2 = A2 cos( 2πF2t ) x = x1 + x2 choose Fs based on max( F1.Δt.V. and fis called discrete time frequency with units cycles/sample.7) = Acos[2πfn] … (1. ω = ΩT describes the relationship between the D. DSP Lab Manual Consider a continuous-time signal.4) If Fs is the sampling frequency then Fs= 1/T samples per second. Sullia D.5) = Acos[2πFnT] … (1. with amplitude ‘A’ and frequency ‘F’ Hz. College of Engineering.T. xa[nT]=Acos[ΩnT] … (1.8 it can be seen that f = [ 𝑭𝒔]. T is the sampling Page | 6 interval in seconds. t0.7 and eqn1.T angular frequency(rad/sec) ALGORIHM: Begin Read Amplitude ‘A’ and Frequency ‘F’. 2πf = ω is called discrete-time angular frequency with units radian/sample.9) 𝑭 Comparing eqn1.6) 𝑭 =Acos[2π[𝑭𝒔]n] … (1. F2 ) define n from n0 = (t0/Ts) to n1 = ( t1/Ts) in steps of 1 xn1 = A1cos[ 2πF1nT ] xn2 = A2cos[ 2πF2nT ] xn = xn1 + xn2 𝒔𝒊𝒏(𝟐𝝅𝑩𝒕) compute 𝒈 = (𝟐𝝅𝑩𝒕) forn0to n1in steps of 1 𝑛 𝑛 𝑠𝑖𝑛 2𝜋𝐵(𝑡− ) 2𝐵 𝑥𝑟 = ∑ 𝑥𝑎 (𝑛/𝐹𝑠)𝑔(𝑡 − 𝑛/𝐹𝑠) ) = ∑ 𝑥𝑎 (2𝐵) 𝑛 2𝜋𝐵(𝑡− ) 2𝐵 end End K. angular frequency and C. . 2 ) plot( t. % Generate the single composite Analog Signal xa(t) xa = x1 + x2. x2. 1. 1 ) plot( t. % Sum of the Amplitudes for plotting of xa(t) A = A1 + A2. DSP Lab Manual PROGRAM: samp_thrm. A2 = input(‘Amplitude of signal x2(t) = '). 'g' ) axis( [ t0 t1 -A2 A2 ] ) K. College of Engineering. Sullia D. t1 = input(‘ End Time = '). % Define Analog Signals x1 = A1 * cos( 2 * pi * F1 * t ).V. % Define Beginning and End Time t0 = input(' Beginning Time = '). x1. 1. % To plot x1(t).K. % Define x-axis as Time axis t = t0: Delta_t : t1. 'r' ) axis( [ t0t1 -A1 A1 ] ) ylabel( 'x1(t)' ) title ( ' Continuous Time Signals ' ) subplot( 3. % Define the Time Resolution Delta_t= input('Resolution =’). x2(t) and xa(t) signals figure( 1 ) %Clear Command Window subplot( 3. x2 = A2 * cos( 2 * pi * F2 * t ). F2 = input(‘Frequency of signal x2(t) = '). % Enter the frequency values F1 = input(‘Frequency of signal x1(t) = '). .m clc %Clear Command Window clear all % Clear all the variables close all % Close all Figure Windows Page | 7 % Enter the Amplitude values A1 = input(‘Amplitude of signal x1(t) = ').G. 1. length(t) ). 3 ) plot( t. t1/Ts. length( t ) ). A2 ] ) ylabel( 'x2[n]' ) subplot( 3.K. 2 ) stem( n. . % Calculate the number of Samples n0 = t0/Ts n1 = t1/Ts. College of Engineering. nT = n * Ts. xn = xn1 + xn2. DSP Lab Manual ylabel( 'x2(t)' ) subplot( 3. end K. -A. 1. figure(2) subplot( 3. 'b' ) axis( [ t0/Ts. 1. t1/Ts. A ] ) ylabel( 'x [n]' ) % Find the Maximum Frequency for reconstruction Fmax = max( [ F1 F2 ] ). 'g' ) axis( [ t0/Ts. for row = 1 : length(nT) Theta( row. Theta = zeros( length(nT). xn2 = A2 * cos( 2 * pi * F2 * nT ). n = n0:n1. -A2. t1/Ts. A1 ] ) ylabel( 'x1[n]' ) title ( ' Discrete Time Signals ' ) subplot( 3. -A1. xn1 = A1 * cos( 2 * pi * F1 * nT ). 'r' ) axis( [ t0/Ts. 'b' ) axis( [ t0 t1 -A A] ) ylabel( 'x3(t)' ) Page | 8 % Choose the Sampling Frequency satisfying Nyquist’s Sampling Theorem Fs = input('Enter the Sampling Frequency in Hz = ' ). xn2. : ) = t( 1. tn = nT' * ones( 1. 3 ) stem( n.V. 1. % Calculate the Sampling Interval Ts = 1/Fs. xa.G. Sullia D. xn1. xn. : ) .tn( row. : ). 1 ) stem( n. 'b' ) xlabel( ' t--> ' ) ylabel(' xr(t) ' ) title ( ' Reconstructed Continous Time Signals ' ) >> Amplitude of signal x1(t) = 1. . DSP Lab Manual % Generation of Interpolation Function Interpolate = sinc( ( 2 * pi * Fmax ) . 'b' ) axis( [ t0. 2 ) plot( t. -A.2 Amplitude of signal x2(t) = 0. Sullia D.V.* Theta ).8 Frequency in Hz of signal x1(t) = 4 Frequency in Hz of signal x2(t) = 8 Beginning Time = -1 End Time = 1 Resolution =0. xr = xn * Interpolate. 1 ) plot( t.G. t1.0001 Enter the Sampling Frequency in Hz = 64 Figure 1. 1. Page | 9 figure(3) subplot( 2. 1. K. xa. xr.2Screenshot of the output of Nyquist Sampling Theorem Verification program for perfect reconstruction. College of Engineering. A ] ) xlabel( ' t--> ' ) ylabel(' xa(t) ' ) title ( ' Original Continous Time Signals ' ) subplot( 2.K. associative and distributive properties. College of Engineering. For a non-causal system the response is given by the convolution summation defined by the eqn3. 2. DSP Lab Manual EXPT No: 2 a) DATE: LINEAR CONVOLUTION OF TWO SEQUENCES AIM: To execute MATLAB m-file program for finding the response of a given Linear Page | 10 Time Invariant system by linear convolution summation with: (i) Causal sequence (ii) Non Causal sequence and (iii) To verify commutative. 1}Nh = 3 Ny =Nx + Nh . 3. THEORY: For discrete time systems with input signal x(n) and finite duration unit impulse response h(n).1) Eqn 3.3) Graphical Computation of Linear Convolution Summation: • Reflection of h(k) resulting in h(-k) • Shifting of h(-k) resulting in h(n-k) • Element wise multiplication of the sequences x(k) and h(n-k) • Summation of the product sequence x(k) h(n-k) results in the convolution Sample value for y(n) Example: x(n) = {1.1 represents the response of a causal system. linear convolution summation is defined by 𝐲(𝐧) = ∑𝑵 𝑵 𝒌= 𝟎 𝐱[𝐤]𝐡[𝐧 − 𝐤] = ∑𝒌=𝟎 𝐡[𝐤]𝐱[𝐧 − 𝐤] … (3.2 𝑵 𝑵𝟐 y(n) =∑𝒌=𝟐 −𝑵𝟏 𝐱[𝐤]𝐡[𝐧 − 𝐤] = ∑𝒌=−𝑵 𝟏 𝐡[𝐤]𝐱[𝐧 − 𝐤] … (3.K. .1 … (3. 1}Nx = 4 h(n) = {1. 1. Sullia D.2) If Nx is the length of x[n] and Nh is the length of h[n] then the length of y[n] is Ny given by Ny= Nx + Nh .V.1= 4 + 3 – 1 = 6 K.G. K.G.V. College of Engineering. DSP Lab Manual Page | 11 K. Sullia D. . G.V. .k . DSP Lab Manual Page | 12 y[n] = { 1. 6.K. yn display xn.Causal Begin Read xn and hn Compute yn = ∑ xk hn. 1 } ALGORIHM: (i) Convolution . College of Engineering. hn. hn. Sullia D. 4. yn End K. ∀n length of xn. 6. 3. 'filled' ) xlabel(' n--> ' ) ylabel(' y[n] ' ) K. 'filled' ) xlabel(' n--> ' ) ylabel(' h[n] ' ) title(' Impulse Response h[n] ' ) subplot( 3.m clc Page | 13 clear all close all % Enter the samples of Input Sequence x[n] and Unit Impulse Response h[n] x = input('Enter the Discrete Input Signal Sequence x[n] = '). DSP Lab Manual PROGRAM:(i)conv_causal.V. 'filled' ) xlabel(' n--> ' ) ylabel(' x[n] ' ) title(' Input Sequence x[n] ' ) subplot( 3. % Convolving Input x[n] and Impulse Response h[n] % y = conv( h. College of Engineering. 1 ) stem(nx. disp(' The Convolution of x[n] and h[n] is y[n] = ' ) disp( y ) disp(' The number of samples in y[n] is Ny = ' ) disp(Ny ) figure( 1 ) subplot( 3. nx = 0 : 1 : Nx-1. 1. nh = 0 : 1 : Nh-1. 'r'. ny = 0 : 1 : Ny-1.K. 'r'. x ). x. 1.G. . Nh = length( h ). Sullia D. y. h = input('Enter the Impulse Response Sequence h[n] = '). Ny = length( y ). 2 ) stem(nh. 1. h. Nx = length( x ). 'r'. 3 ) stem(ny. Non Causal Begin Read xn. . yn End K. 4 ] Enter the Impulse Response Sequence h[n] = [ 3 1 2 1 ] The Convolution of x[n] and h[n] is y[n] = 3 7 13 20 12 11 4 The number of samples in y[n] is Ny = 7 >> Fig 3.G. ∀n Min(ny)= Min(nx)+Min(nh) Max(ny)= Max(nx)+Max(nh) ny = Min(ny):Max(ny) displayxn.V. 3. hn andnh Compute yn = ∑ xkhn. 2.m program ALGORIHM: (ii) Convolution .K. hn. DSP Lab Manual title(' Output Sequence y[n] ' ) AFTER THE EXECUTION: Page | 14 >> Enter the Discrete Input Signal Sequence x[n] = [ 1.k . College of Engineering.nx. Sullia D.1 Screenshot of output of the conv_causal. 1 ] Enter the index values of x[n] = -2:2 Enter the Unit Impulse Response h[n] = [ 1.G.V. disp(' The Output Sequence = ' ) disp( y ) disp(ny ) figure(1) subplot( 3. College of Engineering. 'filled' ) axis( [ min(nx) max(nx) min(x) max(x) ] ) xlabel(' n--> ') ylabel(' x[n] ') title(' Input Signal x[n] ' ) subplot( 3. 1. 2. 1] Enter the index values of h[n] = -1:2 The Output Sequence = 3 13 23 28 21 12 4 1 -3 -2 -1 0 1 2 3 4 K. 1. 1. DSP Lab Manual PROGRAM: (ii)conv_noncuasal. y. 4. nh = input( ' Enter the index values of h[n] = ' ). 3 ) stem ( ny. 5. 'filled' ) axis( [ min(ny) max(ny) min(y) max(y) ] ) xlabel(' n--> ') ylabel(' y[n] ') title(' Input Signal y[n] ' ) AFTER THE EXECUTION: >> Enter the input signal x[n] = [ 3. nx = input( ' Enter the index values of x[n] = ' ). 3. Sullia D. 2 ) stem ( nh. 1 ) stem ( nx. h = input(' Enter the Unit Impulse Response h[n] = ' ). . 2. 'filled' ) axis( [ min(nh) max(nh) min(h) max(h) ] ) xlabel(' n--> ') ylabel(' h[n] ') title(' Input Signal h[n] ' ) subplot( 3. % Index Sequence of y[n] % ny = ( min(nx)+min(nh) ) : 1 : ( max(nx)+max(nh) ). x ).K. x. % Convolution % y = conv( h.m clc clear all close all Page | 15 % Enter the values of x[n] and h[n] x = input(' Enter the input signal x[n] = ' ). h. h1) y2 = conv(h1.2 Screenshot of output of the conv_noncausal. 1. 2. Associative & Distributive properties of Linear Convolution clc clear all close all x = [3.K. College of Engineering. x) if y1 == y2 disp('Commutative Property of convolution is proved').V. 1]. 2. else disp('error in the computation') end K. 2. DSP Lab Manual >> Page | 16 Fig 3. %Commutative Property y1 = conv(x.G. 1 ]. Sullia D. 2. h2 = [ 2. .m program Commutative. 4. h1 = [ 1. 4 ]. h1). h1+h2) y6 = conv(x. h2) Page | 17 if y3 == y4 disp('Associative Property of convolution is proved'). DSP Lab Manual % Associative Property y3 = conv(x. else disp('error in the computation') end % Distributive Property y5 = conv(x. h2)) y4 = conv(conv(x. h2) if y5 == y6 disp('Distributive Property of convolution is proved'). . College of Engineering.G. else disp('error in the computation') end >> y1 = 3 7 10 10 7 4 1 y2 = 3 7 10 10 7 4 1 Commutative Property of convolution is proved y3 = 6 26 54 86 102 96 72 40 18 4 y4 = 6 26 54 86 102 96 72 40 18 4 Associative Property of convolution is proved y5 = 9 21 24 34 19 14 5 y6 = 9 21 24 34 19 14 5 K.V. Sullia D. conv(h1.K. h1) + conv(x. HoweverLinear convolution result can be obtained from circular convolution using the following steps:  Append ( Nh .1 ) zeros to x[n]andthus resulting length is (Nx+ Nh .V. 0.1) IfNx is the length of x[n] and Nh is the length of h[n] then the length of y[n] is Ny given by Ny = Max(Nx.Nh). Sullia D. 0. 0. 0. 2. 0. THEORY: Circular convolution of two finite duration discrete time sequences x[n] and h[n] is given by 𝐲(𝐧) = ∑𝑵 𝑵 𝒌= 𝟎 𝐱[𝐤]𝐡[(𝐧 − 𝐤)]𝐍 = ∑𝒌=𝟎 𝐡[𝐤] 𝐱[(𝐧 − 𝐤)]𝐍 … (4.1 )  Append ( Nx .G.Nh ) … (4. 1} and x2(n) = {1.1 ) zeros to h[n] andthus resulting length is (Nx+ Nh .K. . College of Engineering. …. Example: Given x1(n) = {1. 2. 3. 1. ….2) The computation of y[n] is based on the equalization of the lengths of x[n] and h[n] by appending appropriate zeros with the following logic: ifNx>Nh hn = [ hn. associative and distributive properties. Circular convolution performed in this manner has no practical significance. DSP Lab Manual Distributive Property of convolution is proved EXPT No: 2 b) DATE: CIRCULAR CONVOLUTION OF TWO SEQUENCES Page | 18 AIM: To execute an m-file program to compute the circular convolution of two given finite-duration discrete-time sequences and to verify the commutative. 0 ] (Nx -Nh) zeros else xn = [ xn. 4}.Nx ) zeros end The length of y[n] is Ny = Max(Nx. 0] (Nh. Arrange x1(n) and x2(n) in circular fashion as shown below K. 0.1 )  Perform circular convolution y[n] = x[n] (*) h[n]  Resulting y[n] is same as linear convolution between x[n] & h[n] Linear convolution is the response of an LTI system. . x3(0) = x1(m) x2(-m) = x1(0) x2(0) + x1(1) x2(3) + x1(2) x2(2) + x1(3) x2(1) = 1 + 4 + 6 +2 = 13 x3(0) = 13 Keep x1(m) constant and rotate x2(-m) once to compute further values. rotate x2(m) by 4 samples in clockwise direction. Sullia D. College of Engineering. DSP Lab Manual Page | 19 To get x2(-m).K. To get x3(1) rotate x2(-m) by one sample in anti-clockwise direction x2(1-m) K.V.G. DSP Lab Manual x3(1) = x1(m) x2(1-m) = x1(0) x2(1) + x1(1) x2(0) + x1(2) x2(3) + x1(3) x2(2) = 2 + 1 + 8 + 3 = 14 x3(1) = 14 Page | 20 To get x3(2) rotate x2(1-m) by one sample in anti-clockwise direction x2(2-m) x3(2) = x1(m) x2(2-m) = x1(0) x2(2) + x1(1) x2(1) + x1(2) x2(0) + x1(3) x2(3) = 3 + 2 + 2+ 4 = 11 x3(2) = 11 To get x3(3) rotate x2(2-m) by one sample in anti-clockwise direction x2(3-m) x3(3) = x1(m) x2(3-m) = x1(0) x2(3) + x1(1) x2(2) + x1(2) x2(1) + x1(3) x2(0) = 4 + 3 + 4 + 1 = 12 x3(3) = 12 The convoluted signal is.G.K. x3(n) = {13. 14. 11. Sullia D. College of Engineering. 12} ALGORIHM: Circular Convolution Begin K. .V. DSP Lab Manual Read xn and hn Compute length of xn. H2 = fft(h. ∀n displayxn. y1 = ifft(Y1). Nx+Nh-1). Nh = length( h ). Nx+Nh-1).Nh ) ].…0] Page | 21 else xn= [xn.* temp ). end disp(' Circular convolution of x[n] and h[n] is y[n] ' ) disp( y ) X1 = fft(x). else x = [ x zeros( Nh .0. disp(' Circular convolution of x[n] and h[n] in frequency domain is y1[n] ' ) disp( y1 ) X2 = fft(x. for k = 2 : N temp = circshift( temp'. end N = max(Nx. y(1) = sum( x . y( k ) = sum( x . K. Nx = length( x ).Nx ) ]. hn if (Nx>Nh) hn= [hn. Y1 = X1 . 0.V. Sullia D.m clc clear all close all x = input(' Enter the samples of x[n] = ' ). .* temp ). 0.…0] yn = ∑ xk h((n. hn. yn End PROGRAM:circ_conv. k-1 )'. temp = [ h(1) fliplr( h( 2:N ) ) ].K. H1 = fft(h).k)) .G. if ( Nx>Nh ) h = [ h zeros( Nx . Nh ). College of Engineering.* H1. h = input(' Enter the samples of h[n] = ' ).0. Nx+Nh-1). 'r'. disp(' Linear convolution of x[n] and h[n] in frequency domain is y2[n] ' ) disp( y2 ) Page | 22 figure( 1 ) subplot( 3. 'filled' ) title(' Discrete Time Sequence x[n] ' ) xlabel(' n--> ' ) ylabel(' x[n] ' ) subplot( 3. 3 ) stem( 0 : N-1. 'r'. 'r'. 1.V.2. 4] Enter the samples of h[n] = [ 1 . . 'filled' ) title(' Discrete Time Sequence y[n] ' ) xlabel(' n--> ' ) ylabel(' y[n] ' ) AFTER THE EXECUTION: >> Enter the samples of x[n] = [ 1. 1. y2= ifft(Y2. 1 ] Circular convolution of x[n] and h[n] is y[n] 17 15 13 15 Circular convolution of x[n] and h[n] in frequency domain is y1[n] 17 15 13 15 Linear convolution of x[n] and h[n] in frequency domain is y2[n] 1 4 9 15 16 11 4 K. 3. College of Engineering. 2. DSP Lab Manual Y2 = X2. 2. Sullia D. x. h. 1.G.*H2. y. 2 ) stem( 0 : Nh-1. 'filled' ) title(' Discrete Time Sequence h[n] ' ) xlabel(' n--> ' ) ylabel(' h[n] ' ) subplot( 3.K. 1 ) stem( 0 : Nx-1. 1].1 Screenshot of output of the circ_conv. Associative & Distributive properties of Convolution clc clear all close all x = [3. else disp('Error in compuatation'). 4 ]. Y1h = H1 . h2 = [ 2. . 1. DSP Lab Manual Page | 23 Fig 4.* H1.V.m program Commutative. y1x = ifft(Y1x) y1h = ifft(Y1h) if y1x == y1h disp('Commutative Property proved'). College of Engineering. end K. H1 = fft(h1). h1 = [ 1. Sullia D. %Commutative Property X1 = fft(x). 2.K. Y1x = X1 . 2.G. 4.* X1. 2. 2. 1 ]. * H2. Yhx = (X1 .* ( H1 .* H1) . y11 = ifft(Y11) y12 = ifft(Y12) if y11 == y12 disp('Distributive Property proved').V.G. Y12 = X1 .* H2.K. Yxh = X1 . .* H2 ). else disp('Error in compuatation'). end >>y1x = 10 11 11 10 y1h = 10 11 11 10 Commutative Property proved yxh = 126 126 126 126 yhx = 126 126 126 126 Associative Property proved y11 = 28 35 29 34 y12 = 28 35 29 34 Distributive Property proved >> K.* H1 + X1 . DSP Lab Manual %Associative Property H2 = fft(h2). College of Engineering.* ( H1 + H2). Page | 24 yxh = ifft( Yxh ) yhx = ifft(Yhx) if yxh == yhx disp('Associative Property proved'). end %Distributive Property Y11 = X1 . Sullia D. else disp('Error in compuatation'). K. It is used frequently in signal processing for analysing functions or series of values. 𝒓𝒙𝒙 [𝟎] = ∑∞ ∞ 𝟐 𝒏=−∞ 𝐱[𝒏]𝒙[ 𝒏] = ∑𝒏=−∞ |𝐱[𝒏]| = 𝑬𝒙 … (5. DSP Lab Manual EXPT No: 3 a) DATE: AUTOCORRELATIONOF A SEQUENCE AND Page | 25 VERIFICATION OF ITS PROPERTIES AIM: To execute an m-file program to find the autocorrelation of a given sequence and to verify its properties.V. College of Engineering. 5. It may be recalled that in convolution one of the sequence is time reversed and then the operations of shifting multiplications and additions are carried out.1 indicates that the sequence x[n] is shifted by lsamples with respect to itself. Eqn. PROPERTIES OF AUTO CORRELATION: (i) 𝒓𝒙𝒙 [ 𝒍 ]attainsmaximum value when the lag parameter l = 0. 2..G.1) Where the integer parameter l is called the lag indicator. Autocorrelation is a mathematical tool for finding repeating patterns. or identifying the missing fundamental frequency in a signal implied by its harmonic frequencies. such as time domain signals. . 𝒓𝒙𝒙 [ 𝒍 ] = ∑∞ ∞ 𝒏=−∞ 𝐱[𝒏]𝒙[ 𝒏 − 𝒍 ] = ∑𝒏=−∞ 𝐱[𝒏 + 𝒍] 𝒙[𝒏] … (5. 3.1 is identical to convolution except for the time folding. (ii) The auto correlation results in a symmetric sequence i.3) Auto correlation finds application in digital communication. 𝒓𝒙𝒙 [𝒍] = 𝒓𝒙𝒙 [ −𝒍 ] … (5. 5. it is the similarity between observations as a function of the time separation between them. 4 } rxx[ 0] => 1 2 3 4 rxx[ 1] => 1 2 3 4 1 2 3 4 1 2 3 4 _________________________ _______________________ 1 + 4 + 9 + 16 = 30 2 + 6 + 12 =20 ________________________ ______________________ K. Example: x[n] = { 1. such as the presence of a periodic signal which has been buried under noise. Sullia D. The operation defined by eqn. However in correlation except for the folding he rest of the three operations are carried out. e. THEORY:The autocorrelation of a sequence x[n] is given by.2) Where 𝑬𝒙 denotes the energy of the signal x[n]. Informally. K.G.l) . DSP Lab Manual rxx[ 2] => 1 2 3 4 rxx[ 3] =>1 2 3 4 1 2 3 4 1 2 3 4 ________________________ _______________________ 3 + 8 = 11 4 Page | 26 ___________________________ _______________________ rxx[ -1] => 1 2 3 4 rxx[ -2] => 1 2 3 4 1 2 3 4 1 2 3 4 __________________________ ________________________ 2 + 6 + 12 = 20 3 + 8 = 11 rxx[ -3] => 1 2 3 4 1 2 3 4 _________________________ 4 _________________________ ALGORIHM: Autocorrelation Begin Read xn Compute length of xn rxx = ∑ xn x (n.m clc clear all close all x = input(' Enter the samples of the sequence x[n] = ' ).V. Sullia D. rxx End PROGRAM:Auto_Corr. . xn E = rxx(0) displayxn. ∀𝑙 Ex= ∑xn.K. % Compute Auto-Correlation rxx = xcorr( x ). College of Engineering. 1.K. rxx.1. disp(' The Energy of the Signal ' ) disp( Ex ). L = length( l ).0000 30. Sullia D.^ 2 ). DSP Lab Manual disp(' The Autocorrelation Sequence rxx[ l ] = ' ) disp(rxx ) N = length( x ).T. nx = N . 'r'. 4 ] The Autocorrelation Sequence rxx[ l ] = 4. Page | 27 l = -nx : 1 : nx. 3.G. lx = L .1. 'filled' ) xlabel(' n-.0000 4.V. 2. 2 ) stem( 0 : lx. 1 ) stem ( 0 : nx .0000 14. figure( 1 ) subplot ( 2. College of Engineering. 1.> ' ) ylabel(' x[n] ' ) title ( ' Input D. 'filled' ) xlabel(' l --> ' ) ylabel(' rxx[l] ' ) title(' Autocorrelation Sequence ' ) % Autocorrelation using Convolution Function rxx_c = conv( x.0000 17.0000 17. Sequeence x[n] ' ). . 'r'. x .0000 The Autocorrelation computed using Convolution 4 14 17 30 17 14 4 The Energy of the Signal 30 The Energy of the Signal from autocorrelation 30 >> K. disp(' The Autocorrelation computed using Convolution ' ) disp(rxx_c ) disp(' The Autocorrelation computed using Convolution ' ) disp(rxx_c ) % Autocorrelation with Zero Lag Quantifies Energy in x[n] Ex = sum( x . fliplr( x ) ). disp(' The Energy of the Signal from autocorrelation' ) disp( rxx( round( L/2 ) ) ) AFTER THE EXECUTION: >> Enter the samples of the sequence x[n] = [ 1.0000 14. subplot( 2. 𝒓𝒙𝒚 [ 𝒍 ] = ∑∞ 𝒏=−∞ 𝐱[𝒏]𝒚[ 𝒏 − 𝒍 ] … (6. The objective in computing the correlation between two different signals is to measure the degree to which the signals are similar and thus to extract some useful information. College of Engineering.1) ∞ 𝒓𝒚𝒙 [ 𝒍 ] = ∑𝒏=−∞ 𝒚[𝒏] 𝐱[ 𝒏 − 𝒍 ]… (6.K. . finite energy. THEORY:Correlation is a mathematical operation that closely resemble convolution. The cross-correlation of two real-valued. sequences x[n] and y[n] is given by. Properties of cross-correlation: 𝒊) 𝒓𝒙𝒚 [ 𝒍 ] ≤ √𝐄𝐱 𝐄𝒚 … (6. … Where the integer parameter l is called the lag indicator.2) 𝒍 = 𝟎.V. DSP Lab Manual Page | 28 Fig 5.1 Screenshot of output of the Auto_Corr.m program EXPT No: 3 b) DATE: CROSS CORRELATION OF TWO GIVEN SEQUENCES AND VERIFICATION OF ITS PROPERTIES AIM: To execute an m-file program to find the cross-correlation of two given sequences and to verify its properties. ±𝟐. Sullia D.3) K. ±𝟏.G. ∀𝑙 ryx = ∑ ynx (n. SONAR and so on. DSP Lab Manual 𝒊𝒊) 𝒓𝒙𝒚 [𝒍] = 𝒓𝒚𝒙 [ −𝒍 ] … (6.G.m clc clear all close all x = input(' Enter the samples of the sequence x[n] = ' ).l) . yn Compute length of xn . K.rxy. The application of correlation finds in RADAR. Solution: ALGORIHM: Cross-correlation Begin Read xn. Page | 29 EXAMPLE: Compute the cross correlation of the two sequences:x[n] = { 1.4) Where Ex and Ey are energies of the signals x[n] and y[n] respectively.l) . x ). 4 } and y[n] = { 1. rxy = xcorr( x. yn rxy = ∑ xn y (n. 2. 4. y = input(' Enter the samples of the sequence y[n] = ' ). 3. College of Engineering. 3 }. y ).K.V. . Sullia D. ryx = xcorr( y. ∀𝑙 displayxn. 2. ryx End PROGRAM:Cross_Corr.yn. 1. 2 ) stem ( y. 2 ) stem ( ryx. 3 ] The Cross-Correlation between x[n] and y[n] 3. Sullia D. 1. 3.0000 3.G.0000 20.0000 23. DSP Lab Manual % Verify the failure of commutative property with rxy and ryx % disp(' The Cross-Correlation between x[n] and y[n] ' ) disp(rxy ) disp(' The Cross-Correlation between y[n] and x[n] ' ) Page | 30 disp(ryx ) figure( 1 ) subplot( 2. College of Engineering. 'filled' ) xlabel(' l--> ' ) ylabel(' ryx[ l ] ' ) title(' The Cross-Correlation Sequence ryx[ l ] ' ) AFTER THE EXECUTION: >> Enter the samples of the sequence x[n] = [ 1. 'filled') xlabel(' n--> ' ) ylabel(' y[ n ] ' ) title(' Second Sequence y[n] ' ) figure(2 ) subplot( 2. .0000 13. 'filled') xlabel(' l--> ' ) ylabel(' rxy[ l ] ' ) title(' The Cross-Correlation Sequence rxy[ l ] ' ) subplot( 2.0000 4. 'filled') xlabel(' n--> ' ) ylabel(' x[ n ] ' ) title(' First Sequence x[n] ' ) subplot( 2. 1. 1 ) stem ( x.0000 27. 1 ) stem ( rxy.0000 10. 4 ] Enter the samples of the sequence y[n] = [ 1.0000 23. 4.0000 27.0000 >> K.K. 1.0000 20. 2.0000 13.0000 The Cross-Correlation between y[n] and x[n] 4.V.0000 10. 2. V. College of Engineering.K.G. DSP Lab Manual Page | 31 Fig 6.1 Screenshot of the output of Cross_Corr.m program K. . Sullia D. Equation (7. .G.1 models a recursive IIR system. 𝒓𝟏 𝒓𝒏 𝑯𝒛 = 𝒌𝟏 + 𝒌𝟏 𝒛−𝟏 + ⋯ + −𝟏 + ⋯+ 𝟏 − 𝒑𝟏 𝒛 𝟏 − 𝒑𝒏 𝒛−𝟏 hn= IZT{ Hz} define input signal to be unit step input xn = un solv𝑒 𝑦𝑛 = − ∑𝑵−𝟏 𝑴−𝟏 𝒌=𝟏 𝒂𝒌 𝒚𝒏−𝒌 + ∑𝒌=𝟎 𝒃𝒌 𝒙𝒏−𝒌 displayr. EXAMPLE: ALGORIHM: LINEAR DIFFERENCE EQUATION WITHOUT INITIAL CONDITIONS(INITIALLY RELAXED SYSTEM) Begin Read ak. then 𝐲[𝒏] = ∑𝑴−𝟏 −𝒌 𝒌=𝟎 𝒃𝒌 𝒛 … (7. Sullia D.2) Rearranging eqn(7.p.K. 𝒌 andhnfromrational H(z) using partial fraction expansion. & 𝑖𝑓 𝒂𝟎 =1.4) is identical to convolution summation with {bk} being the filter coefficients of a Finite Impulse Response (FIR) Filter.1) governs a recursive or Infinite Impulse Response(IIR) filter. College of Engineering.1) Applying z-transform to eqn.3) 𝑿(𝒛) 𝟏+∑𝑵−𝟏 𝒌=𝟏 𝒂𝒌 𝒛 −𝒌 H(z) is called transfer function of the system. 𝒑.k.V.4) Equation(7. THEORY:Thegeneral form linear constant coefficient difference equation is given by: 𝐲[𝒏] = − ∑𝑵−𝟏 𝑴−𝟏 𝒌=𝟏 𝒂𝒌 𝒚[ 𝒏 − 𝒌] + ∑𝒌=𝟎 𝒃𝒌 𝒙[ 𝒏 − 𝒌] … (7. Linear Constant Coefficient Difference Equations(LCCDEs) model LTI systems.1) 𝐘[𝒛] = − ∑𝑵−𝟏 𝒌=𝟏 𝒂𝒌 𝒀[ 𝒛]𝒛 −𝒌 + ∑𝑴−𝟏 𝒌=𝟎 𝒃𝒌 𝑿[𝒛]𝒛 −𝒌 … (7. Equation 7. If 𝒂𝒌 ≡ 𝟎 ∀𝒌 except for 𝒂𝟎 . (7.2) 𝒀(𝒛) ∑𝑴−𝟏 𝒌=𝟎 𝒃𝒌 𝒛 −𝒌 𝐇[𝒛] = = (7. h. yn End K. bk Compute 𝒓. DSP Lab Manual EXPT No: 4 DATE: LINEAR DIFFERENCE EQUATION Page | 32 AIM: To execute an m-file program to find the solution of a given difference equation(i) without initial conditions and (ii) with initial conditions. p. a. y ) xlabel(' n--> ' ) ylabel(' y[n] ' ) title(' Response of the System ' ) K. h ) xlabel(' n--> ' ) ylabel(' h[n] ' ) title(' Impulse Response of the System ' ) % Exciting the System with Unit Step Signal x = ones( 1. . x ). a = input(' Enter the Denomenator Coefficients = ' ). y = filter( b. disp( y1 ) subplot( 2. 1. [ r.K. 1. % Impulse Response of the System disp(' Impulse Response of the System h[n] = ' ) disp( h' ) disp(' ' ) figure( 1 ) subplot( 2. x ).m % With ZERO initial conditions OR system initially relaxed. 1 ) stem( n. 1. n ] = impz( b. disp(' The Response of the System y[n] for Step input =' ) disp( y ) disp(' ' ) % Alternatively disp(' Alternatively the Response of the System y[n] for Step input =' ) y1 = filter( h. a ).G. DSP Lab Manual PROGRAM: LCCDE1. Sullia D. k ] = residuez( b.1. 12 ).V. College of Engineering. a ). disp(' Residues = ' ) disp( r ) disp(' Poles = ' ) disp( p ) disp(' Constants = ' ) disp( k ) disp(' ' ) [ h. Page | 33 clc clear all close all b = input(' Enter the Numerator Coefficients = ' ). 2 ) stem( 0:length( y ) . 9213 0.V.9166 0.0000 -0.9156 0.0018 0.1250 + 0.9174 0.9167 0.9028 0.9028 0.0039 -0.0000 The Response of the System y[n] for Step input = Columns 1 through 7 1. Sullia D.0001 -0.9167 Alternatively the Response of the System y[n] for Step input = Columns 1 through 7 1. .0000 0.9167 0. 1/8 ] Enter the Denomenator Coefficients = [ 1.0139 0.9213 0.0.0001 0.9169 Columns 8 through 12 0.7500 Impulse Response of the System h[n] = Columns 1 through 7 1.0002 0. 1/4.G.0559i Poles = -0.0559i 0.9169 Columns 8 through 12 0.9167 K. 1/6 ] Residues = 0.9167 0.0185 -0.9167 0.3727i -0.1250 .9167 0.0012 Columns 8 through 11 -0.9168 0. College of Engineering.9156 0. DSP Lab Manual AFTER THE EXECUTION: >> Page | 34 Enter the Numerator Coefficients = [ 1.9168 0. 1/3.0.0833 -0.9174 0.1667 + 0.9166 0.K.0000 0.9167 0.1667 .3727i Constants = 0. yn End PROGRAM: LCCDE2. Sullia D. a = input(' Enter the Denomenator Constant Coefficients = ' ).1 Screenshot of output of the LCCDE1. . ic = input( ' Enter the initial conditions y[-1].K. K.m program ALGORIHM: LINEAR DIFFERENCE EQUATIONWITH INITIAL CONDITIONS Begin Read ak. bk Compute hn= IZT{ Hz} define input signal to be unit step input xn = un solve 𝐲𝐧 = − ∑𝑵−𝟏 𝑴−𝟏 𝒌=𝟏 𝒂𝒌 𝒚𝒏−𝒌 + ∑𝒌=𝟎 𝒃𝒌 𝒙𝒏−𝒌 for yzi and yzs 𝐲𝐧 = yzi+yzs display h.V.G. y[-2] : ' ).m clc clear all close all b = input(' Enter the Numerator Constant Coefficients = ' ). DSP Lab Manual Page | 35 Fig 7. College of Engineering. V. 12 ). 1 ) stem( n. ny = 0:N . DSP Lab Manual % Impulse Response [ h n ] = impz( b. 2 ) stem(ny. y ) xlabel(' n--> ' ) ylabel(' y[n] ' ) title(' Response of the System ' ) AFTER THE EXECUTION: >> Enter the Numerator Constant Coefficients = [ 1.0001 0.0833 0. College of Engineering.0013 0.0156 0. ic ). disp(' Impulse Response ' ) disp( h' ) Page | 36 % Unit Step Signal as Input x = ones( 1. h ) xlabel(' n--> ' ) ylabel(' h[n] ' ) title(' Impulse Responnse ' ) N = length( y ). Sullia D. a. 1. 1/3. . subplot( 2. 1. % Zero Input Response zi = filtic( b. 1/8 ] Enter the initial conditions y[-1].K. 1/6 ] Enter the Denomenator Constant Coefficients = [ 1. % Total Response = Zero Input Response + Zero State Response y = filter( b. a. a ). y[-2] : [ 1. 0 ] Impulse Response Columns 1 through 7 1.0016 -0. 1/4.0001 K.0208 -0.1. x. zi ).0006 Columns 8 through 9 -0. disp(' Response of the System for Step Signal ' ) disp( y ) figure( 1 ) subplot( 2.G.0000 0. K. Sullia D.G.0906 1.0208 1.m program K.0846 1.0910 1.7500 1.0911 Page | 37 Columns 8 through 10 1. . College of Engineering.0909 >> Fig 7.0850 1.2 Screenshot of output of the LCCDE2. DSP Lab Manual Response of the System for Step Signal Columns 1 through 7 0.1510 1.0932 1.V.
Copyright © 2024 DOKUMEN.SITE Inc.