📄 adaptnlmsdemo.m
字号:
%% Linear Prediction Using the NLMS Adaptive Filter% This demo casts the normalized least mean squares adaptive filter in a linear% prediction framework. The current sample of a noise corrupted sine wave is% predicted using 32 past samples, i.e., a 32nd order normalized LMS adaptive% filter is applied to the data.%% Note: This demo is equivalent to the Simulink model 'lmsadlp' provided in the% Signal Processing Blockset.% Reference: S. Haykin, "Adaptive Filter Theory", 3rd Edition, Prentice Hall,% N.J., 1996.% Copyright 1999-2005 The MathWorks, Inc. % $Revision: 1.6.4.7 $ $Date: 2005/11/02 03:18:55 $%%% The desired signal is a sine wave of 0.015 cycles/sample and a cosine of 0.008% cycles/sample.N = 500;sig = [sin(2*pi*0.015*(0:N-1)) 0.5*cos(2*pi*0.008*(0:N-1))];plot(0:2*N-1,sig); grid;title('Desired Input to the Adaptive Filter');%%% The input to the adaptive filter is a delayed version of the desired signal% corrupted by white noise of variance 0.5.nvar = 0.5; % Noise variancenoise = nvar*randn(1,2*N); % Noisen = sig + noise; % The noise corrupted sine wave.x = [0 n]; % Delayed input for linear predictiond = [sig 0]; % Desired signal to the adaptive filterM = 32; % NLMS adaptive filter ordermu = 0.2; % Normalized LMS step size.plot(0:2*N,x); grid;title('Input to the Adaptive Filter');%%% Create and use the Normalized LMS adaptive filter object% of length M, step size 0.2 and offset 1e-6Hadapt = adaptfilt.nlms(M,mu,1,1e-6);[y,e] = filter(Hadapt,x,d);cla;plot(0:1000,[d' y']);grid on;axis([0 1000 -2 2]);title('Adaptive Linear Prediction');legend('Actual Signal','Predicted Signal');%%% The autocorrelation of the prediction error shows that the input is white% noise.X = xcorr(e(50:end),'coeff');[maxX idx] = max(X);plot(X(idx:end));grid;title('Autocorrelation of the Prediction Error');displayEndOfDemoMessage(mfilename)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -