How to Design a Band-Pass Filter
204 views (last 30 days)
Show older comments
Hello everyone,
I've been having issues to create a band pass filter to treat EMG signals. I want to create a band pass filter of bandwith 85 (10-95) and my sampling rate is 200 Hz. After that, I would like to plot the frequency spectrum of the signal to verify that I filtered it correctly. Could someone help me with that? I appreciate any kind of help.
0 Comments
Answers (2)
Mark Sherstan
on 13 Nov 2018
Check out the bandpass filter from the signal processing toolbox located here. I would imagine your function would look something like this (a similar question was asked here):
% signalEMG = Your data
filteredEMG = bandpass(signalEMG,[10 95],200)
Plot the results using a FFT (you may need to tweak a few of the values such as L depending on your data):
Fs = 200;
T = 1/Fs;
L = 1500;
t = (0:L-1)*T;
Y = fft(filteredEMG);
P2 = abs(Y/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)
title('Single-Sided Amplitude Spectrum of X(t)')
xlabel('f (Hz)')
ylabel('|P1(f)|')
0 Comments
Star Strider
on 14 Nov 2018
Try this:
EMG = rand(1,1E+4); % EMG Signal
N = length(EMG);
Fs = 200; % Sampling Frequency (Hz)
t = linspace(0, N, N)/Fs; % Time Vector (If One Has Not Been Supplied With Your EEG Record)
Fn = Fs/2; % Nyquist Frequency (Hz)
Wp = [10 95]/Fn; % Passband Frequency Vector (Normalised)
Ws = [ 9 96]/Fn; % Stopband Frequency Vector (Normalised)
% Wp = 3.5/Fn;
% Ws = 2.5/Fn;
Rp = 1; % Passband Ripple (dB)
Rs = 50; % Stopband Attenuation (dB)
[n,Wp] = ellipord(Wp,Ws,Rp,Rs); % Calculate Filter Order
[z,p,k] = ellip(n,Rp,Rs,Wp,'bandpass'); % Default Here Is A Lowpass Filter
[sos,g] = zp2sos(z,p,k); % Use Second-Order-Section Implementation For Stability
EMG_filtered = filtfilt(sos,g,EMG); % Filter Signal (Here: ‘x’)
figure
freqz(sos, 2^14, Fs) % Bode Plot Of Filter
% set(subplot(2,1,1), 'XLim',[0 15]) % Optional, Change Limits As Necessary
% set(subplot(2,1,2), 'XLim',[0 15]) % Optional, Change Limits As Necessary% x = rand(1,1E+4);
nfft = 2^nextpow2(N);
FEMG_filtered = fft(EMG_filtered)/N;
Fv = linspace(0, 1, fix(N/2)+1)*Fn; % Frequency Vector
Iv = 1:length(Fv); % Index Vector
figure
plot(Fv, abs(FEMG_filtered(Iv))*2)
grid
2 Comments
Ben
on 3 Jul 2020
Star Strider, the output signal here is FEMG_filtered or EMG_Filtered? FEMG is a complex signal.Gracias, Ben
Star Strider
on 3 Jul 2020
Ben — The filtered output is ‘EMG_filtered’. The Fourier transform of it is ‘FEMG_filtered’. The purpose of that is to demonstrate the effect of the filtering.
See Also
Categories
Find more on Digital Filter Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!