自适应噪声抑制算法LMSmatlab源码

本文介绍了一种利用LMS(Least Mean Squares)算法实现的数字信号滤波器,通过M阶滤波器处理带有噪声的信号,展示了从输入信号到滤波输出及误差信号的逐步过程,重点在于噪声抑制和信号质量改善。
摘要由CSDN通过智能技术生成

% filter parameters
M=20;      % number of taps
mu=0.05;   % step-size parameter
e_max=200; % maximum #of epochs

% constants
pi=3.14;
Fs=0.02;   % signal frequency
Fn=0.05;   % noise frequency

% initialize
w=(randn(1,M)-randn(1,M))/100;
d=zeros(1,M);
u=zeros(1,M);
u_out=zeros(1,e_max-M);
f_out=zeros(1,e_max-M);

% Generate desires signal and input(signal+noise)
for t=1:M-1
    d(t)=sin(2*pi*Fs*t);
    u(t)=d(t)+0.5*sin(2*pi*Fn*t)+randn;
end
t=M;
epoch=0;

while epoch<e_max
    epoch
    % generate new input
    input=sin(2*pi*Fs*t);
    % shift new input into array
    for i=2:M
        d(M-i+2)=d(M-i+1);
        u(M-i+2)=u(M-i+1);
    end
    d(1)=input;
    % add undesired freq & random noise
    u(1)=input+0.5*sin(2*pi*Fn*t)+0.09*randn;
    u_out(t-M+1)=u(1);
    
    % compute filteroutput
    output=dot(w,u);
    f_out(t-M+1)=output;
    
    % LMS algorithm
    % compute error
    e=d(1)-output;
    
    % update weights
    for n=1:M
        w(n)=w(n)+mu*u(n)*e;
    end
    
    %
    in(t-M+1)=u(1);
    out(t-M+1)=output;
    err(t-M+1)=e;
    
    t=t+1;
    epoch=epoch+1;
    
    %  plot noise and filtered signal
    figure(1)
    subplot(211);
    plot(t,u(1));axis([0 e_max -2.5 2.5]);
    title('滤波器输入')';
    hold on;
    subplot(212);
    plot(t,d(1));axis([0 e_max -2.5 2.5]);
    title('滤波器输出')';
    hold on;
    figure(2)
    subplot(211);
    plot(t,output);axis([0 e_max -2.5 2.5]);
    title('滤波输出信号')';
    hold on;
     subplot(212);
    plot(t,e);axis([0 e_max -2.5 2.5]);
    title('误差信号')';
    hold on;
end

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

fpga和matlab

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值