📄 rls.m
字号:
clear all
close all
clc
% RLS 算法
Fs = 600 ; % Set no of data points used for training
N = 4 ; % Set the adaptive filter order
Lambda = 0.998 ; % Set the forgetting factor
Delta = 0.0001 ; % R initialized to Delta*I
f1=10;
f2=50;
det=1/Fs;
t=0:det:1-det;
d=2*cos(2*pi*f1*t);
snr=20;
s_power=var(d); %var函数: 返回方差值
linear_snr=10^(snr/10);
factor=sqrt(s_power/linear_snr);
%noise=randn(1,length(d))*factor+sin(2*pi*f2*t);
%noise=randn(1,length(d))*factor;
noise=randn(1,length(d))*factor;
x=d+noise;
x=x';
M=Fs;
% Initialize RLS
P = 1/Delta * eye ( N, N ) ;
w = zeros ( N,1 ) ;
y1=zeros(M,N);
% RLS Adaptation
%引入遗忘因子Lambda<1
for n = N : M ;
u = x(n:-1:n-N+1) ;%延时函数
K=P*u/(Lambda+u'*P*u);
y(n)=w'*u;
e(n) = d(n) - w' * u ;%误差函数
w = w + K * e(n) ;%递归公式
P=(P-K*u'*P)/Lambda;
%w_err(n) = norm(h - w) ;%真实估计误差
end ;
figure(1);
subplot(3,1,1)
plot(x);xlabel('Hz')
title('原始信号')
subplot(3,1,2)
plot(y)
title('经未知系统后信号');xlabel('Hz')
subplot(3,1,3)
plot(20*log10(abs(e)))
axis([0 Fs/2 -150 5]);
title('经自适应FIR滤波器后信号');xlabel('Hz')
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -