If you want to eliminate the baseline wander and offset, change to a highpass filter with a different cutoff frequency:
wn=5/(fs/2);
[b,a] = butter(8,wn,'high');
ppg_head_data = filter(b,a,ppg_head);
There are much better ways to design and implement filters. Here is one:
t = linspace(0, numel(ppg_head), numel(ppg_head))/fs;
Fs = 960;
Fn = Fs/2;
Wp = 24.5/Fn;
Ws = 25.0/Fn;
Rp = 1;
Rs = 50;
[n,Ws] = cheb2ord(Wp,Ws,Rp,Rs);
[z,p,k] = cheby2(n,Rs,Ws,'high');
[sos,g] = zp2sos(z,p,k);
figure(2)
freqz(sos, 2^16, Fs)
ppg_head_data = filtfilt(sos, g, ppg_head);
Use the Signal Processing Toolbox findpeaks (link) function on your filtered data to locate the peaks: [pks,locs] = findpeaks(ppg_head_data, 'MinPeakHeight',2E+5);
You can use the ‘locs’ index vector to refer to the peaks and times in the original unfiltered signal.
Best Answer