{"id":8236,"date":"2024-10-01T15:54:14","date_gmt":"2024-10-01T13:54:14","guid":{"rendered":"http:\/\/www.tonmeister.ca\/wordpress\/?p=8236"},"modified":"2024-10-05T14:15:17","modified_gmt":"2024-10-05T12:15:17","slug":"aliasing-is-weird-part-1","status":"publish","type":"post","link":"http:\/\/www.tonmeister.ca\/wordpress\/2024\/10\/01\/aliasing-is-weird-part-1\/","title":{"rendered":"Aliasing is weird: Part 1"},"content":{"rendered":"\n<p>One of the best-known things about digital audio is the fact that you cannot record a signal that has a frequency that is higher than 1\/2 the sampling rate.<\/p>\n\n\n\n<p>Now, to be fair, that statement is not true. You CAN record a signal that has a frequency that is higher than 1\/2 the sampling rate. You just won&#8217;t be able to play it back properly, because what comes out of the playback will not be the original frequency, but an alias of it.<\/p>\n\n\n\n<p>If you record a one-spoked wheel with a series of photographs (in the old days, we called this &#8216;a movie&#8217;), the photos (the frames of the movie) might look something like this:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"169\" src=\"http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/wheel_01-1024x169.png\" alt=\"\" class=\"wp-image-8237\" style=\"width:840px;height:auto\" srcset=\"http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/wheel_01-1024x169.png 1024w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/wheel_01-300x50.png 300w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/wheel_01-768x127.png 768w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/wheel_01-1536x254.png 1536w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/wheel_01.png 1571w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>As you can see there, the wheel happens to be turning at a speed that results in it rotating 45\u00ba every frame.<\/p>\n\n\n\n<p>The equivalent of this in a digital audio world would be if we were recording a sine wave that rotated (yes&#8230;. rotated&#8230;) 45\u00ba every sample, like this:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/sine_01-1024x768.png\" alt=\"\" class=\"wp-image-8238\" srcset=\"http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/sine_01-1024x768.png 1024w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/sine_01-300x225.png 300w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/sine_01-768x576.png 768w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/sine_01.png 1120w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Notice that the red lines indicating the sample values are equivalent to the height of the spoke at the wheel rim in the first figure.<\/p>\n\n\n\n<p>If we speed up the wheel&#8217;s rotation so that it rotated 90\u00ba per frame, it looks like this:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"169\" src=\"http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/wheel_02-1024x169.png\" alt=\"\" class=\"wp-image-8239\" srcset=\"http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/wheel_02-1024x169.png 1024w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/wheel_02-300x50.png 300w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/wheel_02-768x127.png 768w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/wheel_02-1536x254.png 1536w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/wheel_02.png 1571w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>And the audio equivalent would look like this:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/sine_02-1024x768.png\" alt=\"\" class=\"wp-image-8240\" srcset=\"http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/sine_02-1024x768.png 1024w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/sine_02-300x225.png 300w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/sine_02-768x576.png 768w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/sine_02.png 1120w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Speeding up even more to 135\u00ba per frame, we get this:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"169\" src=\"http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/wheel_03-1024x169.png\" alt=\"\" class=\"wp-image-8241\" srcset=\"http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/wheel_03-1024x169.png 1024w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/wheel_03-300x50.png 300w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/wheel_03-768x127.png 768w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/wheel_03-1536x254.png 1536w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/wheel_03.png 1571w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>and this:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/sine_03-1024x768.png\" alt=\"\" class=\"wp-image-8242\" srcset=\"http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/sine_03-1024x768.png 1024w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/sine_03-300x225.png 300w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/sine_03-768x576.png 768w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/sine_03.png 1120w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Then we get to a magical speed where the wheel rotated 180\u00ba per frame. At this speed, it appears when we look at the playback of the film that the wheel has stopped, and it now has two spokes.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"169\" src=\"http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/wheel_04-1024x169.png\" alt=\"\" class=\"wp-image-8244\" srcset=\"http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/wheel_04-1024x169.png 1024w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/wheel_04-300x50.png 300w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/wheel_04-768x127.png 768w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/wheel_04-1536x254.png 1536w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/wheel_04.png 1571w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>In the audio equivalent, it looks like the result is that we have no output, as shown below.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/sine_04-1024x768.png\" alt=\"\" class=\"wp-image-8243\" srcset=\"http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/sine_04-1024x768.png 1024w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/sine_04-300x225.png 300w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/sine_04-768x576.png 768w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/sine_04.png 1120w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>However, this isn&#8217;t really true. It&#8217;s just an artefact of the fact that I chose to plot a sine wave. If I were to change the phase of this to be a cosine wave (at the same frequency) instead, for example, then it would definitely have an output.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/sine_04a-1024x768.png\" alt=\"\" class=\"wp-image-8245\" srcset=\"http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/sine_04a-1024x768.png 1024w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/sine_04a-300x225.png 300w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/sine_04a-768x576.png 768w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/sine_04a.png 1120w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>At this point, the frequency of the audio signal is 1\/2 the sampling rate.<\/p>\n\n\n\n<p>What happens if the wheel goes even faster (and audio signal&#8217;s frequency goes above this)?<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"169\" src=\"http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/wheel_05-1024x169.png\" alt=\"\" class=\"wp-image-8246\" srcset=\"http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/wheel_05-1024x169.png 1024w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/wheel_05-300x50.png 300w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/wheel_05-768x127.png 768w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/wheel_05-1536x254.png 1536w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/wheel_05.png 1571w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Notice that the wheel is now making more than a half-turn per frame. We can still record it. However, when we play it back, it doesn&#8217;t look like what happened. It looks like the wheel is going backwards like this:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"169\" src=\"http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/wheel_05a-1024x169.png\" alt=\"\" class=\"wp-image-8247\" srcset=\"http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/wheel_05a-1024x169.png 1024w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/wheel_05a-300x50.png 300w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/wheel_05a-768x127.png 768w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/wheel_05a-1536x254.png 1536w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/wheel_05a.png 1571w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Similarly, if we record a sine wave that has a frequency that is higher than 1\/2 the sampling rate like this:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/sine_05-1024x768.png\" alt=\"\" class=\"wp-image-8248\" srcset=\"http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/sine_05-1024x768.png 1024w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/sine_05-300x225.png 300w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/sine_05-768x576.png 768w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/sine_05.png 1120w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Then, when we play it back, we get a lower frequency that fits the samples, like this:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/sine_05a-1024x768.png\" alt=\"\" class=\"wp-image-8249\" srcset=\"http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/sine_05a-1024x768.png 1024w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/sine_05a-300x225.png 300w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/sine_05a-768x576.png 768w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/sine_05a.png 1120w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Just a little math<\/h2>\n\n\n\n<p>There is a simple way to calculate the frequency of the signal that you get out of the system if you know the sampling rate and the frequency of the signal that you tried to record.<\/p>\n\n\n\n<p>Let&#8217;s use the following abbreviations to make it easy to state:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Fs = Sampling rate<\/li>\n\n\n\n<li>F_in = frequency of the input signal<\/li>\n\n\n\n<li>F_out = frequency of the output signal<\/li>\n<\/ul>\n\n\n\n<p>IF<br>F_in &lt; Fs\/2<br>THEN<br>F_out = F_in<\/p>\n\n\n\n<p>IF<br>Fs &gt; F_in &gt; Fs\/2<br>THEN<br>F_out = Fs\/2 &#8211; (F_in &#8211; Fs\/2) = Fs &#8211; F_in<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Some examples:<\/h2>\n\n\n\n<p>If your sampling rate is 48 kHz, and you try to record a 25 kHz sine wave, then the signal that you will play back will be:<br>48000 &#8211; 25000 = 23000 Hz<\/p>\n\n\n\n<p>If your sampling rate is 48 kHz, and you try to record a 42 kHz sine wave, then the signal that you will play back will be:<br>48000 &#8211; 42000 = 6000 Hz<\/p>\n\n\n\n<p>So, as you can see there, as the input signal&#8217;s frequency goes up, the alias frequency of the signal (the one you hear at the output) will go down.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">There&#8217;s one more thing&#8230;<\/h2>\n\n\n\n<p>Go back and look at that last figure showing the playback signal of the sine wave. It looks like the sine wave has an inverted polarity compared to the signal that came into the system (notice that it starts on a downwards-slope whereas the input signal started on an upwards-slope). However, the polarity of the sine wave is NOT inverted. Nor has the phase shifted. The sine wave that you&#8217;re hearing at the output is going <strong>backwards in time<\/strong> compared to the signal at the input, just like the wheel appears to be rotating backwards when it&#8217;s actually going forwards.<\/p>\n\n\n\n<p>In Part 2, we&#8217;ll talk about why you don&#8217;t need to worry about this in the real world, except when you REALLY need to worry about it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of the best-known things about digital audio is the fact that you cannot record a signal that has a frequency that is higher than 1\/2 the sampling rate. Now, to be fair, that statement is not true. You CAN record a signal that has a frequency that is higher than 1\/2 the sampling rate. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","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":[63,4,59,19,54],"tags":[],"class_list":["post-8236","post","type-post","status-publish","format-standard","hentry","category-analysis","category-audio","category-digital-audio","category-funny-noises","category-perception-audio"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p48hIM-28Q","_links":{"self":[{"href":"http:\/\/www.tonmeister.ca\/wordpress\/wp-json\/wp\/v2\/posts\/8236","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.tonmeister.ca\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.tonmeister.ca\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.tonmeister.ca\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.tonmeister.ca\/wordpress\/wp-json\/wp\/v2\/comments?post=8236"}],"version-history":[{"count":3,"href":"http:\/\/www.tonmeister.ca\/wordpress\/wp-json\/wp\/v2\/posts\/8236\/revisions"}],"predecessor-version":[{"id":8287,"href":"http:\/\/www.tonmeister.ca\/wordpress\/wp-json\/wp\/v2\/posts\/8236\/revisions\/8287"}],"wp:attachment":[{"href":"http:\/\/www.tonmeister.ca\/wordpress\/wp-json\/wp\/v2\/media?parent=8236"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.tonmeister.ca\/wordpress\/wp-json\/wp\/v2\/categories?post=8236"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.tonmeister.ca\/wordpress\/wp-json\/wp\/v2\/tags?post=8236"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}