{"id":748,"date":"2018-09-21T16:23:27","date_gmt":"2018-09-21T23:23:27","guid":{"rendered":"http:\/\/www.earlevel.com\/main\/?p=748"},"modified":"2018-09-21T16:23:27","modified_gmt":"2018-09-21T23:23:27","slug":"sampling-theory-the-best-explanation-youve-ever-heard-end-notes","status":"publish","type":"post","link":"https:\/\/www.earlevel.com\/main\/2018\/09\/21\/sampling-theory-the-best-explanation-youve-ever-heard-end-notes\/","title":{"rendered":"Sampling theory, the best explanation you\u2019ve ever heard\u2014End notes"},"content":{"rendered":"<p><em>A few words before moving on to other topics&#8230;<\/em><\/p>\n<p>We\u2019ve looked at why digital sample represent ideal impulses, and why any point between samples represents a value of zero. And, as a result, audio samples don\u2019t represent the audio itself, but a modulated version of the audio.<\/p>\n<p>Why is helpful to understand these points?<\/p>\n<h3>Critical sampling<\/h3>\n<p>First, it gives clear and intuitive answers for why digital audio behaves certain ways than do more typical explanations. For instance, it makes this puzzle trivial:<\/p>\n<p>People ask why the sample rate needs to be double the frequency of the highest signal frequency that we want to preserve. Often the reply is that it needs to be just <i>above<\/i> double the highest frequency of interest, to avoid aliasing. But why? And how much higher? At this point, someone mentions something about wagon wheels turning the wrong way in movies. Or shows a graph with two sine waves of different frequencies intersecting the same sample points. So unsatisfying.<\/p>\n<p>If you consider that the signal is amplitude modulated in the digitization process, you need only see that the sidebands would start overlapping at exactly half the sample rate. To keep them from overlapping, all frequencies must be below half the sample rate, giving each cycle more than two samples.<\/p>\n<h3>Multistage conversion<\/h3>\n<p>And integer sample rate conversion choices are easier to make. Especially for multistage conversion. We often use multistage conversion to improve efficiency. Like performing 8x upsampling as three 2x stages. If that sounds like three times the work, it isn\u2019t, because the higher relative cutoffs of the filters make for fewer coefficients, balancing out with the total operations for 8x. But we can do more than break even by optimizing each stage\u2014the earlier stages can be a bit sloppy as long as everything is tidy by the last stage\u2019s output. Somewhat like doing a big cleanup on a house in multiple passes versus one.<\/p>\n<p>Perhaps this is a good place to note that you might see chatroom posts where someone says that instead of inserting zeros and filtering, they prefer to use a polyphase filter. There is no difference\u2014a polyphase filter in this case is simply an algorithm that upsamples and filters. Any seasoned programmer will notice that there is no need to explicitly place zeros between samples, then run all samples through an FIR, because the zero samples result in a zero product; optimizing the code to skip the zero operations results in a polyphase filter.<\/p>\n<h3>Optimization example<\/h3>\n<p>An understanding of why we need to filter rate conversions can help us optimize DSP processes. For example, someone posted a question on a DSP board recently. They were using EQ filters designed by the bilinear transform, which have a pinching effect near half the sample rate (due to zeros at the Nyquist frequency). They didn\u2019t need additional frequency headroom per se\u2014the filters are linear\u2014but they wanted to oversample by 2x to avoid the shape distortion of peaking EQ filters. (Note there are methods to reduce or avoid such distortion of the filter shape, but this is a good example.)<\/p>\n<p>Let\u2019s say we\u2019re using a 48 kHz sample rate. Typically we\u2019d raise the sample rate to 96k by inserting zeros every other sample and then lowpass filtering below 24k. Then we\u2019d do our processing (EQ filtering). Finally, we\u2019d take it back to 48k by lowpass filtering below 24k and discarding every other sample. But in this case, our processing step is linear (linear EQ filters), so it doesn\u2019t create new frequencies. That means we can skip one of the lowpass filtering stages. It doesn\u2019t matter whether we lowpass filter before or after the EQ processing, but we don\u2019t need both. That\u2019s a substantial savings.<\/p>\n<h3>Another example<\/h3>\n<p>Let\u2019s say we create an audio effect such as an amp simulator, which has a non-linear process that requires running at a higher sample rate to reduce audible aliasing. We run our initial linear processes, such as tone controls, then upsample and run our non-linear processes (an overdriven tube simulation!). But in this case we conclude with a speaker cabinet simulator, which is a linear process (via convolution or other type of filtering). Guitar and bass cabinets use large speakers (typically 8\u201d and up, often 10\u201d or 12\u201d for guitar), with frequency responses that drops steeply above around 5 kHz. Understanding how the downsampling process works, we might choose to eliminate the downsampling filter stage altogether, as superfluous, or at least save cycles with a simplified filter with relaxed requirements.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A few words before moving on to other topics&#8230; We\u2019ve looked at why digital sample represent ideal impulses, and why any point between samples represents a value of zero. And, as a result, audio samples don\u2019t represent the audio itself, &hellip; <a href=\"https:\/\/www.earlevel.com\/main\/2018\/09\/21\/sampling-theory-the-best-explanation-youve-ever-heard-end-notes\/\">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,7],"tags":[37],"_links":{"self":[{"href":"https:\/\/www.earlevel.com\/main\/wp-json\/wp\/v2\/posts\/748"}],"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=748"}],"version-history":[{"count":3,"href":"https:\/\/www.earlevel.com\/main\/wp-json\/wp\/v2\/posts\/748\/revisions"}],"predecessor-version":[{"id":751,"href":"https:\/\/www.earlevel.com\/main\/wp-json\/wp\/v2\/posts\/748\/revisions\/751"}],"wp:attachment":[{"href":"https:\/\/www.earlevel.com\/main\/wp-json\/wp\/v2\/media?parent=748"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.earlevel.com\/main\/wp-json\/wp\/v2\/categories?post=748"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.earlevel.com\/main\/wp-json\/wp\/v2\/tags?post=748"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}