SLIDE 10 st = sprintf(’Window:%d s Filter Order:%d Estimator:%s Window:%s’,wl,fo,estimatorType,windowType); title(st); FigureSet(1,’Slides’); AxisSet(8); fn = sprintf(’ChirpARO%02dL%03dE%1dW%1d’,fo,wl,et,wt); print(fn,’-depsc’); fprintf(fid,’%%==============================================================================\n’); fprintf(fid,’\\newslide\n’); fprintf(fid,’\\slideheading{Example \\arabic{exc}: Autoregressive PSD}\n’); fprintf(fid,’%%==============================================================================\n’); fprintf(fid,’\\hspace{-1.5em} \\includegraphics[scale=1]{Matlab/%s}\n\n’,fn); end; end; fclose(fid);
Portland State University ECE 539/639 Autoregressive Models
39
Example 1: MATLAB Code
clear; close all; %==================================================================== % User-Specified Parameters %==================================================================== fs = 1; % Sample rate (Hz) N = 1000; % Number of observations from the process Np = 500; % Number of samples to throw away to account for transient k1 = 1:N/4; t1 = (k1-0.5)/fs; yc = chirp(t1,0.05,t1(end),0.45); y = [yc fliplr(yc) yc fliplr(yc)]’; %==================================================================== % ParametricSpectrograms %==================================================================== fid = fopen(’ARChirp.tex’,’w’); if fid==-1, error(’Could not open ARChirp.tex file for writing’); end; fo = [2 10]; wl = [50 100 200]; for c0=1:fo, for c1=1:length(wl), AutoregressiveSpectrogram(y,fs,wl(c1),fo(c0),0,0); colormap(ColorSpiral(256)); title(sprintf(’Autoregressive Spectrogram Window:%d s Filter Order:%d’,wl(c1),fo(c0))); FigureSet(1,’Slides’); AxisSet(8); fn = sprintf(’ChirpARO%02dL%03d’,fo(c0),wl(c1));
Portland State University ECE 539/639 Autoregressive Models
37
Example 1: MATLAB Code
function [S,t,f] = AutoregressiveSpectrogram(x,fsa,wla,foa,eta,wta,fra,nfa,nsa,pfa); %AutoregressiveSpectrogram: Generates the spectrogram of the signal % % [S,t,f] = AutoregressiveSpectrogram(x,fs,wl,fo,et,wt,fr,nf,ns,pf); % % x Input signal. % fs Sample rate (Hz). Default = 1 Hz. % wl Length of window to use (sec). Default = 1024 samples. % If a vector, specifies entire window. % fo Model order. Default = 30. % et Estimator type: 0=Unbiased/no window, % 1=Modified covariance (default). % wt Window type: 0=Rectangular, 1=Blackman (default). % fr Minimum and maximum frequencies to display (Hz). % Default = [0 fs/2]. % nf Number of frequencies to evaluate (vertical resolution). % Default = max(128,round(wl/2)). % ns Requested number of times (horizontal pixels) to evaluate % Default = min(400,length(x)). % pf Plot flag: 0=none (default), 1=screen. % % S Matrix containing the image of the Spectrogram. % t Times at which the spectrogram was evaluated (s). % f Frequencies at which the spectrogram was evaluated (Hz). % % Calculates estimates of the spectral content at the specified % times using an autoregressive model. The mean of the signal is % removed as a preprocessing step. The square root of the power % spectral density is calculated and displayed. To limit % computation, decimate the signal if necessary to make the upper % frequency range approximately equal to half the sampling % frequency. % % If only the window length is specified, the blackman window is
Portland State University ECE 539/639 Autoregressive Models
40
print(fn,’-depsc’); fprintf(fid,’%%==============================================================================\n’); fprintf(fid,’\\newslide\n’); fprintf(fid,’\\slideheading{Example \\arabic{exc}: Autoregressive PSD}\n’); fprintf(fid,’%%==============================================================================\n’); fprintf(fid,’\\hspace{-1.5em} \\includegraphics[scale=1]{Matlab/%s}\n\n’,fn); if c0==1, NonparametricSpectrogram(y,fs,wl(c1)); colormap(ColorSpiral(256)); title(sprintf(’Nonparametric Spectrogram Window:%d s’,wl(c1))); FigureSet(2,’Slides’); AxisSet(8); fn = sprintf(’ChirpNPO%02dL%03d’,fo(c0),wl(c1)); print(fn,’-depsc’); fprintf(fid,’%%==============================================================================\n’); fprintf(fid,’\\newslide\n’); fprintf(fid,’\\slideheading{Example \\arabic{exc}: Nonparametric PSD}\n’); fprintf(fid,’%%==============================================================================\n’); fprintf(fid,’\\hspace{-1.5em} \\includegraphics[scale=1]{Matlab/%s}\n\n’,fn); end; end; end; fo = 5; wl = 50; for c1=0:1, for c2=0:1, et = c1; wt = c2; AutoregressiveSpectrogram(y,fs,wl,fo,et,wt); colormap(ColorSpiral(256)); if et==0, estimatorType = ’Unbiased/no window’; else estimatorType = ’Modified Covariance’; end; if wt==0, windowType = ’Rectangular’; else windowType = ’Blackman’; end;
Portland State University ECE 539/639 Autoregressive Models
38