Remove 50 Hz noise
Show older comments
I am recording 6 channels from a force transducer, but there is a 50 Hz noise I want to remove. I was considering to use a simple solution as iirnotch, but I don't have this function on my Matlab R2015a. How can I create a filter (filtfilt and fir1?) to eliminate this 50 Hz without a signal processing toolbox?
Thank you
16 Comments
Rik
on 25 Jun 2018
I added the 'no toolbox' tag, because this is almost trivial otherwise. My Google search (for 'bandstop filter') didn't turn up something either. There are several contributors more skilled in signal processing than me, so they might be able to help here.
Paola
on 26 Jun 2018
Walter Roberson
on 26 Jun 2018
How wide can the stop band be? What is your sampling frequency?
Paola
on 26 Jun 2018
Edited: Walter Roberson
on 26 Jun 2018
Walter Roberson
on 26 Jun 2018
That is not the correct way to create a bandstop butterworth filter.
Walter Roberson
on 26 Jun 2018
You cannot remove only 50 Hz exactly with a digital filter of that type. Instead you effectively construct a lowpass filter that starts to drop down near 50 Hz, cutting off high frequencies, "plus" (in some sense) a highpass filter that starts coming up near 50 Hz, cutting off low frequencies. The downwards dip heading into 50 Hz and the upwards dip heading after 50 Hz together diminish 50 Hz, along with diminishing frequencies approaching 50 Hz on other side.
The higher the order that you use, the sharper the cutoff can be, but also the longer the filter representation comes out when expressed as a convolution, so the processing rate is higher for lower orders.
Walter Roberson
on 26 Jun 2018
I think that looks okay, but I hardly do any filter work so I am not sure.
Paola
on 27 Jun 2018
Walter Roberson
on 27 Jun 2018
Tests I did with butter suggest that it is not very good at narrow band suppression :( With low orders it still left a fair bit of signal in the target range, and with orders from about 5 up, it created quite large transients.
Paola
on 28 Jun 2018
Star Strider
on 28 Jun 2018
I thought you said that you do not have the Signal Processing Toolbox! I agree with Rik Wisselink that with it this is essentially trivial. However, you appear to be using its functions, so I will add this:
Fs = 20000;
Fn = Fs/2;
Wp = [47 53]/Fn;
Ws = [49 51]/Fn;
Rp = 1;
Rs = 50;
[n,Wn] = buttord(Wp,Ws,Rp,Rs);
[z,p,k] = butter(n,Wn,'stop');
[sos,g] = zp2sos(z,p,k);
figure
freqz(sos, 2^14, Fs)
set(subplot(2,1,1), 'XLim',[0 100])
set(subplot(2,1,2), 'XLim',[0 100])
The freqz call lets you see what the filter is doing in the frequency domain. There is also no need for the loop, because the filter functions operate column-wise. You simply need to transpose your matrix.
This should work:
ForceDataFilt = filtfilt(sos, g, ForceData'); % Transpose & Filter
ForceDataFilt = ForceDataFilt';
I transposed ‘ForceDataFilt’ so it will match the rest of your code. Experiment with the filter passband and stopband frequencies to get the result you want. Remember that for a notch or bandstop filter, the stopband frequencies (here ‘Ws’) are within the passband limits, ‘Wp’. The passband and stopband attenuation values are ‘Rp’ and ‘Rs’ respectively.
Walter Roberson
on 28 Jun 2018
Looks like you should be able to invoke designfilt in R2015a.
Paola
on 28 Jun 2018
Answers (1)
Kouichi C. Nakamura
on 20 Feb 2020
Edited: Walter Roberson
on 21 Feb 2020
0 votes
This looks like an answer.
Remove the 60 Hz Hum from a Signal
1 Comment
Alan
on 3 Jan 2025
Thank you. That solved it for me. Applying the filter with the coefficients didn't seem to do anything.
Categories
Find more on Single-Rate Filters 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!