ELE_651_Hwk3_solutions_final_rev_Sp24

pdf

School

Northern Illinois University *

*We aren’t endorsed by this school

Course

651

Subject

Electrical Engineering

Date

Apr 3, 2024

Type

pdf

Pages

19

Uploaded by ConstableRock13662

Report
ELE 651 HWK 3 Mansour Tahernezhadi <mtaherne@niu.edu> Wed 1/31/2024 3:27 PM To:Mansour Tahernezhadi < mtaherne@niu.edu> Cc:Courtney Bradley <Z1635378@students.niu.edu> @ 1 attachments (45 KB) speech1_640.xlsx; Dear All, Below please find HWK 3 due by next Tuesday noon. Thanks! Dr. T. ************************************************* a) Given your computed autocorrelation from previous homework of r(O), r(l) and r(2) for each frame, determine the linear prediction coefficients (LPC) al and a2 for each frame. Plot al and a2 for each frame. b) Given the attached xis file (speech1_640.xlsx) containing 640 speech samples obtained at 8000 samples/sec (8000 Hz sampling frequency) compute and plot the autocorrelation for k=0,1, .. ,10 for frames of size of 160 and observe its evolution. c) Find the power spectrum of each frame at 1/ 256 resolution, find dominant frequencies for each frame for both index and actual frequencies. Also, observe the power spectrum's slowly evolving nature from one frame to another. d) Find the LPC al, a2, ... , alO for each frame and observe their evolution from one frame to another frame by plotting them e) Given a 4xl vector A=[-0.5 0.3 0.2 OS] find the projection of A along 16 xl cosine wave and since wave vectors at 3 / 16 frequency each using 16-point FFT.
Contents (a) Given your computed autocorrelation from previous homework of r(O), r(1) and r(2) for each frame, determine the linear prediction coefficients (LPC) a1 and a2 for each frame. Plot a1 and a2 for each data for part (a) Find rx(O) through rx(2) for each frame use formula from notes to calculate [a) vector: R"-1 *r = a plot [a1 a2]' for each frame clc close all clear all % Navistar ELE 651 Spring 2024 % HOMEWORK 3 part A Solutions % By Courtney Bradley % Note: This is Matlab code. However any coding software can be used. There are multiple ways to code this to get the same answer. % There is no wrong or right way however some methods may take more memory which % will matter once we start dealing with larger data sets. (a) Given your computed autocorrelation from previous homework of r(O), r(1) and r(2) for each frame, determine the linear prediction coefficients (LPC) a1 and a2 for each frame. Plot a1 and a2 for each %frame. data for part (a) filename = 'HWK 2_data' ; xlRangel = 'A2:All' ; x1Range2 = 'A12:A21' ; x1Range3 = 'A22:A31' ; xnl=xlsread(filename,xlRangel); xn2=xlsread(filename,x1Range2); xn3=xlsread(filename,x1Range3); disp( 'Framel' ); disp(xnl); disp( 'Frame2' ); disp(xn2); disp( 'Frame3' ); disp(xn3); Framel -0.0540 0.0290 -0.0840 0.0840 -0.0620 0.1340 -0.0010 -0.0270 -0.0120 0.0850 Frame2 0.3000 -0.0700 %retreives first 10 cells of xn data stored in an excel spreadsheet
-0.2800 -0.1570 0.4300 0.1900 -0.4500 -0.2800 0.4400 0.3100 Frame3 0.6200 -0.1600 -0.4900 -0.0050 0.4700 -0.1700 -0.5400 0.2300 0.4100 -0.3300 %Part (a) Find rx(O) through rx(2) for each frame k=2; N=length(xnl); %frame 1 autocorelation for k=0-2 x=xnl; autcor=auto(x,k,N); autocor3_xnl=autcor; disp( 'Framel r0- r2' ); disp(autocor3_xnl); %frame 2 autocorelation for k=0-2 X=Xn2; autcor=auto(x,k,N); autocor3_xn2=autcor; disp( 'Frame2 r0- r2' ); disp(autocor3_xn2); %frame 3 autocorelation for k=0-2 X=Xn3; autcor=auto(x,k,N); autocor3_xn3=autcor; disp( 'Frame3 r0- r2' ); disp(autocor3_xn3); Framel r0- r2 0.0048 -0.0025 0.0018 Frame2 r0- r2 0.0990 0.0110 -0.0755 Frame3 r0- r2 0.1521 -0.0174 -0.1123
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
use formula from notes to calculate [a] vector: R A -1*r=a %FRAME 1 r0_rl_xnl=autocor3_xnl(l:2); % the first colomn of the R matrix [r(0) r(l)] R_xnl= toeplitz(r0_rl_xnl); %creates the R 2x2 matrix from the first column r_xnl=autocor3_xn1(2:3); %r vector a_xnl=inv(R_xnl)*r_xnl; % [a] disp( 'The 2xl [a] vector frame 1' ); disp(a_xnl); %FRAME 2 r0_rl_xn2=autocor3_xn2(1:2); R_xn2= toeplitz(r0_rl_xn2); r_xn2=autocor3_xn2(2:3); a_xn2=inv(R_xn2)*r_xn2; %[a] disp( 'The 2xl [a] vector of frame 2' ); disp(a_xn2); %FRAME 3 r0_rl_xn3=autocor3_xn3(1:2); R_xn3= toeplitz(r0_rl_xn3); r_xn3=autocor3_xn3(2:3); a_xn3=inv(R_xn3)*r_xn3; %[a] disp( 'The 2xl [a] vector frame 3' ); disp(a_xn3); The 2xl [a] vector frame 1 -0.4675 0.1200 The 2xl [a] vector of frame 2 0.1992 -0.7849 The 2xl [a] vector frame 3 -0.2014 -0.7609 plot [a1 a2]' for each frame t=(l:1:2); figure (1) plot(t,a_xnl, "LineWidth" ,2); hold on plot (t,a_xn2, "LineWidth" ,2); hold on plot (t,a_xn3, "LineWidth" ,2); title( "[al a2] for frame 1-3 " ) xlabel( 'n' ) ylabel (' a[n] ' ) legend( 'Frame 1' , 'Frame 2' , 'Frame3' ) hold off %frame 1 %frame 2 %frame 3
0 . 1 0 -0 . 1 -0.2 -0.4 -0.5 �o.6 -0.7 [a1 a2] for frame 1-3 - F rame 1 - Fr am e2 -0.8 �-�--�-�--�-�--�--�-�--�-� , . 1 1..2 1 . 3 1.4 Published with MATLAB® R2022b 1 . 5 n 1.6 1.7 1 . 8 1.9 2
Contents data for part B-D _First calculate the rx(k) for each frame, k=0-10 (b) plot the auto correlation rO through r10 for each frame (c) Using the 256 FFT, plot the power spectrum for each frame across actual _Px(f) ploted across normalized frequency -0.5 to 0.5 (d) use formula from notes to calculate [a] vector plot [a1 ...a10] for each frame (e) You are given the 4x1 vector [a]=(-0.5 0.3 0.2 0.5]. Find [a] along C1 and S1 @ freq=3/16 Vector a along cosine & vector a along sine real part of the fft Plot your results (recommended but optional) (e) 16-point FFT method clc close all clear all %ELE 651 HWK 3 % Navistar ELE 651 Spring 2024 % HOMEWORK 3 part B-E Solutions % By Courtney Bradley % Note: This is Matlab code. However any coding software can be used. There are multiple ways to code this to get the same answer. % There is no wrong or right way however some methods may take more memory which % will matter once we start dealing with larger data sets. data for part B-D filename xlRangel x1Range2 x1Range3 'speech1_640' ; 'Al :A160' ; 'A161:A320' ; 'A321:A480' ; x1Range4 = 'A481:A640' ; sheet = 'Sheetl' ; % Sheet containing the data of interest xnl=xlsread(filename,sheet,xlRangel); %retreives first 160 cells of xn data stored in an excel spreadsheet xn2=xlsread(filename,sheet,x1Range2); xn3=xlsread(filename,sheet,x1Range3); xn4=xlsread(filename,sheet,x1Range4); N=length(xnl); _First calculate the rx(k) for each frame, k=0-10 k=10; %k=0-10 %frame 1 autocorelation for k=0-10 x=xnl; auto_corr_0_10_framel=auto(x,k,N); disp( 'frame 1 r0-r10' ); disp(auto_corr_0_10_framel); %frame 2 autocorelation for k=0-10 X=Xn2j auto_corr_0_10_frame2=auto(x,k,N); disp( 'frame 2 r0-r10' ); disp(auto_corr_0_10_frame2);
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
%frame 3 autocorelation for k=0-10 x=xn3; auto_corr_0_10_frame3=auto(x,k,N); disp( 'frame 3 r0-r10' ); disp(auto_corr_0_10_frame3); %frame 4 autocorelation for k=0-10 x=xn4; auto_corr_0_10_frame4=auto(x,k,N); disp( 'frame 4 r0-r10' ); disp(auto_corr_0_10_frame4); frame 1 r0-r10 0.0127 0.0115 0.0086 0.0046 0.0002 -0.0039 -0.0070 -0.0087 -0.0088 -0.0073 -0.0046 frame 2 r0-r10 0.0120 0.0109 0.0082 0.0044 0.0002 -0.0036 -0.0064 -0.0080 -0.0081 -0.0070 -0.0048 frame 3 r0-r10 0.0151 0.0138 0.0103 0.0054 -0.0000 -0.0050 -0.0087 -0.0107 -0.0108 -0.0092 -0.0060 frame 4 r0-r10 0.0134 0.0122 0.0090 0.0047 -0.0000 -0.0042 -0.0073 -0.0091 -0.0094 -0.0083 -0.0059
(b) plot the auto correlation rO through r10 for each frame %you can put them all on of graph % you will have 4 curves (one for each frame) y_xnl=auto_corr_0_10_frame1; y_xn2=auto_corr_0_10_frame2; y_xn3=auto_corr_0_10_frame3; y_xn4=auto_corr_0_10_frame4; t=(0:1:10); % x-axis values figure (2) plot(t,y_xnl, "LineWidth" ,2); hold on plot (t,y_xn2, "LineWidth" ,2); hold on plot (t,y_xn3, "LineWidth" ,2); hold on % llxl vector containing % llxl vector containing % llxl vector containing % llxl vector containing for autocorrelation plot %frame 1 graph %frame 2 graph %frame 3 graph plot (t,y_xn4, "LineWidth" ,2); %frame 4 graph title( "Frame 1,2,3 & 4 Auto Correlation " ) xlabel (' k' ) ylabel( 'Auto Correlation ' ) legend( 'Frame 1' , 'Frame 2' , 'Frame3' , 'Frame 4' ) hold off rx(0) to rx(10) rx(0) to rx(10) rx(0) to rx(10) rx(0) to rx(10) Frame 1,2,3 & 4 Auto Correlation 0.02 0.015 0.01 0 0.005 0 0 - 0 . 00 5 -0.01 -0 . 015 0 2 3 4 5 k 6 7 - F ra me 1 - F r a me2 Frame3 - F rame 4 8 9 10 (c) Using the 256 FFT, plot the power spectrum for each frame across actual frequency (sampling frequency is 8000 Hz) and observe its evolution from frame to frame. to observe you need to plot it % use the rx(0-10) calculated in part b % creates the 21x1 vector rx(k) for Frame 1 B=auto_corr_0_10_frame1; B(l)=[]; %removes the first element b=flip(B); autocorr_symmetrical_fl=[b;auto_corr_0_10_frame1]; %combines the vectors to create a symetrical rx(k) % creates the 21x1 vector rx(k) for Frame 2 B=auto_corr_0_10_frame2; B(l)=[]; %removes the first element b=flip(B); autocorr_symmetrical_f2=[b;auto_corr_0_10_frame2]; %combines the vectors to create a symetrical rx(k)
% creates the 21xl vector rx(k) for Frame 3 B=auto_corr_0_10_frame3; B(l)=[]; %removes the first element b=flip(B); autocorr_symmetrical_f3=[b;auto_corr_0_10_frame3]; %combines the vectors to create a symetrical rx(k) % creates the 21xl vector rx(k) for Frame 4 B=auto_corr_0_10_frame4; B(l)=[]; %removes the first element b=flip(B); autocorr_symmetrical_f4=[b;auto_corr_0_10_frame4]; %combines the vectors to create a symetrical rx(k) %Compute the fourier transform for each frame N=256; % The resolution fft_xnl=abs(fft(autocorr_symmetrical_fl,N)); % fft frame 1 fft_xn2=abs(fft(autocorr_symmetrical_f2,N)); % fft frame 2 fft_xn3=abs(fft(autocorr_symmetrical_f3,N)); % fft frame 3 fft_xn4=abs(fft(autocorr_symmetrical_f4,N)); % fft frame 4 _Px(f) ploted across normalized frequency -0.5 to 0.5 f_start = -N/2; f_End = N/2-1; I = 1/N; freq=[f_start:1:f_End]/N; %x-axis % you can avoid using fft shift by plotting only the possitive end of the % frequency spectum 0:N/2 figure (3) plot(freq, fftshift(fft_xnl), "LineWidth" ,2); hold on plot(freq, fftshift(fft_xn2), "LineWidth" ,2); hold on plot(freq, fftshift(fft_xn3), "LineWidth" ,2); hold on plot(freq, fftshift(fft_xn4), "LineWidth" ,2); title( "px(f) frame 1,2,3,& 4" ) xlabel( 'f (normalized)' ) ylabel( 'Jfft(auto)I ' ) legend( 'Frame 1' , 'Frame 2' , 'Frame3' , 'Frame 4' ) hold off %frame 1 power spectrum %frame 2 power spectrum %frame 3 power spectrum %frame 4 power spectrum
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
0.15 p x ( f ) frame 1,2,3,& 4 - F rame1 X 0 . 0625 - F rame2 Y 0 . 142 1 49 Frame3 - Fra m e 4 0.1 l X 0.0625 Y 0 . 1 096 1 5 0.05 0 IV��'.:3!� [.____] l.---.! ![___J ,__ _ -LJL- _ ---!...- .!".--1- _¥._ ����� -0.5 0 0.5 f (normalized)
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
legend( 'Frame 1' , 'Frame 2' , 'Frame3' , 'Frame 4' ) hold off fra m e 1,2,3,& 4 a values 2 . 5 2 1.5 1 0.5 -0.5 -1 -1.5 -2 2 3 4 5 6 7 n - F rame 1 - F r a me2 Frarne3 - F rarn e4 B 9 10 (e) You are given the 4x1 vector [a]=[-0.5 0.3 0.2 0.5]. Find [a] along C1 and S1 @ freq=3/16 A=[-0.5;0.3;0.2;0.5]; N=16; m = 3; padding = zeros(12,1); A_padded = [A;padding]; %sine and cosine should be plotted vs time not frequency t = (-pi:.39:pi-l/pi); % x axis for the plot % From the information given you can compute Cl and 51 as shown below: Cl= cos(2*pi*(m/N)*[0:N-1]). '; 51= sin(2*pi*(m/N)*[0:N-1]).'; Vector a along cosine & vector a along sine finish the problem by first calculating the unit vectors, then solve %for A along Cl and 51 u_vector_Cl=Cl/norm(Cl); u_vector_51=51/norm(51); A_along_Cl=dot(A_padded,U_vector_Cl)*U_vector_Cl; disp( 'A along Cl:' ); disp(A_along_Cl); A_along_5l=dot(A_padded,U_vector_51)*U_vector_51; disp( 'A along 51: ' ) disp(A_along_51) A along Cl: -0.1236 % [a] along [Cl] % [a] along [51]
-0.0473 0.0874 0.1142 0.0000 -0.1142 -0.0874 0.0473 0.1236 0.0473 -0.0874 -0.1142 -0.0000 0.1142 0.0874 -0.0473 A along S1: 0 0.0262 0.0201 -0.0109 -0.0284 -0.0109 0.0201 0.0262 0.0000 -0.0262 -0.0201 0.0109 0.0284 0.0109 -0.0201 -0.0262 real part of the fft re_fft_A_cl = (2/N)*dot(A_padded,Cl); disp( 'real part of fft cl' ) disp(re_fft_A_cl) re_fft_A_sl = (2/N)*dot(A_padded,S1); disp( 'real part of fft sl' ) disp(re_fft_A_sl) real part of fft cl -0.1236 real part of fft sl 0.0284 Plot your results (recommended but optional) figure(S) plot(t,A_along_Sl, "LineWidth" ,3); hold on plot(t,A_along_Cl, "LineWidth" ,3); title( "vector a along sine & vector a along cosine (@ f=3/16)" ) xlabel( 'time' ) ylabel( 'amplitude' ) legend( 'a along S1' , 'a along Cl' ) hold off
:!= 0 . 1 0.05 0 -.0.05 -0 . 1 vector a along sine & vector a along cosine(@ r-3/16) - a alo n gS 1 , _ a along Cl -0 . 15 �--�---�---�---�---�---�--� -4 -3 -2 real part of the fft re_fft_A_cl = dot(A_padded,Cl); disp( 'real part of fft cl' ) disp(re_fft_A_cl) -1 0 time re_fft_A_sl = -dot(A_padded,S1); %<<---negative sign disp( 'real part of fft sl' ) disp(re_fft_A_sl) real part of fft cl -0.9886 real part of fft sl -0.2272 (e) 16-point FFT method N=16; % The resolution f_start = -N/2; f_End = N/2-1; I = 1/N; freq = (f_start:1:f_End)/N; fft_A=abs(fftshift(fft(A,N))); %<<<---fftshift was applied here figure (6) 2 3 plot(freq, fft_A, "LineWidth" ,3); %%<«----previously had fftshift here but it was already applied above title( "16 point fft spectrum" ) xlabel( 'f (normalized)' ) ylabel( 'jfft(A)j ' ) hold off
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
f (normalized)
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help