FFT and butterworth - Attenuation inside the passband

5 views (last 30 days)
Hello,
I am using "butter" to filter DC and as passband for two channels. Prior to filtering I choose a prefered segment in time that I want to filter (same segment for both channels). However, when I look at the fft of those channels I sometimes see that the signal is attenuated INSIDE the pass band for one of the channels but not for the other one. It can be either one of them.. (happening when using both HPF and BPF). When the segment is longer in length the phenomenon is less obvious but still happens. Sampling Rate = 10000. Is this a problem of using "filtfilt" instead of "filter"? Is there a limit to the length of the vector when using butter or fft?
Example Code for one of the channels (the other one is the same):
ind_fft = ind1(1:2^(nextpow2(length(ind1))-1)); % Transforming to length 2^x
N=length(ind_fft);
freq=linspace(-C.sr/2,C.sr/2,N+1);
freq=freq(1:N); % Remove DC Y_cw = Vcw_(ind_fft);
[b,a] = butter(2,[1]/(C.sr/2),'high'); % Remove DC 1 Hz
Y_DC_filtered_cw = filtfilt(b,a,Y_cw) ; % BPF
[b,a]=butter(2,[2 6]/5000,'bandpass'); % Bandpass at 4 Hz
Y_BPF_cw = filtfilt(b,a,Y_DC_filtered_cw) ;
Vcw_fft=fftshift(fft(Y_cw,N));
Vcw_fft_DC=fftshift(fft(Y_DC_filtered_cw,N));
Vcw_filt_fft=fftshift(fft(Y_BPF_cw,N));
Thanks !

Answers (2)

Wayne King
Wayne King on 11 Nov 2012
Edited: Wayne King on 11 Nov 2012
I don't think you need a filter to remove DC, just subtract the mean, or use detrend() to remove the best linear fit if there is a trend. The other thing is that your bandpass filter is not really much of a bandpass filter. With such a low order and a sample rate that is very large compared to the narrow passband you are trying to create, you're not going to get any kind of flat passband. Look at your filter's magnitude response.
[b,a] = butter(2,[2 6]/5000,'bandpass');
fvtool(b,a,'Fs',1e4)
Can you downsample your data? If you have a much lower sampling rate, then designing a decent [2,6] Hz bandpass filter would be much easier. Of course this depends on how much data you have at 10 kHz.
  2 Comments
Zack
Zack on 12 Nov 2012
Hi thanks !
You're right I can remove DC without a filter. I thought that the higher the sampling rate the better the digital filter works, but you're right - there is attenuation inside the passband. When I reduce the passband is it better to downsample? Most of my data is near the passband. Is till don't understand why the attenuation is more visible in one channel compared to the other if I am using the same filter.
Wayne King
Wayne King on 12 Nov 2012
the higher the sampling rate the better the digital filter works, The above is not accurate. The problem is your filter design in very strict at a sampling rate of 10 kHz, but it would be much less strict at a lower sampling rate. Your passband is very narrow with respect to the sampling frequency AND you are trying to do it with a very low order. If you can afford the data loss I would downsample the data and use a higher order. I don't know what to say about your last question without seeing the data.

Sign in to comment.


Catherine Schevon
Catherine Schevon on 6 Jun 2014
I ran into a similar problem. In my case, I was not subtracting the mean or the DC component, simply using a low pass 4th order Butterworth filter for antialiasing prior to downsampling a signal (from 30 kHz to 1 kHz). I used 250 Hz as the corner frequency. This resulted in attenuating the entire signal (including e.g. the < 10 Hz waveforms) by a factor of nearly 1000!!!!! This stands in contrast to the filter characteristics (freqz command) showing that attenuation should be zero up to about 135 Hz. The signals I am analyzing are EEG, which concentrates most signal power in the low frequencies (well under 135 Hz).
I found that similar signal attenuation was present no matter what kind of filter I tried (FIR1, ellip). However, I think this must be a Matlab bug (R2013b), as I don't remember seeing anything like this with prior Matlab versions. Until this is resolved I must consider Matlab R2013b filter functions to be unusable. Very disappointing...in general Matlab seems to be getting worse with time, not better.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!