⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 e6422exer3.m

📁 these code are about adaptive filter.
💻 M
字号:
%
%  Example 6: Generating a Moving Average (MA) Stochastic Process .... 
%  
%

clear all;

samp = 10000;   % number of samples ...

%coeff  = [0.1 0.2 0.3 0.4 0.5 0.4 0.3 0.2 0.1]*0.4 ;  
coeff = [-0.0031 0.0014 0.0134 0.0022 -0.0521 -0.0376 0.1655 0.4104 0.4104 0.1655 -0.0376 -0.0521 0.0022 0.0134 0.0014 -0.0031];
                                    % FIR filter coefficients

N = length(coeff) ;    % N is the FIR filter length
taps = zeros(1,N) ;

for jj=1:samp
   
  in_seq(jj) = randn(1,1)  ;    % Gaussian white noise ....
  taps(2:N) = taps(1:N-1);
  taps(1) = in_seq(jj) ;

  out_seq(jj) = coeff*taps' ;

end ;

%
% .... Evaluate the Power Spectra of input and output sequences ....
%

[Pin,ff]  = PSD(in_seq,256,1.0,hanning(256),128);
[Pout,ff] = PSD(out_seq,256,1.0,hanning(256),128);

figure(1); plot(ff,Pin,ff,Pout) ; grid ;

xlabel('Normalized Frequency');
ylabel('Power');
legend('input sequence', 'output sequence');

%
% Comment on the Power Spectra. 
%  .... Compare with the Spectrum obtained in Exercise 1. !!!!
%
%  Can you estimate the MA filter transfer function from Pin and Pout ???
%

%
%  Example 7: Generating an Auto-regressive (AR) Stochastic Process .... 
%  
%

samp = 10000;   % number of samples ...
clear taps, coeff ;

coeff  = [-0.2 0.3 0.4 0.1] ;  % AR coefficients
N = length(coeff) ;              % N is the AR model order 
taps = zeros(1,N) ;

for jj=1:samp
   
  in_seq(jj) = randn(1,1)  ;    % Gaussian white noise ....
  
  out_seq(jj) = in_seq(jj) - coeff*taps' ;
  taps(2:N) = taps(1:N-1);
  taps(1) = out_seq(jj) ;

end ;

%
% .... Evaluate the Power Spectra of input and output sequences ....
%

[Pin,ff]  = PSD(in_seq,256,1.0,hanning(256),128);
[Pout,ff] = PSD(out_seq,256,1.0,hanning(256),128);

figure(2); plot(ff,Pin,ff,Pout) ; grid ;

xlabel('Normalized Frequency');
ylabel('Power');
legend('input sequence', 'output sequence');

%
% Comment on the Power Spectra. 
%  .... Compare with the Spectrum obtained in Exercise 2. !!!!
%

%
% Now implement an AR Process Anlayzer ....
%

clear taps, coeff ;
coeff  = [1.0 -0.2 0.3 0.4 0.1] ;  % an FIR filter 
N = length(coeff) ;    % N is the FIR filter length
taps = zeros(1,N) ;

for jj=1:samp
   
  in_seq(jj) = out_seq(jj)  ;    % Gaussian white noise ....
  taps(2:N) = taps(1:N-1);
  taps(1) = in_seq(jj) ;

  out_seq2(jj) = coeff*taps' ;

end ;

%
% .... Evaluate the Power Spectra of input and output sequences ....
%

[Pout2,ff] = PSD(out_seq2,256,1.0,hanning(256),128);

figure(3); plot(ff,Pout,ff,Pout2) ; grid ;

xlabel('Normalized Frequency');
ylabel('Power');
legend('output sequence', 'inverse filtered sequence');

%
%  Comment on the Power Spectrum 2. 
%  AR analyzer performs an inverse filtering  !!!!
%  Note that perfect inverse filtering is done in this example.
%

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -