{"id":641,"date":"2017-05-27T10:32:55","date_gmt":"2017-05-27T17:32:55","guid":{"rendered":"http:\/\/www.earlevel.com\/main\/?p=641"},"modified":"2019-02-24T15:18:36","modified_gmt":"2019-02-24T23:18:36","slug":"amp-simulation-oversampling","status":"publish","type":"post","link":"https:\/\/www.earlevel.com\/main\/2017\/05\/27\/amp-simulation-oversampling\/","title":{"rendered":"Amp simulation oversampling"},"content":{"rendered":"<p>In tandem with our last article on <a href=\"\/main\/2017\/05\/26\/guitar-amp-simulation\/\">Guitar amp simulation<\/a>, this article gives a step by step view of the sampling and rate conversion processes, with a look at the frequency spectrum.<\/p>\n<h3>From guitar to digital<\/h3>\n<p>The first two charts\u00a0embody\u00a0the initial sampling of the analog signal. It&#8217;s done in one step, from your analog-to-digital converter,\u00a0but it&#8217;s a two-part process. First, a lowpass filter clears everything from half the sample rate up\u2014something we must do to avoid higher frequencies aliasing into our audio band when sampled.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-650\" src=\"\/main\/wp-content\/uploads\/2017\/05\/OS1.png\" alt=\"\" width=\"160\" height=\"71\" \/><\/p>\n<p>Then the signal is digitized. This creates\u00a0repeating images of the positive and negative frequencies that extend upward without end. After this, we&#8217;ll look only at frequencies between 0 Hz and the sampling frequency, but it&#8217;s important to understand that these images are there, nonetheless.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-651\" src=\"\/main\/wp-content\/uploads\/2017\/05\/OS2.png\" alt=\"\" width=\"388\" height=\"71\" srcset=\"https:\/\/www.earlevel.com\/main\/wp-content\/uploads\/2017\/05\/OS2.png 388w, https:\/\/www.earlevel.com\/main\/wp-content\/uploads\/2017\/05\/OS2-300x55.png 300w\" sizes=\"(max-width: 388px) 100vw, 388px\" \/><\/p>\n<p>If we don&#8217;t need more frequency headroom, we can do our signal processing on the samples we have. In fact, we want to do as much as we can at the lower sample rate. In the case of a guitar amp, we would process any tone controls that come before the &#8220;tube&#8221;, and other things like\u00a0DC blocking and noise gating. And we can do our (non-saturating) gain stage here (assuming floating point).<\/p>\n<h3>Higher rate processing<\/h3>\n<p>After initial processing and gain, it&#8217;s time for saturation. For this non-linear process, we need frequency headroom. The first step is to increase the rate by inserting zero-magnitude samples. Though I suggested starting with 8x upsampling in the guitar amp article, this exercise shows 4x, in order to better accommodate page\u00a0constraints. We place three zero-samples between each existing sample to bring it up 4x. This only raises the sample rate\u2014we have four samples in the same period that we used to have one. Since the spectrum is not altered, the aliases are still there.<\/p>\n<p><a href=\"\/main\/wp-content\/uploads\/2017\/05\/OS3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-652\" src=\"\/main\/wp-content\/uploads\/2017\/05\/OS3.png\" alt=\"\" width=\"587\" height=\"72\" srcset=\"https:\/\/www.earlevel.com\/main\/wp-content\/uploads\/2017\/05\/OS3.png 587w, https:\/\/www.earlevel.com\/main\/wp-content\/uploads\/2017\/05\/OS3-300x37.png 300w\" sizes=\"(max-width: 587px) 100vw, 587px\" \/><\/a><\/p>\n<p>Part two of the sample rate conversion process is to use a lowpass filter to clear everything above our original audio band. (In reality, we optimize the zero insertion and filtering into a single process, to take advantage of multiplies by zero that we can skip. Note we usually use a linear-phase FIR for this step, in order to preserve the wave shape for the saturator.) Now we see our headroom.<a href=\"\/main\/wp-content\/uploads\/2017\/05\/OS4.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-653\" src=\"\/main\/wp-content\/uploads\/2017\/05\/OS4.png\" alt=\"\" width=\"586\" height=\"73\" srcset=\"https:\/\/www.earlevel.com\/main\/wp-content\/uploads\/2017\/05\/OS4.png 586w, https:\/\/www.earlevel.com\/main\/wp-content\/uploads\/2017\/05\/OS4-300x37.png 300w\" sizes=\"(max-width: 586px) 100vw, 586px\" \/><\/a><\/p>\n<p>After our saturation stage, we&#8217;ve created new harmonics. As long as they are at a sufficiently low level by the time they reach\u00a0the sample rate minus our final audio bandwidth, the aliased version won&#8217;t pollute our audio band.<\/p>\n<p><a href=\"\/main\/wp-content\/uploads\/2017\/05\/OS5.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-654\" src=\"\/main\/wp-content\/uploads\/2017\/05\/OS5.png\" alt=\"\" width=\"587\" height=\"72\" srcset=\"https:\/\/www.earlevel.com\/main\/wp-content\/uploads\/2017\/05\/OS5.png 587w, https:\/\/www.earlevel.com\/main\/wp-content\/uploads\/2017\/05\/OS5-300x37.png 300w\" sizes=\"(max-width: 587px) 100vw, 587px\" \/><\/a><\/p>\n<h3>Back to normal<\/h3>\n<p>Done with our more expensive high-rate signal processing,\u00a0we can drop back to our original sample rate for the rest. The first step is to run our lowpass filter again, to clear everything above our audio band.<\/p>\n<p><a href=\"\/main\/wp-content\/uploads\/2017\/05\/OS6.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-655\" src=\"\/main\/wp-content\/uploads\/2017\/05\/OS6.png\" alt=\"\" width=\"584\" height=\"71\" srcset=\"https:\/\/www.earlevel.com\/main\/wp-content\/uploads\/2017\/05\/OS6.png 584w, https:\/\/www.earlevel.com\/main\/wp-content\/uploads\/2017\/05\/OS6-300x36.png 300w\" sizes=\"(max-width: 584px) 100vw, 584px\" \/><\/a><\/p>\n<p>Part two is the downsampling process\u2014we simply keep one sample, discard three, and repeat. Why did we bother calculating them? Because we needed them ahead of the lowpass filter. But, here also, we can optimize these two down-conversion steps into one, and save needless calculation.<\/p>\n<p><a href=\"\/main\/wp-content\/uploads\/2017\/05\/OS7.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-656\" src=\"\/main\/wp-content\/uploads\/2017\/05\/OS7.png\" alt=\"\" width=\"156\" height=\"71\" \/><\/a><\/p>\n<h3>Final processing<\/h3>\n<p>From here, we handle other linear processes\u2014any filtering and tone controls the follow the tube stage, effects such spring reverb, and finally the speaker cabinet simulation. In the end, we send it\u00a0to our digital-to-analog converter, which itself has a lowpass filter to remove the aliased copies.<\/p>\n<p><a href=\"\/main\/wp-content\/uploads\/2017\/05\/OS8.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-657\" src=\"\/main\/wp-content\/uploads\/2017\/05\/OS8.png\" alt=\"\" width=\"152\" height=\"68\" srcset=\"https:\/\/www.earlevel.com\/main\/wp-content\/uploads\/2017\/05\/OS8.png 152w, https:\/\/www.earlevel.com\/main\/wp-content\/uploads\/2017\/05\/OS8-150x68.png 150w\" sizes=\"(max-width: 152px) 100vw, 152px\" \/><\/a><\/p>\n<p>And enjoy listening.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In tandem with our last article on Guitar amp simulation, this article gives a step by step view of the sampling and rate conversion processes, with a look at the frequency spectrum. From guitar to digital The first two charts\u00a0embody\u00a0the &hellip; <a href=\"https:\/\/www.earlevel.com\/main\/2017\/05\/27\/amp-simulation-oversampling\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,33,35,6],"tags":[],"_links":{"self":[{"href":"https:\/\/www.earlevel.com\/main\/wp-json\/wp\/v2\/posts\/641"}],"collection":[{"href":"https:\/\/www.earlevel.com\/main\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.earlevel.com\/main\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.earlevel.com\/main\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.earlevel.com\/main\/wp-json\/wp\/v2\/comments?post=641"}],"version-history":[{"count":11,"href":"https:\/\/www.earlevel.com\/main\/wp-json\/wp\/v2\/posts\/641\/revisions"}],"predecessor-version":[{"id":844,"href":"https:\/\/www.earlevel.com\/main\/wp-json\/wp\/v2\/posts\/641\/revisions\/844"}],"wp:attachment":[{"href":"https:\/\/www.earlevel.com\/main\/wp-json\/wp\/v2\/media?parent=641"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.earlevel.com\/main\/wp-json\/wp\/v2\/categories?post=641"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.earlevel.com\/main\/wp-json\/wp\/v2\/tags?post=641"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}