I'm having difficulty in calculating the Butterworth coefficients with the 'buttord' and 'butter' functions. My objective is to filter out noise from a time series I constructed. The time series has a red noise component and a sinuosoid signal with frequency 0.3 Hz. The sampling frequency of the time series is 10 Hz.
Following the documentation on 'buttord' http://www.mathworks.com/help/signal/ref/buttord.html I calculated [n, Wn] for the specifications (followed example 1 of the documentation):
Wp = 0.33/(sfreq/2); Ws = 0.37/(sfreq/2);
passripp = 0.1; stopatten = 40;
[n,Wn] = buttord(Wp,Ws,passripp,stopatten);
[b,a] = butter(n,Wn);
y_butter = filter(b,a,timeseries(:,2));
Plotting y_butter with time just gives me zero everywhere!
I attempted to use 'freqz' to examine the frequency response of the filter (using 512 samples):
freqz(b,a,512,sfreq)
whose plot shows that the transition band is between 1 and 4 Hz!
My understanding behind the filter is:
- signal at 0.3 Hz
- noise at >> 0.3 Hz
- pass everything from 0 to 0.33 Hz
- attenuate everything from 0.36 Hz beyond
Your help will be much appreciated!
Data can be downloaded here: http://dl.dropbox.com/u/1918592/detrendedTS.mat Column 1 of 'ts' is time variable, column 2 is data variable
I detrended a linear fit (Matlab 'detrend') to remove some of the walk-away red noise behavior.