A list,

Least Mean Squares (LMS) is the most basic adaptive filtering algorithm.

LMS algorithm is a commonly used algorithm in adaptive filter. Different from Wiener algorithm, the coefficient of the system changes with the input sequence. Wiener algorithm intercepts a segment of the autocorrelation function of the input sequence to construct the optimal coefficient of the system. LMS algorithm is implemented by modifying the initial filter coefficients according to the minimum mean square error criterion. Therefore, theoretically speaking, the performance of LMS algorithm is better than wiener under the same conditions. However, LMS is gradually adjusted under the initial value, so there will be a period of adjustment before the system is stable. The adjustment time is controlled by the step factor. Within a certain range, the larger the step factor, the smaller the adjustment time, and the maximum value of step factor is the trace of R. LMS adopts the principle of minimum square error instead of the principle of minimum mean square error. The basic signal relationship is as follows:



Ii. Source code

clear all; clc; close all; %filedir=[D:\Program Files\MATLAB\speech.wav]; % the path is not set correctly, and the following is omitted: filename='speech.wav'; %fle=[filedir filename]; [s,fs] =audioread(filename); Audioread s=s/ Max (abs(s)); % Normalize the amplitude of speech signal N=length(s); % signal length time=(0:N- 1)/fs; % set the abscissa time ns=0.5*cos(2* pi* 50* time); % to calculate50Hz power frequency signal x= S +ns'; % Voice signal and50Superposition of Hz power frequency signal SNR1 =SNR_singlech(s,x); % after calculating overlay50The signal-to-noise ratio after Hz power frequency signal x1=cos(2* pi * 50* time); % set x1 and x2 x2=cos(2* pi * 50 * time);
w1=0.1; % initialize w1 and w2 w2=0.1;
e=zeros(1,N); % initialize e and y y=zeros(1,N);
mu=0.05; % set up mufor i=1:N y(i)=w1* x1(i)+ w2* x2(i); %LMS adaptive notch filter E (I)=x(I)-y(I); w1=w1+mu* e(i) * x1(i); w2=w2+mu* e(i) * x2(i); end output=e'; Snr2 =SNR_singlech(s,output); % Calculated filtered output SNR = SNR2-SNR1;fprintf('snr1 = % 5.4 f snr2 = % 5.4 f SNR = % 5.4 f \ n',snr1,snr2,snr); %wavpaly(x,fs); Audioplayer (x,fs) pause(1);
audioplayer(output,fs);
wavwrite(output,'hehe.wav');
Copy the code

3. Operation results

Fourth, note

Version: 2014 a