Filtering of 60 Hz signal - not working

M
Mackenzie · Jan 8, 2021 · 1.9K views
Question
Following the example "Remove the 60 Hz hum from a signal", I tried to run a butterworth filter in order to filter out multiples of 60 Hz (60, 120, 180, 240, etc.) from my signal. However, in some of my signals, the filter actually amplifies those frequencies which I am trying to filter out. Here is some my code. All help is appreciated:     multiples60 = 60:60:2500; for v=1:length(multiples60) halfpowerHz1 = multiples60(v) - 2; halfpowerHz2 = multiples60(v) + 2; d = designfilt('bandstopiir','FilterOrder',2, ... 'HalfPowerFrequency1',halfpowerHz1,'HalfPowerFrequency2',halfpowerHz2, ... 'DesignMethod','butter','SampleRate',Fs); %butterworth filter if v==1 buttLoop = filtfilt(d,fsignal); else buttLoop = filtfilt(d,buttLoop); end end
Expert Answer
Profile picture of Kshitij Singh
Kshitij Singh PhD Expert
Answered Aug 24, 2026
Here is what I have tested by changing in one point of your code and seen that it is working quite well now:
 
multiples60 = 60:60:2500;
for v=1:numel(multiples60)
    halfpowerHz1 = multiples60(v) - 3;
    halfpowerHz2 = multiples60(v) + 3;
    d = designfilt('bandstopiir','FilterOrder', 2, ...
               'HalfPowerFrequency1',halfpowerHz1,'HalfPowerFrequency2',halfpowerHz2, ...
               'DesignMethod','butter', 'SampleRate',Fs); %butterworth filter
        if v==1
        buttLoop = filtfilt(d,fsignal);
    else
        buttLoop = filtfilt(d,buttLoop);
    end
end
L = length(fsignal);
N = 4*2048; % block size
 f = Fs/2*linspace(0,1, N/2+1);
Y = fft(buttLoop, N)/L;
plot(f, Y(1:N/2+1)), grid on
100% Run Guarantee 3-Hour Fast-Track Delivery

Need a Custom Version or Complete Simulation for This Problem?

Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.

Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!