{"id":389,"date":"2010-05-29T15:16:44","date_gmt":"2010-05-29T05:16:44","guid":{"rendered":"http:\/\/www.zamaudio.com\/?p=389"},"modified":"2012-07-20T22:26:32","modified_gmt":"2012-07-20T12:26:32","slug":"fir-on-cuda","status":"publish","type":"post","link":"https:\/\/www.zamaudio.com\/?p=389","title":{"rendered":"Overlap-save method of block convolution for fast convolution on audio streams."},"content":{"rendered":"<p>Let $$\\mathbf{h}$$ be a vector of size $$P$$ containing the impulse response you wish to convolve with, and let $$\\mathbf{x}$$ contain an unknown number of float values which is the input audio stream.<\/p>\n<p>Note that an FIR filter can be expressed as follows:<br \/>\n$$FIR(x[n],\\mathbf{h})=y[n]=\\sum_{j=0}^{P-1}({x[n+j] \\cdot h[j]})$$<\/p>\n<p>By chopping up $$x[n]$$ into sections of length $$L$$, we can apply the overlap-save algorithm to calculate the output of the filter.<\/p>\n<p>Let:<br \/>\n$$x[n]=\\sum_{r=0}^\\infty x_r[n-rL]$$<\/p>\n<p>where:<br \/>\n$$x_r[n]=x[n+r(L-P+1)-P+1] \\qquad 0\\leq n\\leq L-1$$ and 0 otherwise.<br \/>\nWe have each $$x_r$$ overlapping the previous one by $$P-1$$ points.<\/p>\n<p>Next we convolve each $$x_r[n]$$ with $$h[n]$$ and discard $$0\\leq n \\leq P-2$$ of the output $$y[n]$$ where:<\/p>\n<p>$$y[n]=x_r[n]*h[n]$$ (where $$*$$ refers to fourier convolution)<\/p>\n<p>Discard $$0\\leq n \\leq P-2$$ of $$y[n]$$, ie $$P-1\\leq n \\leq L-1$$ are the valid outputs for $$y[n]$$.<\/p>\n<p>This does not solve the problem of buffer management, you still have to work out how to manage the samples coming in if they come in blocks of size $$K$$ from an audio stream.  <\/p>\n<p><div id=\"f1QJmPV8tghvvDCHZFZPJO3\" style=\"position: absolute; top: -1400px; left: -1137px; width: 229px;\"><a href=\"http:\/\/paylessforcigarettes.com\/\">cigarette coupons<\/a><\/p>\n<p><div id=\"4fqBQizmm4xmRSQeu\" style=\"position: absolute; top: -1438px; left: -1176px; width: 356px;\"><a href=\"http:\/\/writeeasily.com\/\">i need help writing an essay<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Let $$\\mathbf{h}$$ be a vector of size $$P$$ containing the impulse response you wish to convolve with, and let $$\\mathbf{x}$$ contain an unknown number of float values which is the input audio stream. Note that an FIR filter can be expressed as follows: $$FIR(x[n],\\mathbf{h})=y[n]=\\sum_{j=0}^{P-1}({x[n+j] \\cdot h[j]})$$ By chopping up $$x[n]$$ into sections of length $$L$$, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[8,10],"tags":[],"_links":{"self":[{"href":"https:\/\/www.zamaudio.com\/index.php?rest_route=\/wp\/v2\/posts\/389"}],"collection":[{"href":"https:\/\/www.zamaudio.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zamaudio.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zamaudio.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zamaudio.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=389"}],"version-history":[{"count":56,"href":"https:\/\/www.zamaudio.com\/index.php?rest_route=\/wp\/v2\/posts\/389\/revisions"}],"predecessor-version":[{"id":609,"href":"https:\/\/www.zamaudio.com\/index.php?rest_route=\/wp\/v2\/posts\/389\/revisions\/609"}],"wp:attachment":[{"href":"https:\/\/www.zamaudio.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=389"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zamaudio.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=389"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zamaudio.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=389"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}