{"id":209,"date":"2017-02-15T14:14:50","date_gmt":"2017-02-15T12:14:50","guid":{"rendered":"http:\/\/benediktehinger.de\/blog\/science\/?p=209"},"modified":"2017-02-15T14:14:50","modified_gmt":"2017-02-15T12:14:50","slug":"simple-filter-generation","status":"publish","type":"post","link":"https:\/\/benediktehinger.de\/blog\/science\/simple-filter-generation\/","title":{"rendered":"Simple Filter Generation"},"content":{"rendered":"<p>I sometimes explain concepts to my students. Then I forget the code and the next time round, I have to redo it. Take this post as an extended memory-post. In this case I showed what filter-ringing artefacts could look like. This is especially important for EEG preprocessing where filtering is a standard procedure.<\/p>\n<p>A good introduction to filtering can be found in this slides <a href=\"https:\/\/cloud.github.com\/downloads\/widmann\/firfilt\/firfilt.pdf\" target=\"_blank\">by andreas widmann<\/a>\u00a0or this paper <a href=\"https:\/\/www.ncbi.nlm.nih.gov\/pmc\/articles\/PMC3391960\/\" target=\"_blank\">by andreas widmann<\/a><\/p>\n<h3>Impulse with noise<\/h3>\n<p>I simulated as simple impulse response with some additional noise. The idea is to show the student that big spikes in the EEG-data could result in filter-ringing that is quite substantial and far away from the spike.<\/p>\n<p><a href=\"http:\/\/benediktehinger.de\/blog\/science\/upload\/sites\/2\/2017\/02\/simple_filter_example_01.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-211\" src=\"http:\/\/benediktehinger.de\/blog\/science\/upload\/sites\/2\/2017\/02\/simple_filter_example_01.png\" alt=\"\" width=\"568\" height=\"424\" srcset=\"https:\/\/benediktehinger.de\/blog\/science\/upload\/sites\/2\/2017\/02\/simple_filter_example_01.png 568w, https:\/\/benediktehinger.de\/blog\/science\/upload\/sites\/2\/2017\/02\/simple_filter_example_01-300x224.png 300w\" sizes=\"auto, (max-width: 568px) 100vw, 568px\" \/><\/a><\/p>\n<h3>The filter<\/h3>\n<p>This is the filter I generated. It is a BAD filter. It shows huge passband ripples. But for educational purposes it suits me nice. I usually explain what passbands, transitionband, stopband, ripples and attenuation means.<br \/>\n<a href=\"http:\/\/benediktehinger.de\/blog\/science\/upload\/sites\/2\/2017\/02\/simple_filter_example_02.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-210\" src=\"http:\/\/benediktehinger.de\/blog\/science\/upload\/sites\/2\/2017\/02\/simple_filter_example_02-1024x518.png\" alt=\"\" width=\"1024\" height=\"518\" srcset=\"https:\/\/benediktehinger.de\/blog\/science\/upload\/sites\/2\/2017\/02\/simple_filter_example_02-1024x518.png 1024w, https:\/\/benediktehinger.de\/blog\/science\/upload\/sites\/2\/2017\/02\/simple_filter_example_02-300x152.png 300w, https:\/\/benediktehinger.de\/blog\/science\/upload\/sites\/2\/2017\/02\/simple_filter_example_02-768x388.png 768w, https:\/\/benediktehinger.de\/blog\/science\/upload\/sites\/2\/2017\/02\/simple_filter_example_02.png 1598w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/p>\n<h3>The code<\/h3>\n<p>&#8220;`matlab<br \/>\nfs = 1000;<br \/>\nT = 2;<br \/>\ntime = 0:1\/fs:T-1\/fs;<\/p>\n<p>data = zeros(length(time),1);<br \/>\n% data(end\/2:end) = data(end\/2:end) + 1;<br \/>\ndata(end\/2) = data(end\/2) + 1;<br \/>\ndata = data + rand(size(data))*0.02;<\/p>\n<p>subplot(2,1,1)<br \/>\nplot(data)<\/p>\n<p>filtLow = designfilt(&#8216;lowpassfir&#8217;,&#8217;PassbandFrequency&#8217;,100, &#8230;<br \/>\n&#8216;StopbandFrequency&#8217;,110,&#8217;PassbandRipple&#8217;,0.5, &#8230;<br \/>\n&#8216;StopbandAttenuation&#8217;,65,&#8217;SampleRate&#8217;,1000);<\/p>\n<p>subplot(2,1,2)<\/p>\n<p>% 0-padding to get the borders right<br \/>\ndata = padarray(data,round(filtLow.filtord));<\/p>\n<p>% Filter twice to get the same phase(non-causal)<br \/>\na = filter(filtLow,data);<br \/>\nb = filter(filtLow,a(end:-1:1));<br \/>\nb = b(round(filtLow.filtord)+1:end &#8211; round(filtLow.filtord));<br \/>\nplot(b)<\/p>\n<p>fvtool(filtLow) % to look at the filter<\/p>\n<p>&#8220;`<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I sometimes explain concepts to my students. Then I forget the code and the next time round, I have to redo it. Take this post as an extended memory-post. In this case I showed what filter-ringing artefacts could look like. This is especially important for EEG preprocessing where filtering is a standard procedure. A good introduction to filtering can be found in this slides by andreas widmann\u00a0or this paper by andreas widmann Impulse with noise I simulated as simple impulse response with some additional noise. The idea is to show the student that big spikes in the EEG-data could result&#8230;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-209","post","type-post","status-publish","format-standard","hentry","category-blog"],"_links":{"self":[{"href":"https:\/\/benediktehinger.de\/blog\/science\/wp-json\/wp\/v2\/posts\/209","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/benediktehinger.de\/blog\/science\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/benediktehinger.de\/blog\/science\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/benediktehinger.de\/blog\/science\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/benediktehinger.de\/blog\/science\/wp-json\/wp\/v2\/comments?post=209"}],"version-history":[{"count":0,"href":"https:\/\/benediktehinger.de\/blog\/science\/wp-json\/wp\/v2\/posts\/209\/revisions"}],"wp:attachment":[{"href":"https:\/\/benediktehinger.de\/blog\/science\/wp-json\/wp\/v2\/media?parent=209"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/benediktehinger.de\/blog\/science\/wp-json\/wp\/v2\/categories?post=209"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/benediktehinger.de\/blog\/science\/wp-json\/wp\/v2\/tags?post=209"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}