# signal does not show filtered, using filter()

1 view (last 30 days)
Terry Carney on 9 May 2021
Commented: Star Strider on 9 May 2021
Hello,
I have a signal that I must filter out 60-Hz noise from. I've setup the three moving averages that I want to use to see which one will filter out the 60-Hz noise. However, when I use the coefficients with the unfiltered signal using the filter() function, the plot of the unfiltered signal and the "filtered" signal remains the same. Any advice would be helpful. If someone wants to also use the text file that contains the data for the unfiltered signal, that is attached as well.
%Moving Averages' Coefficients
ync = [.25, .5, .25];
ync1 = [-.085 .342 .485 .342 -.085];
ync2 = [-.090 .060 .168 .233 .255 .233 .168 .060 -.090]
Fs1 = 500; %Sampling Frequency
Ts1 = 1/Fs1; %Sampling Time
t1 = 0:1/Fs1:1-1/Fs1;
dataMean = mean(data, 2);
plot(t1,dataMean); %Unfiltered Signal
z = filter(ync,1,dataMean); %Choice of Moving Average to test for filtered results
plot(t1,z);
The issue is that the unfiltered signal from the data.txt plot(t1,dataMean) looks identical to the intended filtered signal z = filter(ync,1,dataMean).

Star Strider on 9 May 2021
Use freqz to see what the filters are actually doing —
Fs1 = 500; %Sampling Frequency
ync = [.25, .5, .25];
ync1 = [-.085 .342 .485 .342 -.085];
ync2 = [-.090 .060 .168 .233 .255 .233 .168 .060 -.090];
figure
freqz(ync,1, 2^16, Fs1)
sgtitle('ync')
figure
freqz(ync1,1, 2^16, Fs1)
sgtitle('ync_1')
figure
freqz(ync2,1, 2^16, Fs1)
sgtitle('ync_2')
So none of them are going to filter out the 60 Hz signal.
To design one that specifically will do that —
Fs1 = 500; %Sampling Frequency
freqs = [57 59 61 63];
mags = [1 0 1];
devs = [0.05 0.01 0.05];
[n,Wn,beta,ftype] = kaiserord(freqs,mags,devs,Fs1)
n = 560
Wn = 2×1
0.2320 0.2480
beta = 3.3953
ftype = 'stop'
hh = fir1(n,Wn,ftype,kaiser(n+1,beta),'noscale');
figure
freqz(hh, 1, 2^16, Fs1)
sgtitle('60 Hz Notch Filter')
This is a relatively long filter, however it should do what you want.
Use the filtfilt function to do the actual filtering.
.
Star Strider on 9 May 2021
I would just do something like this —
signal_filtered = filter(ycn2, 1, signal)
That will not eliminate the 60 Hz noise because the filter is not designed to do that. It will simply attenuate it a bit.