Low-pass filter in Matlab / Python for removing movement noise
24 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello
I'm recording a signal (skin conductance) over time, i.e. I have a time series. Unfortunately, the signal is affected by movement. In a user guide I have now read the following:
> A low pass filter should be applied to the data to remove high > frequency noise which can be attributed to movement artifact and other > noise components. A cutoff frequency of as low as 1 - 5 Hz can be used > without affecting the data of interest due to the slowly varying > nature of GSR responses.
How can I apply such a low pass filter with a cutoff frequency to my time series in Matlab or Python?
0 comentarios
Respuestas (2)
Star Strider
el 24 de Sept. de 2017
That filter is straightforward to design with Signal Processing Toolbox functions.
A bandpass filter (eliminating d-c offset) is:
Fs = 1000; % Sampling Frequency (Hz)
Fn = Fs/2; % Nyquist Frequency (Hz)
Wp = [1.0 5.0]/Fn; % Passband Frequency (Normalised)
Ws = [0.5 5.1]/Fn; % Stopband Frequency (Normalised)
Rp = 1; % Passband Ripple (dB)
Rs = 150; % Stopband Ripple (dB)
[n,Ws] = cheb2ord(Wp,Ws,Rp,Rs); % Filter Order
[z,p,k] = cheby2(n,Rs,Ws); % Filter Design
[sosbp,gbp] = zp2sos(z,p,k); % Convert To Second-Order-Section For Stability
figure(3)
freqz(sosbp, 2^16, Fs) % Filter Bode Plot
filtered_signal = filtfilt(sosbp, gbp, original_signal); % Filter Signal
A ‘pure’ lowpass filter design (that would pass the d-c offset) is:
Fs = 1000; % Sampling Frequency (Hz)
Fn = Fs/2; % Nyquist Frequency (Hz)
Wp = 5.0/Fn; % Passband Frequency (Normalised)
Ws = 5.1/Fn; % Stopband Frequency (Normalised)
Rp = 1; % Passband Ripple (dB)
Rs = 150; % Stopband Ripple (dB)
[n,Ws] = cheb2ord(Wp,Ws,Rp,Rs); % Filter Order
[z,p,k] = cheby2(n,Rs,Ws); % Filter Design
[soslp,glp] = zp2sos(z,p,k); % Convert To Second-Order-Section For Stability
figure(3)
freqz(soslp, 2^16, Fs) % Filter Bode Plot
filtered_signal = filtfilt(soslp, glp, original_signal); % Filter Signal
Be sure to provide the correct sampling frequency ‘Fs’ value for your data. I used 1 KHz here to test my code. Both of these designs have an upper passband of 5.0 Hz and a stopband of 5.1 Hz. Change the passband and stopband frequencies to those appropriate for your data. A stopband at least 0.1 Hz higher than the passband is acceptable, and will produce a stable filter providing the sampling frequency is reasonable (not too high). Experiment with these to get the filter characteristics and behaviour that you want.
2 comentarios
Star Strider
el 25 de Sept. de 2017
Begin by plotting the fft (link) of your signal. It will tell you what you need to know about the frequency content. If the first (or 0 Hz) value is very high, subtract the mean of your signal from the rest of your signal before taking the Fourier transform:
FTsignal = fft(signal-mean(signal))/length(signal);
Be careful about using length, numel, and size to get the number of elements in your signal. See the documentation on them for details.
All these functions and my filter design code assume that your data are regularly sampled (constant sample time difference). If not, you will have to do some pre-processing on them with the Signal Processing Toolbox resample function.
I will help as needed.
Image Analyst
el 24 de Sept. de 2017
Take the fft. Zero out the elements corresponding to -5 Hz to +5 Hz, then inverse transform. Attach your data if you need more help.
0 comentarios
Ver también
Categorías
Más información sobre Filter Design en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!