MATLAB自适应滤波dsp.LMSFilter和dsp.RLSFilter

%% Load data
path = 'F:/PPGActivity/demo11pythonAndMatlab/ppg22222222222222222222/2015IEEE信号处理/Training_data/';
load([path,'DATA_01_TYPE01.mat']);

ecg  = sig(1,:);
ppg1_raw = sig(2,:); 
ppg2_raw = sig(3,:); 
accX = sig(4,:); 
accY = sig(5,:); 
accZ = sig(6,:);  

%% Preprocess

% A low pass filter is Used at 50Hz in PPG signals
N   = 120;
Fs  = 125;
Fp  = 40;
Ap  = 0.01;
Ast = 80;

% Design a FIR low pass filter
LP_FIR = dsp.LowpassFilter('SampleRate',Fs,...
    'DesignForMinimumOrder',false,'FilterOrder',N,...
    'PassbandFrequency',Fp,'PassbandRipple',Ap,'StopbandAttenuation',Ast);


ppg1 = step(LP_FIR,ppg1_raw);
ppg2 = step(LP_FIR,ppg2_raw);

%% LMS

order = 10;
mu = 0.008;            % LMS step size.
lms =dsp.LMSFilter('Length',order,'StepSize',mu);
% lms = adaptfilt.lms(order,mu);
% [y] = lms (accX,ppg1);
[y1] = maxstep(lms,accX);
[y2] = maxstep(lms,ppg1);

%% RLS

% rls = dsp.RLSFilter(11, 'ForgettingFactor', 0.98);
% [y3] = step(rls,accX);
% [y4] = step(rls,ppg1);


subplot(4,1,1)
plot(ppg1)
title('Input signal')
subplot(4,1,2)
plot(accX)
title('Observed Noise')
subplot(4,1,3)
plot(y)
title('LMS Filter output')
subplot(4,1,4)
plot(y2)
title('RLS Filter output')


subplot(3,1,1)
plot(ppg1_raw(1:2000))
title('PPG 1');
subplot(3,1,2)
plot(ppg2_raw(1:2000))
title('PPG 2');
subplot(3,1,3)
plot(ecg(1:2000))
title('ECG');


fvtool(LP_FIR,'Fs',Fs);
measure(LP_FIR)

%Spectrum plot
T = 1/Fs;             % Sampling period       
L = length(ppg1);    % Length of signal
t = (0:L-1)*T;        % Time vector

Y =fft(ppg1)./numel(ppg1);

P2 = abs(Y(2:end)/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);

f = Fs*(0:(L/2))/L;
plot((f),P1) 
grid on
title('Single-Sided Amplitude Spectrum of X(t)')
xlabel('f (Hz)')
ylabel('|P1(f)|')


评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值