Can anyone provide the error free full matlab code for output like in the attached picture taken from the link https://www.mathworks.com/help/signal/ref/bandpass.html?searchHighlight=bandpassing&s_tid=doc_srchtitle
MATLAB: Bandpassing of a signal
bandpassbandpass filtering
Related Solutions
If you want to eliminate the baseline wander and offset, change to a highpass filter with a different cutoff frequency:
wn=5/(fs/2); %lowpass 10Hz for ppg
[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; % Sampling Frequency (Hz)
Fn = Fs/2; % Nyquist Frequency (Hz)
Wp = 24.5/Fn; % Stopband Frequency (Normalised)
Ws = 25.0/Fn; % Passband Frequency (Normalised)
Rp = 1; % Passband Ripple (dB)
Rs = 50; % Stopband Ripple (dB)
[n,Ws] = cheb2ord(Wp,Ws,Rp,Rs); % Filter Order
[z,p,k] = cheby2(n,Rs,Ws,'high'); % Filter Design, Sepcify Bandstop
[sos,g] = zp2sos(z,p,k); % Convert To Second-Order-Section For Stability
figure(2)freqz(sos, 2^16, Fs) % Filter Bode Plot
ppg_head_data = filtfilt(sos, g, ppg_head); % Filter Signal
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.
That is likely asking too much of a Butterworth design. Use an elliptic filter instead:
Fs = 44100; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
Wp = [1E+3-30 1E+3+30]/Fn; % Passband Frequency (Normalised)
Ws = [1E+3-100 1E+3+100]/Fn; % Stopband Frequency (Normalised)
Rp = 1; % Passband Ripple
Rs = 100; % Passband Ripple (Attenuation)
[n,Wp] = ellipord(Wp,Ws,Rp,Rs); % Elliptic Order Calculation
[z,p,k] = ellip(n,Rp,Rs,Wp,'bandpass'); % Elliptic Filter Design: Zero-Pole-Gain
[sos,g] = zp2sos(z,p,k); % Second-Order Section For Stability
figurefreqz(sos, 2^16, Fs) % Filter Bode Plot
Use your own sampling frequency.
.
Best Answer