www.gusucode.com > dsp 案例源码程序 matlab代码 > dsp/ExamplePlotChangingFilterWeightsExample.m

    %% Plot Changing Filter Weights  
%%
% *Note*: This example runs only in R2016b or later. If you are using an
% earlier release, replace each call to the function with the equivalent
% |step| syntax. For example, myObject(x) becomes step(myObject,x).

%%
% View Least Mean Squares (LMS) adaptive filter weights on the Array Plot
% figure. Watch the filter weights change as they adapt to filter a noisy
% input signal.   

%% 
% Create an LMS adaptive filter System object. 
hlms = dsp.LMSFilter(40,'Method', 'Normalized LMS', 'StepSize', .002);  

%% 
% Create and configure an audio file reader System object to read the input
% signal from the specified audio file. 
hsigsource = dsp.AudioFileReader('dspafxf_8000.wav',  ...
    'SamplesPerFrame', 40, ...
    'PlayCount', Inf,...
    'OutputDataType', 'double');  

%% 
% Create and configure a fixed-point Finite Impulse Response (FIR) digital
% filter System object to filter random white noise, creating colored noise. 
hfilt = dsp.FIRFilter('Numerator', fir1(39, .25));  

%% 
% Create and configure an Array Plot System object to display the adaptive
% filter weights. 
harrayplot = dsp.ArrayPlot('XLabel', 'Filter Tap', ...
    'YLabel', 'Filter Weight', ...
    'YLimits', [-.05 .2]');  

%% 
% Plot the LMS filter weights as they adapt to a desired signal. Read from
% the audio file, produce random data, and filter the random data. Update 
% the filter weights and plot the filter weights.
numplays = 0;
while numplays < 3
    [y, eof]    = hsigsource();
    noise       = rand(40,1);
    noisefilt   = hfilt(noise);
    desired     = y + noisefilt;
    [~, ~, wts] = hlms(noise, desired);
    harrayplot(wts); 
    numplays = numplays + eof;
end