TEAP (Toolbox for Emotion Analysis using Physiological Signals) doc
filterECG256Hz.m
Go to the documentation of this file.
1 %> @file filterECG256Hz.m
2 function [filtdata] = filterECG256Hz(data)
3 
4 % [filtdata] = filterECG256Hz(data);
5 % apply a zerophase FIR filter (coeffs designed with sptool)
6 % Least Sq. FIR LP & HP filters (cascaded): 70dB 0.05-40Hz 1dB ripple.
7 % Sampling Frequency of Fs = 256.
8 %
9 % Should work nicely for 16bit, 256Hz ECG. You may experince
10 % some ringing at turning points, but that's FIR filters for you.
11 % You might like to try wavelets for a better filter
12 %
13 % These routines are made available under the GNU general public license.
14 % If you have not received a copy of this license, please download from
15 % http://www.gnu.org/
16 %
17 % Please distribute (and modify) freely, commenting where you have
18 % added modifications. The author would appreciate correspondence
19 % regarding corrections, modifications, improvements etc.
20 %
21 % G. Clifford : gari@ieee.org
22 
23 % sampling frequency
24 Fs = 256; % Hz
25 
26 % Data should be zeromeaned before calling this function
27 data = data - mean(data);
28 
29 % set up transfer function
30 denominator = 1;
31 numerator_lp = [
32  0.00116294818892327
33  0.0108214392935653
34  0.0200343666593651
35  0.0261187881634098
36  0.0212816864030144
37  0.00490488877763669
38  -0.0145498515998796
39  -0.0232788926070469
40  -0.0124182936123568
41  0.0126862162067748
42  0.0328393141039891
43  0.0277014738094466
44  -0.00663354198352208
45  -0.0487259025516825
46  -0.0610853025450089
47  -0.0144549204767754
48  0.0886474308596396
49  0.208814361863424
50  0.289332487838881
51  0.289332487838881
52  0.208814361863424
53  0.0886474308596396
54  -0.0144549204767754
55  -0.0610853025450089
56  -0.0487259025516825
57  -0.00663354198352208
58  0.0277014738094466
59  0.0328393141039891
60  0.0126862162067748
61  -0.0124182936123568
62  -0.0232788926070469
63  -0.0145498515998796
64  0.00490488877763669
65  0.0212816864030144
66  0.0261187881634098
67  0.0200343666593651
68  0.0108214392935653
69  0.00116294818892327];
70 
71 numerator_hp = [
72  -0.007719806995443
73  -0.000593529464503111
74  -0.000616537270116216
75  -0.000639451830525362
76  -0.000663561635529363
77  -0.000687428482340838
78  -0.000712345353053305
79  -0.000737050063062293
80  -0.000762827770843517
81  -0.000788276159757994
82  -0.000814687362552657
83  -0.000840693466317883
84  -0.000867737622092878
85  -0.00089438708671706
86  -0.00092216902638079
87  -0.000949570338620629
88  -0.000978288661010672
89  -0.00100668160625124
90  -0.00103659671861193
91  -0.00106615479623852
92  -0.00109736040348402
93  -0.00112792836635087
94  -0.00116004251486604
95  -0.00119092382531205
96  -0.00122322204449099
97  -0.00125354739873849
98  -0.00128545618449105
99  -0.00131494126741691
100  -0.00134807599742105
101  -0.00138005083638085
102  -0.00142229273289703
103  -0.00145905623888122
104  -0.00147988572401479
105  -0.00152337012050789
106  -0.00155509077331504
107  -0.0015924435019478
108  -0.00162645093636032
109  -0.00166360336918217
110  -0.00169886271207229
111  -0.00173643201108726
112  -0.00177256853414649
113  -0.00181053087910452
114  -0.00184738932024739
115  -0.00188580324032983
116  -0.00192320422309985
117  -0.00196187823931274
118  -0.00199959655075123
119  -0.00203849112299403
120  -0.0020765587432622
121  -0.00211583028869268
122  -0.00215442956472851
123  -0.00219430023605191
124  -0.00223352552719682
125  -0.00227395565365889
126  -0.00231354279813875
127  -0.002354108014004
128  -0.00239338505355968
129  -0.00243353302728908
130  -0.00247248705230046
131  -0.00251352618627335
132  -0.00255409536944302
133  -0.00259725994910034
134  -0.00263509464305156
135  -0.00267536483006731
136  -0.00271826154742389
137  -0.00275770700056424
138  -0.00279927582669419
139  -0.00283951499715645
140  -0.00288073484890323
141  -0.00292129482201999
142  -0.00296233875603428
143  -0.00300290150021605
144  -0.00304386170207064
145  -0.00308454857127824
146  -0.00312549340035217
147  -0.00316610295239397
148  -0.00320679774729835
149  -0.0032471413328337
150  -0.00328750802064282
151  -0.00332753344802601
152  -0.00336758426155901
153  -0.00340736140579608
154  -0.00344722643493981
155  -0.00348685648439877
156  -0.00352656997497068
157  -0.00356591121574338
158  -0.00360510516351791
159  -0.00364360588016825
160  -0.00368197568241012
161  -0.00371996751152801
162  -0.00375850930844281
163  -0.00379655172798984
164  -0.00383430839616961
165  -0.00387004946444441
166  -0.00390808220759818
167  -0.00394482515495904
168  -0.00398066969639526
169  -0.00401692280951308
170  -0.00405221772052505
171  -0.00408773437155447
172  -0.00412235016462235
173  -0.00415686418023859
174  -0.00419066438491442
175  -0.00422445487363778
176  -0.0042576163393507
177  -0.00429061997144701
178  -0.00432291749710377
179  -0.00435498997501222
180  -0.00438636173060546
181  -0.00441745251390048
182  -0.00444780506237289
183  -0.00447784887049958
184  -0.00450718961782266
185  -0.00453627650609555
186  -0.00456472176460446
187  -0.0045929170622211
188  -0.00462034686518763
189  -0.00464732123257699
190  -0.0046733867508092
191  -0.00469915525083144
192  -0.00472429941522134
193  -0.00474929514447324
194  -0.00477312604512227
195  -0.00479636638243965
196  -0.00481865942392797
197  -0.00484177134432678
198  -0.00486283917051695
199  -0.0048838439863828
200  -0.00490407570971269
201  -0.00492386545165352
202  -0.00494290018123188
203  -0.0049611304645503
204  -0.00497862211466973
205  -0.00499556750358641
206  -0.00501186356380093
207  -0.00502752874153267
208  -0.00504241401877351
209  -0.00505665927887701
210  -0.00507016713131965
211  -0.00508305015409715
212  -0.00509513775950472
213  -0.00510653645526546
214  -0.00511710891690786
215  -0.00512701904388992
216  -0.00513616850829649
217  -0.00514472125325565
218  -0.00515250765464019
219  -0.00515958960068915
220  -0.00516579676427969
221  -0.00517132876190234
222  -0.00517617853236731
223  -0.00518043811157794
224  -0.00518382726123044
225  -0.00518621003962965
226  -0.00518794262187708
227  -0.00518900154305289
228  0.994810133061056
229  -0.00518900154305289
230  -0.00518794262187708
231  -0.00518621003962965
232  -0.00518382726123044
233  -0.00518043811157794
234  -0.00517617853236731
235  -0.00517132876190234
236  -0.00516579676427969
237  -0.00515958960068915
238  -0.00515250765464019
239  -0.00514472125325565
240  -0.00513616850829649
241  -0.00512701904388992
242  -0.00511710891690786
243  -0.00510653645526546
244  -0.00509513775950472
245  -0.00508305015409715
246  -0.00507016713131965
247  -0.00505665927887701
248  -0.00504241401877351
249  -0.00502752874153267
250  -0.00501186356380093
251  -0.00499556750358641
252  -0.00497862211466973
253  -0.0049611304645503
254  -0.00494290018123188
255  -0.00492386545165352
256  -0.00490407570971269
257  -0.0048838439863828
258  -0.00486283917051695
259  -0.00484177134432678
260  -0.00481865942392797
261  -0.00479636638243965
262  -0.00477312604512227
263  -0.00474929514447324
264  -0.00472429941522134
265  -0.00469915525083144
266  -0.0046733867508092
267  -0.00464732123257699
268  -0.00462034686518763
269  -0.0045929170622211
270  -0.00456472176460446
271  -0.00453627650609555
272  -0.00450718961782266
273  -0.00447784887049958
274  -0.00444780506237289
275  -0.00441745251390048
276  -0.00438636173060546
277  -0.00435498997501222
278  -0.00432291749710377
279  -0.00429061997144701
280  -0.0042576163393507
281  -0.00422445487363778
282  -0.00419066438491442
283  -0.00415686418023859
284  -0.00412235016462235
285  -0.00408773437155447
286  -0.00405221772052505
287  -0.00401692280951308
288  -0.00398066969639526
289  -0.00394482515495904
290  -0.00390808220759818
291  -0.00387004946444441
292  -0.00383430839616961
293  -0.00379655172798984
294  -0.00375850930844281
295  -0.00371996751152801
296  -0.00368197568241012
297  -0.00364360588016825
298  -0.00360510516351791
299  -0.00356591121574338
300  -0.00352656997497068
301  -0.00348685648439877
302  -0.00344722643493981
303  -0.00340736140579608
304  -0.00336758426155901
305  -0.00332753344802601
306  -0.00328750802064282
307  -0.0032471413328337
308  -0.00320679774729835
309  -0.00316610295239397
310  -0.00312549340035217
311  -0.00308454857127824
312  -0.00304386170207064
313  -0.00300290150021605
314  -0.00296233875603428
315  -0.00292129482201999
316  -0.00288073484890323
317  -0.00283951499715645
318  -0.00279927582669419
319  -0.00275770700056424
320  -0.00271826154742389
321  -0.00267536483006731
322  -0.00263509464305156
323  -0.00259725994910034
324  -0.00255409536944302
325  -0.00251352618627335
326  -0.00247248705230046
327  -0.00243353302728908
328  -0.00239338505355968
329  -0.002354108014004
330  -0.00231354279813875
331  -0.00227395565365889
332  -0.00223352552719682
333  -0.00219430023605191
334  -0.00215442956472851
335  -0.00211583028869268
336  -0.0020765587432622
337  -0.00203849112299403
338  -0.00199959655075123
339  -0.00196187823931274
340  -0.00192320422309985
341  -0.00188580324032983
342  -0.00184738932024739
343  -0.00181053087910452
344  -0.00177256853414649
345  -0.00173643201108726
346  -0.00169886271207229
347  -0.00166360336918217
348  -0.00162645093636032
349  -0.0015924435019478
350  -0.00155509077331504
351  -0.00152337012050789
352  -0.00147988572401479
353  -0.00145905623888122
354  -0.00142229273289703
355  -0.00138005083638085
356  -0.00134807599742105
357  -0.00131494126741691
358  -0.00128545618449105
359  -0.00125354739873849
360  -0.00122322204449099
361  -0.00119092382531205
362  -0.00116004251486604
363  -0.00112792836635087
364  -0.00109736040348402
365  -0.00106615479623852
366  -0.00103659671861193
367  -0.00100668160625124
368  -0.000978288661010672
369  -0.000949570338620629
370  -0.00092216902638079
371  -0.00089438708671706
372  -0.000867737622092878
373  -0.000840693466317883
374  -0.000814687362552657
375  -0.000788276159757994
376  -0.000762827770843517
377  -0.000737050063062293
378  -0.000712345353053305
379  -0.000687428482340838
380  -0.000663561635529363
381  -0.000639451830525362
382  -0.000616537270116216
383  -0.000593529464503111
384  -0.007719806995443 ];
385 
386 
387 % low pass filter
388 aff_lp = filtfilt(numerator_lp, denominator, data);
389 
390 % Don't high pass filter it if you don't want to remove the baseline
391 % fluctuations due to resp, BP? and electrode noise?
392 filtdata = filtfilt(numerator_hp, denominator, aff_lp);
393 
394 % correct for amplitude distortion. !!!??????
395 %mean_s = mean(new_data);
396 %mean_a = mean(aff_hp);
397 %a = aff*(mean_s/mean_a);
398 
filterECG256Hz
function filterECG256Hz(in data)