Mercurial > hg > map
comparison utilities/UTIL_Butterworth.m @ 38:c2204b18f4a2 tip
End nov big change
author | Ray Meddis <rmeddis@essex.ac.uk> |
---|---|
date | Mon, 28 Nov 2011 13:34:28 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
37:771a643d5c29 | 38:c2204b18f4a2 |
---|---|
1 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 | |
31 |