help-octave
[Top][All Lists]

## Using butterworth filter

 From: StandardOctaveUser Subject: Using butterworth filter Date: Fri, 14 Dec 2012 17:00:10 -0800 (PST)

```What you need is a butterworth filter
which is supplied with signal processing
package.

Say you have N data points and
a sampling frequency of SF (in Hz). Then
you have T seconds of record.

T=N/SF;

Assume uuu is your data and it is
as zigzaggy as it gets, its random.

uuu=rand(N,1).-0.5;

Suppose you are interested in data
that has a maximum of 18 rad*Hz
frequency and above that is noise

wc=18;
n=10;
[b,a]=butter(n,wc/(N*pi/T));
uuu2=filter(b,a,uuu);

uuu2 is the filtered data that you want.
n is a parameter that designates the
sharpness of the butterworth filter.

Consider having an equal amount of
each frequency.

uw=ones(N,1);
uuu1=ifft(uw).*(N/T);

now at this point uuu1 is your problematic
data.

wc=18;
n=10;
[b,a]=butter(n,wc/(N*pi/T));
uuu2=filter(b,a,uuu1);

w=(0:2*pi/T:(N-1)*2*pi/T)';

subplot(2,2,1):plot(w,abs(fft(uuu2)).*(T/N));
title('Filtered Spectra')
subplot(2,2,2):plot(w,abs(fft(uuu1)).*(T/N));
title('Unfiltered Spectra')
subplot(2,2,3):plot(uuu2);
title('Filtered Series')
subplot(2,2,4):plot(uuu1);
title('Unfiltered Series')

Try playing with wc and n and replotting
several times. When you are satisfied
with the filter you are about to apply,
apply it to the real data.

As you will see n increases sharpness of the
fall but it also causes some wiggles in the
frequencies that you want to keep depending
on what your wc is the degree to this effect
will change. The idea is to keep the frequencies
you want to pass as close to 1 in that plot and
the ones you want to get rid off falling to zero
as fast as possible.

To have an idea which frequency will look
how much zigzaggy in time series, make a
plot out of it and decide if you want to keep
it or not. ie.

SF=200;
dt=1/SF;
T=10;
w=5;
t=(0:dt:T-dt)';
Ft=sin(w*t);

plot(t,Ft);

Note: This will not filter signals according to
amplitude range as in the subject but will
filter them based on their frequency which
what you want as I understand.

--
View this message in context:
http://octave.1599824.n4.nabble.com/Filtering-Signals-according-to-an-Amplitude-Range-tp4647610p4647935.html
Sent from the Octave - General mailing list archive at Nabble.com.

```