lms1.m
来自「本源码用MATLAB语言实现了自适应LMS算法」· M 代码 · 共 62 行
M
62 行
randn('seed', 0) ;rand('seed', 0) ;NoOfData = 1785 ; % Set no of data points used for trainingOrder = 40 ; % Set the adaptive filter orderMu = 0.01 ; % Set the step-size constantx = randn(NoOfData, 1) ;% Input assumed to be whitet=0:((4*pi)/1784):4*pi;x=x+(sin(t))';h = rand(Order, 1) ; % System picked randomly% d=sin(t);d = filter(h, 1, x) ; % Generate output (desired signal)% Initialize LMSw = zeros(Order,1) ;% LMS Adaptationfor n = Order : NoOfData D = x(n:-1:n-Order+1) ; e(n) = d(n) - w'*D ; w = w + Mu*e(n)*D ; y(n)=w'*D; w_err(n) = norm(h - w) ;end ;exn=fft(x)yn=fft(y)% Plot resultsfigure;subplot(211),plot(x);subplot(212),plot(y);figure;subplot(211),plot(x);subplot(212),plot(e);figuresubplot(211);plot(abs(xn));ylabel('输入');subplot(212);plot(abs(yn));ylabel('输出');title('FFT频谱分析图')% figure ;% plot(20*log10(abs(e))) ;% title('Learning Curve') ;% xlabel('Iteration Number') ;% ylabel('Output Estimation Error in dB') ;% % figure ;% semilogy(w_err) ;% title('Weight Estimation Error') ;% xlabel('Iteration Number') ;% ylabel('Weight Error in dB') ;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?