SLIDE 9 p = 1; % Number of steps ahead to predict M = 1:100; nM = length(M); NMSE = zeros(nM,1); for c0=1:nM, m = M(c0); % Filter length R = zeros(m,m); for c1=1:m, for c2=1:m, R(c1,c2) = rx(abs(c1-c2)+1); end; end; d = zeros(m,1); for c1=1:m, d(c1) = rx(c1+p); end; co = inv(R)*d; xh = filter(co,1,[zeros(p,1);x]); xh = xh(1:nx); NMSE(c0) = mean((x-xh).^2)/mean(x.^2); end; figure; FigureSet(1,’LTX’); h = plot(M,NMSE,’b’); set(h(1),’LineWidth’,0.8); AxisSet(8); xlabel(’M (samples)’); ylabel(’NMSE’); title(sprintf(’P:%d’,p)); xlim([0.5 M(end)+0.5]); ylim([0 1.05]); box off; print(’RESweepM’,’-depsc’);
Portland State University ECE 539/639 Linear Prediction
35
FigureSet(1,’LTX’); AxisSet(8); print(’REAutocorrelation’,’-depsc’); %================================================ % Plot the Partial Autocorrelation %================================================ PartialAutocorrelation(x,fs,.5); FigureSet(1,’LTX’); AxisSet(8); print(’REPartialAutocorrelation’,’-depsc’); %================================================ % Plot the Power Spectral Density %================================================ BlackmanTukey(x,fs,10); FigureSet(1,’LTX’); AxisSet(8); print(’REBlackmanTukey’,’-depsc’); %================================================ % Plot the Spectrogram %================================================ NonparametricSpectrogram(decimate(x,5),fs/5,2); FigureSet(1,’LTX’); AxisSet(8); print(’RESpectrogram’,’-depsc’); %================================================ % Calculate the Auto- and Cross-Correlation %================================================ rx = Autocorrelation(x,fs,2); m = 25; % Filter length p = 1; % Number of steps ahead to predict R = zeros(m,m);
Portland State University ECE 539/639 Linear Prediction
33
%================================================ % Sweep P for P=1 %================================================ P = 1:300; % Number of steps ahead to predict m = 25; nP = length(P); NMSE = zeros(nP,1); R = zeros(m,m); for c1=1:m, for c2=1:m, R(c1,c2) = rx(abs(c1-c2)+1); end; end; for c0=1:nP, p = P(c0); % Filter length d = zeros(m,1); for c1=1:m, d(c1) = rx(c1+p); end; co = inv(R)*d; xh = filter(co,1,[zeros(p,1);x]); xh = xh(1:nx); NMSE(c0) = mean((x-xh).^2)/mean(x.^2); end; figure; FigureSet(1,’LTX’); h = plot(P/fs,NMSE,’b’); set(h,’LineWidth’,0.8); set(h,’Marker’,’.’); set(h,’MarkerSize’,5); hold on; hb = plot([0 P(end)/fs],[1 1],’r:’); hold off;
Portland State University ECE 539/639 Linear Prediction
36
for c1=1:m, for c2=1:m, R(c1,c2) = rx(abs(c1-c2)+1); end; end; d = zeros(m,1); for c1=1:m, d(c1) = rx(c1+p); end; co = inv(R)*d; xh = filter(co,1,[zeros(p,1);x]); xh = xh(1:nx); NMSE = mean((x-xh).^2)/mean(x.^2); %================================================ % Plot Segment of Signal and Predicted %================================================ figure; FigureSet(1,’LTX’); h = plot(t,x,’r’,t,xh,’g’); set(h(1),’LineWidth’,0.8); set(h(2),’LineWidth’,1.2); AxisSet(8); xlabel(’Time (s)’); ylabel(’Acceleration (scaled)’); title(sprintf(’NMSE:%5.3f P:%d M:%d’,NMSE,p,m)); legend(h,’Signal’,’Predicted’); xlim([t(1) 0.5]); ylim(prctile(x,[0.5 99.5])); box off; print(’RESignalPredicted’,’-depsc’); %================================================ % Sweep M for P=1 %================================================
Portland State University ECE 539/639 Linear Prediction
34