{"id":137,"date":"2016-02-05T05:17:21","date_gmt":"2016-02-05T05:17:21","guid":{"rendered":"http:\/\/weegreenblobbie.com\/?p=137"},"modified":"2016-02-05T05:17:21","modified_gmt":"2016-02-05T05:17:21","slug":"nsoundbiquadfilterbank-work-in-progress","status":"publish","type":"post","link":"http:\/\/weegreenblobbie.com\/?p=137","title":{"rendered":"Nsound::biquad::FilterBank Work In Progress"},"content":{"rendered":"<p>I&#8217;ve made some good progress on a biquad filter bank on this <a href=\"https:\/\/github.com\/weegreenblobbie\/nsound\/tree\/feature\/biquad-filters\">branch<\/a>. \u00a0I&#8217;ve been able to replicate Figure 10 from this <a href=\"http:\/\/www.ece.rutgers.edu\/~orfanidi\/ece346\/hpeq.pdf\">reference<\/a>:<\/p>\n<p><a href=\"http:\/\/weegreenblobbie.com\/wp-content\/uploads\/2016\/02\/nsound_cpp_figure_10.png\" rel=\"attachment wp-att-138\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-138 aligncenter\" src=\"http:\/\/weegreenblobbie.com\/wp-content\/uploads\/2016\/02\/nsound_cpp_figure_10.png\" alt=\"nsound_cpp_figure_10\" width=\"600\" height=\"452\" srcset=\"http:\/\/weegreenblobbie.com\/wp-content\/uploads\/2016\/02\/nsound_cpp_figure_10.png 812w, http:\/\/weegreenblobbie.com\/wp-content\/uploads\/2016\/02\/nsound_cpp_figure_10-300x226.png 300w, http:\/\/weegreenblobbie.com\/wp-content\/uploads\/2016\/02\/nsound_cpp_figure_10-768x579.png 768w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<p>That&#8217;s a filter bank with 4\u00a0individual biquad filters, here&#8217;s the\u00a0C++ code that produced the plot:<\/p>\n<pre class=\"lang:c++ decode:true \" title=\"filter_bank_example.cpp\">#include &lt;Nsound\/NsoundAll.h&gt;\r\n#include &lt;Nsound\/biquad\/FilterBank.hpp&gt;\r\n\r\n#include &lt;iostream&gt;\r\n\r\nusing std::cout;\r\n\r\nusing namespace Nsound;\r\nusing namespace Nsound::biquad;\r\n\r\nint\r\nmain(void)\r\n{\r\n float64 sr = 48000; \/\/ sample rate\r\n\r\n auto khz = 1000.0;\r\n\r\n Biquad bq0(sr, 0*khz, 1*khz,  9,  6, 0, 4);\r\n Biquad bq1(sr, 4*khz, 2*khz, 12,  9, 0, 4);\r\n Biquad bq2(sr, 9*khz, 2*khz, -6, -3, 0, 4);\r\n Biquad bq3(sr,  sr\/2, 8*khz,  6,  3, 0, 4);\r\n\r\n FilterBank fb(sr);\r\n\r\n fb.add(bq0);\r\n fb.add(bq1);\r\n fb.add(bq2);\r\n fb.add(bq3);\r\n\r\n cout\r\n   &lt;&lt; \"-----------------------------------------------------------\\n\"\r\n   &lt;&lt; \"FilterBank: fb.to_json()\\n\"\r\n   &lt;&lt; \"-----------------------------------------------------------\\n\"\r\n   &lt;&lt; fb.to_json() &lt;&lt; \"\\n\";\r\n\r\n fb.plot();\r\n\r\n Plotter pylab;\r\n pylab.ylim(-7, 13);\r\n pylab.title(\"N=4, Butterworth\");\r\n\r\n Plotter::show();\r\n\r\n return 0;\r\n}<\/pre>\n<p>The program also produces this output:<\/p>\n<pre class=\"lang:js decode:true\" title=\"stdout\">-----------------------------------------------------------\r\nFilterBank: fb.to_json()\r\n-----------------------------------------------------------\r\n[\r\n  {\r\n    \"band_width_hz\": 1000,\r\n    \"freq_center_hz\": 0,\r\n    \"gain_db_at_band_width\": 6,\r\n    \"gain_db_at_fc\": 9,\r\n    \"gain_db_baseline\": 0,\r\n    \"order\": 4,\r\n    \"samplerate\": 48000\r\n  },\r\n  {\r\n    \"band_width_hz\": 2000,\r\n    \"freq_center_hz\": 4000,\r\n    \"gain_db_at_band_width\": 9,\r\n    \"gain_db_at_fc\": 12,\r\n    \"gain_db_baseline\": 0,\r\n    \"order\": 4,\r\n    \"samplerate\": 48000\r\n  },\r\n  {\r\n    \"band_width_hz\": 2000,\r\n    \"freq_center_hz\": 9000,\r\n    \"gain_db_at_band_width\": -3,\r\n    \"gain_db_at_fc\": -6,\r\n    \"gain_db_baseline\": 0,\r\n    \"order\": 4,\r\n    \"samplerate\": 48000\r\n  },\r\n  {\r\n    \"band_width_hz\": 8000,\r\n    \"freq_center_hz\": 24000,\r\n    \"gain_db_at_band_width\": 3,\r\n    \"gain_db_at_fc\": 6,\r\n    \"gain_db_baseline\": 0,\r\n    \"order\": 4,\r\n    \"samplerate\": 48000\r\n  }\r\n]<\/pre>\n<p>This work is to enable a parametric equalizer application, where an audio sample can\u00a0be loaded and filtered in real-time while the user adjusts the filter parameters.<\/p>\n<p>I&#8217;ve been using the <a href=\"https:\/\/github.com\/kazuho\/picojson\">picojson<\/a> library and it was been really <a href=\"https:\/\/github.com\/weegreenblobbie\/nsound\/blob\/feature\/biquad-filters\/src\/Nsound\/biquad\/FilterBank.cpp#L371\">easy to use<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve made some good progress on a biquad filter bank on this branch. \u00a0I&#8217;ve been able to replicate Figure 10 from this reference: That&#8217;s a filter bank with 4\u00a0individual biquad filters, here&#8217;s the\u00a0C++ code that produced the plot: #include &lt;Nsound\/NsoundAll.h&gt; &hellip; <a href=\"http:\/\/weegreenblobbie.com\/?p=137\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,7],"tags":[],"class_list":["post-137","post","type-post","status-publish","format-standard","hentry","category-nsound","category-programming"],"_links":{"self":[{"href":"http:\/\/weegreenblobbie.com\/index.php?rest_route=\/wp\/v2\/posts\/137","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/weegreenblobbie.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/weegreenblobbie.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/weegreenblobbie.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/weegreenblobbie.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=137"}],"version-history":[{"count":10,"href":"http:\/\/weegreenblobbie.com\/index.php?rest_route=\/wp\/v2\/posts\/137\/revisions"}],"predecessor-version":[{"id":148,"href":"http:\/\/weegreenblobbie.com\/index.php?rest_route=\/wp\/v2\/posts\/137\/revisions\/148"}],"wp:attachment":[{"href":"http:\/\/weegreenblobbie.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=137"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/weegreenblobbie.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=137"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/weegreenblobbie.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=137"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}