{"id":2914,"date":"2017-05-09T13:27:17","date_gmt":"2017-05-09T13:27:17","guid":{"rendered":"http:\/\/www.richardmudhar.com\/blog\/?p=2914"},"modified":"2017-05-16T22:40:32","modified_gmt":"2017-05-16T22:40:32","slug":"building-the-mind-mirror-filter-bank","status":"publish","type":"post","link":"https:\/\/www.richardmudhar.com\/blog\/2017\/05\/building-the-mind-mirror-filter-bank\/","title":{"rendered":"Building the Mind Mirror filter bank"},"content":{"rendered":"<p>Drafting out the Mind Mirror analogue filters, scaling values to the nearest good combination of series resistors looks good at 1% tolerances of resistors and capacitances, according to LTspice<\/p>\n<figure id=\"attachment_2916\" aria-describedby=\"caption-attachment-2916\" style=\"width: 550px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.richardmudhar.com\/blog\/wp-content\/uploads\/2017\/05\/1705_mm_mc1pc.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-2916\" src=\"https:\/\/i0.wp.com\/www.richardmudhar.com\/blog\/wp-content\/uploads\/2017\/05\/1705_mm_mc1pc-550x389.png?resize=550%2C389\" alt=\"\" width=\"550\" height=\"389\" srcset=\"https:\/\/i0.wp.com\/www.richardmudhar.com\/blog\/wp-content\/uploads\/2017\/05\/1705_mm_mc1pc.png?resize=550%2C389&amp;ssl=1 550w, https:\/\/i0.wp.com\/www.richardmudhar.com\/blog\/wp-content\/uploads\/2017\/05\/1705_mm_mc1pc.png?w=590&amp;ssl=1 590w\" sizes=\"auto, (max-width: 550px) 85vw, 550px\" \/><\/a><figcaption id=\"caption-attachment-2916\" class=\"wp-caption-text\">Monte Carlo simulation at 1% tolerance<\/figcaption><\/figure>\n<p>but realistically the capacitance tolerances are 10% although resistors are 5%, and that&#8217;s makes a mess of some channels<\/p>\n<figure id=\"attachment_2918\" aria-describedby=\"caption-attachment-2918\" style=\"width: 550px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.richardmudhar.com\/blog\/wp-content\/uploads\/2017\/05\/1705_mm_mc5-10pc.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-2918\" src=\"https:\/\/i0.wp.com\/www.richardmudhar.com\/blog\/wp-content\/uploads\/2017\/05\/1705_mm_mc5-10pc-550x389.png?resize=550%2C389\" alt=\"\" width=\"550\" height=\"389\" srcset=\"https:\/\/i0.wp.com\/www.richardmudhar.com\/blog\/wp-content\/uploads\/2017\/05\/1705_mm_mc5-10pc.png?resize=550%2C389&amp;ssl=1 550w, https:\/\/i0.wp.com\/www.richardmudhar.com\/blog\/wp-content\/uploads\/2017\/05\/1705_mm_mc5-10pc.png?w=590&amp;ssl=1 590w\" sizes=\"auto, (max-width: 550px) 85vw, 550px\" \/><\/a><figcaption id=\"caption-attachment-2918\" class=\"wp-caption-text\">Monte Carlo simulation with resistors at 5%, capacitors at 10%<\/figcaption><\/figure>\n<p>in particular the 6,7.5, 9, 10.5, 12.5 and 19, 24, 30 and 38Hz channels. These are simulated using multiple-feedback bandpass filters (MFBP). I then simulated the same spread on the highest Q so most sensitive 9Hz band on the dual amplifier bandpass topology (DABP) and the state variable topology (SVBP) using three opamps per stage.<\/p>\n<figure id=\"attachment_2931\" aria-describedby=\"caption-attachment-2931\" style=\"width: 550px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.richardmudhar.com\/blog\/wp-content\/uploads\/2017\/05\/1705_filtersim.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-2931\" src=\"https:\/\/i0.wp.com\/www.richardmudhar.com\/blog\/wp-content\/uploads\/2017\/05\/1705_filtersim-550x357.png?resize=550%2C357\" alt=\"\" width=\"550\" height=\"357\" srcset=\"https:\/\/i0.wp.com\/www.richardmudhar.com\/blog\/wp-content\/uploads\/2017\/05\/1705_filtersim.png?resize=550%2C357&amp;ssl=1 550w, https:\/\/i0.wp.com\/www.richardmudhar.com\/blog\/wp-content\/uploads\/2017\/05\/1705_filtersim.png?resize=768%2C499&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.richardmudhar.com\/blog\/wp-content\/uploads\/2017\/05\/1705_filtersim.png?resize=624%2C405&amp;ssl=1 624w, https:\/\/i0.wp.com\/www.richardmudhar.com\/blog\/wp-content\/uploads\/2017\/05\/1705_filtersim.png?w=958&amp;ssl=1 958w\" sizes=\"auto, (max-width: 550px) 85vw, 550px\" \/><\/a><figcaption id=\"caption-attachment-2931\" class=\"wp-caption-text\">the DABP and SVBP simulated filters, SVBP on top. The funky values are so the Monte Carlo simulation can tinker with the values between runs<\/figcaption><\/figure>\n<p>Both the latter are meant to have a lower sensitivity to tolerances, and both have the advantage of having a defined gain, whereas the MFBP gain varies quite dramatically with fractional bandwidth and Q.<\/p>\n<figure id=\"attachment_2919\" aria-describedby=\"caption-attachment-2919\" style=\"width: 455px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/www.richardmudhar.com\/blog\/wp-content\/uploads\/2017\/05\/1705_mm_top.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-2919\" src=\"https:\/\/i0.wp.com\/www.richardmudhar.com\/blog\/wp-content\/uploads\/2017\/05\/1705_mm_top.png?resize=455%2C417\" alt=\"\" width=\"455\" height=\"417\" \/><\/a><figcaption id=\"caption-attachment-2919\" class=\"wp-caption-text\">sensitivity of the topologies, blue is the DABP, green is the MFBP and red is the SVBP<\/figcaption><\/figure>\n<p>There&#8217;s not much to be won here with the different topologies regarding sensitivity to tolerances, which surprised me. Williams states that the DABP is less sensitive to component tolerances than the MFBP and the SVBP less still. Examining the SVBP I got a variation in level of 5dB, the MFBP of 2.4dB and the DABP of 3.07. I have the suspicion I will need to tune these, in which case the DABP is easier, since the MFBP has interaction between fc and Q in tuning, as well as a wider spread of resistor values with Q\u00b2 as opposed to with Q in the DABP. However, that is 14ch \u00d7 2 stages \u00d7 2 sides = 56 pots or S.O.T. resistors \ud83d\ude09 As <a href=\"http:\/\/www.mindmirroreeg.com\/w\/equipment\/mm3\/unique.htm\">they said<\/a><\/p>\n<blockquote><p>The original analogue filters in Mind Mirrors 1 and 2 were precise but expensive to manufacture. The digital Band Pass filters parameters were modelled on the band pass characteristics of the analogue filters, and were able to more accurately guarantee the performance of the filters.<\/p><\/blockquote>\n<p>Lining up the analogue filters isn&#8217;t too hard &#8211; Williams [ref]Electronic Filter Design Handbook, A Williams, McGraw-Hill, 1981, p5-46[\/ref] says set the input frequency to be the desired centre frequency, monitor the input and output of the filter on a scope set to XY mode and adjust filter centre frequency until the Lissajous figure closes to a straight line. The thought of doing this 56 times does not fill me with joy, however. So one last time, how about DSP?<!--more--><\/p>\n<h4>The siren song of DSP<\/h4>\n<p>Certainly if you&#8217;re going to make more than one you&#8217;d go DSP, even I am tempted along the <a href=\"http:\/\/www.microchip.com\/wwwproducts\/en\/dsPIC33EP32MC202\">DSP route<\/a> seeing the effect of tolerances on simulation, but that would make the whole thing too dear, and I have no DSP development system. It is possible to transform the analogue filters into IIR digital domain filters using the bilinear transformation so there&#8217;s no particular magic about getting a DSP implementation, apart from the learning curve and the price for a one-off.<\/p>\n<p>I could use a Raspberry Pi and something like <a href=\"https:\/\/wiki.gnuradio.org\/index.php\/What_is_GNU_Radio%3F\">GNURadio <\/a>to do that job. Power consumption will skyrocket, but I get to forget about tuning the filters. Alternatively something like <a href=\"http:\/\/www.gnu.org\/software\/octave\/\">octave with the signal package<\/a> might work, but I haven&#8217;t convinced myself that this will display in real time. There also seems to be <a href=\"https:\/\/www.quora.com\/Why-does-a-digital-IIR-band-pass-filter-become-unstable-when-the-cut-off-frequencies-are-specified-well-below-the-sampling-frequency\">some degree of hurt available with IIR filters<\/a> &#8211; GNURadio focuses on FIR filters and doesn&#8217;t seem to feature IIR very much. Perhaps because of that hurt \ud83d\ude09<\/p>\n<p>The trouble is that I am a total noob with DSP, and to match the Mind Mirror shapes and delays I need to transform the analogue filters, which means IIR from the maths. And IIR seems to be the area that causes noobs trouble, in terms of the filters not settling due to truncation errors.<\/p>\n<p>The obvious way is to use a FFT, or more likely the DFT implementation., but the catch at these low frequencies is that to get the frequency resolution to match the older filters I&#8217;d need sub-1Hz resolution. The DFT frequency resolution is fs\/N. So imagine I sample at 1000Hz I need 1000 samples before I get any output, giving me a 1s latency. This seems to be the basis of the <a href=\"http:\/\/www.mindmirroreeg.com\/w\/equipment\/mm3\/unique.htm\">issues in using FFT to replicate the Mind mirror results<\/a>. There is the very real possibility of Mind Mirror <a href=\"http:\/\/www.yourdictionary.com\/talking-one-s-book\">talking their book<\/a> of course \ud83d\ude09<\/p>\n<p>Or I could <a href=\"http:\/\/forum.arduino.cc\/index.php\/topic,164915\">try an Arduino<\/a>. With an analogue antialiasing filter of about 200Hz and a sampling rate of 1000Hz I could use IIR filters from\u00a0<a href=\"http:\/\/www.schwietering.com\/jayduino\/filtuino\/\">http:\/\/www.schwietering.com\/jayduino\/filtuino\/<\/a> and sample on change of millis(), the Arduino could then also do the LED display. Depending on how long the floating point maths takes I might be able to run two channels on the Arduino, so\u00a0 I will end up with a rig with 14 Arduino chips. Sampling with the Arduino is doable, <a href=\"http:\/\/yaab-arduino.blogspot.co.uk\/2015\/02\/fast-sampling-from-analog-input.html\">as shown here<\/a>.<\/p>\n<p>If I&#8217;m going to go microcontroller I could also consider a PIC, a 16F88 is \u00a32.50 at 10-off prices, has onboard A\/D. I use JAL as a high-level language for PICs because I&#8217;m not prepared to pay out \u00a3200 for a C compiler for those, so <a href=\"http:\/\/www.casadeyork.com\/jalv2\/jalv2\/c108.html#AEN110\">floating point is resource-hungry<\/a>, but I understand interrupts etc on the PIC 16 series, where I don&#8217;t really on Arduino. The ATMega328 used in Arduino Uno is a similar price, which sort of favours the Arduino as there&#8217;s more example code and the sorta C compiler is free. But I get to either buy preprogrammed Arduino chips which are dearer or I get to buy an AVR programmer for about \u00a320 to\u00a0 program the Arduino bootloader onto vanilla ATmega 328s<\/p>\n<p>Every time I look at everything else I need to do to make this happen digitally I am drawn back to the analogue solution. Lining up filters is tedious, particularly at such low frequencies, but easy.\u00a0 I have a LCR meter so I could screen the capacitors to get a better tolerance, I could probably match them to 1% and recalculate the resistors for whatever value they are measured at. The DABP can be done with a single LM324 per channel, at 50p rather than \u00a32.50 Arduino, and LM3914s are to be had cheaply from China. But before I actually go that way, I will take a step back, and investigate again what people have already done in this space. Researching this post picked up a fair amount of open source work in this field, and some of it looked like it would support IIR filtering.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Drafting out the Mind Mirror analogue filters, scaling values to the nearest good combination of series resistors looks good at 1% tolerances of resistors and capacitances, according to LTspice but realistically the capacitance tolerances are 10% although resistors are 5%, and that&#8217;s makes a mess of some channels in particular the 6,7.5, 9, 10.5, 12.5 &hellip; <a href=\"https:\/\/www.richardmudhar.com\/blog\/2017\/05\/building-the-mind-mirror-filter-bank\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Building the Mind Mirror filter bank&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[57,334],"tags":[331,332,333],"class_list":["post-2914","post","type-post","status-publish","format-standard","hentry","category-electronics","category-strange","tag-biofeedback","tag-eeg","tag-mind-mirror"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p5aOO7-L0","jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.richardmudhar.com\/blog\/wp-json\/wp\/v2\/posts\/2914","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.richardmudhar.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.richardmudhar.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.richardmudhar.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.richardmudhar.com\/blog\/wp-json\/wp\/v2\/comments?post=2914"}],"version-history":[{"count":13,"href":"https:\/\/www.richardmudhar.com\/blog\/wp-json\/wp\/v2\/posts\/2914\/revisions"}],"predecessor-version":[{"id":2956,"href":"https:\/\/www.richardmudhar.com\/blog\/wp-json\/wp\/v2\/posts\/2914\/revisions\/2956"}],"wp:attachment":[{"href":"https:\/\/www.richardmudhar.com\/blog\/wp-json\/wp\/v2\/media?parent=2914"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.richardmudhar.com\/blog\/wp-json\/wp\/v2\/categories?post=2914"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.richardmudhar.com\/blog\/wp-json\/wp\/v2\/tags?post=2914"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}