To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
The primary repository for this project is hosted at git://github.com/rmeddis/MAP.git .
This repository is a read-only copy which is updated automatically every hour.
root / utilities / UTIL_Butterworth.m
History | View | Annotate | Download (902 Bytes)
| 1 | 38:c2204b18f4a2 | rmeddis | function x=UTIL_Butterworth (x, dt, fl, fu, order) |
|---|---|---|---|
| 2 | % UTIL_Butterworth (x, dt, fu, fl, order) |
||
| 3 | % Taken from Yuel and beauchamp page 261 |
||
| 4 | % NB error in their table for K (see their text) |
||
| 5 | % x is original signal |
||
| 6 | % x is the filtered output (approx 3 dB down at cutoff for first order filter) |
||
| 7 | % fu, fl upper and lower cutoff |
||
| 8 | % order is the number of times the filter is applied |
||
| 9 | % (approx 6 dB attenuation is corrected) |
||
| 10 | |||
| 11 | sampleRate=1/dt; |
||
| 12 | if 4*fu>sampleRate |
||
| 13 | error(['UTIL_Butterworth: sample rate ' num2str(sampleRate) ' is too low. Sampling rate should be >' num2str(4*fu)]) |
||
| 14 | end |
||
| 15 | |||
| 16 | |||
| 17 | q=(pi*dt*(fu-fl)); |
||
| 18 | J=1/(1+ cot(q)); |
||
| 19 | K= (2*cos(pi*dt*(fu+fl)))/((1+tan(q))*cos(q)); |
||
| 20 | L= (tan(q)-1)/(tan(q)+1); |
||
| 21 | b=[J 0 -J]; |
||
| 22 | a=[1 -K -L]; |
||
| 23 | |||
| 24 | [numChannels nDataPoints]=size(x); |
||
| 25 | for channelNumber=1:numChannels |
||
| 26 | for j=1:order |
||
| 27 | % x2 compensate for 6 dB attenuation |
||
| 28 | x(channelNumber,:)=2*filter(b, a, x(channelNumber,:)); |
||
| 29 | end |
||
| 30 | end |