{"id":8024,"date":"2024-04-24T17:27:43","date_gmt":"2024-04-24T15:27:43","guid":{"rendered":"http:\/\/www.tonmeister.ca\/wordpress\/?p=8024"},"modified":"2024-04-24T17:29:22","modified_gmt":"2024-04-24T15:29:22","slug":"this-weeks-weird-fft","status":"publish","type":"post","link":"http:\/\/www.tonmeister.ca\/wordpress\/2024\/04\/24\/this-weeks-weird-fft\/","title":{"rendered":"This week&#8217;s weird FFT"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">This week, I was testing a device that required that I look WAY down into the floor caused by the noise+distortion artefacts in the presence of a signal.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">One trick to do this is to play a sinusoidal wave through the system and do an FFT of the output. However, as I described in <a href=\"http:\/\/www.tonmeister.ca\/wordpress\/2019\/08\/24\/dfts-part-4-the-artefacts\/\" data-type=\"post\" data-id=\"5680\">this posting<\/a> a long time ago, there is an interaction between the frequency you choose and the behaviour of an FFT on a digital signal (yes&#8230; I know it&#8217;s really a DFT &#8211; but let&#8217;s not be pedantic&#8230;)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, if I do a 65536-point FFT on a 997 Hz sine tone in a 48 kHz sampling rate (with all the  floating point precision I have available&#8230;) I get a magnitude response that looks like this:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/fft_click_figure_01-1024x768.png\" alt=\"\" class=\"wp-image-8025\" srcset=\"http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/fft_click_figure_01-1024x768.png 1024w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/fft_click_figure_01-300x225.png 300w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/fft_click_figure_01-768x576.png 768w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/fft_click_figure_01.png 1120w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">Figure 1. The magnitude response of a 997 Hz sine tone, but is it really?<\/figcaption><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">Obviously, this is NOT the magnitude response of a sinusoidal wave. The &#8220;skirts&#8221; on either side of 997 Hz are artefacts caused by the fact that I&#8217;m using a rectangular window, and the sine wave&#8217;s last sample does not line up perfectly with its first when the FFT &#8220;wraps&#8221; it around to meet itself (read <a href=\"http:\/\/www.tonmeister.ca\/wordpress\/2019\/08\/24\/dfts-part-4-the-artefacts\/\" data-type=\"post\" data-id=\"5680\">this<\/a> leading up to Figure 10 for an explanation). That sharp discontinuity causes the extra energy in the other frequency bins as shown above.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If, however, I find out the frequency of the closest FFT bin, and make my sine wave THAT frequency instead, THEN I do an FFT and look at the magnitude response, it looks like Figure 2.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/fft_click_figure_02-1024x768.png\" alt=\"\" class=\"wp-image-8026\" srcset=\"http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/fft_click_figure_02-1024x768.png 1024w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/fft_click_figure_02-300x225.png 300w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/fft_click_figure_02-768x576.png 768w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/fft_click_figure_02.png 1120w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">Figure 2. The magnitude response of a 996.8261718750000 Hz sine tone.<\/figcaption><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">Notice that this is not a 997 Hz tone, but a 996.8261718750000 Hz tone instead.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now the &#8220;noise floor&#8221; that you see there is  the error in my sine wave caused by the precision of my calculator (Matlab). -300 dB is VERY low, and gives me plenty of room to see the errors in the thing that I might be testing (assuming that I can actually get that signal out to my Device Under Test or &#8220;DUT&#8221; and back in again from it).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s say I were to represent the same sine wave using a 24-bit LPCM signal that has been correctly dithered with TPDF dither, and THEN I do the FFT and calculate the magnitude response. That would look like Figure 3.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/fft_click_figure_03-1024x768.png\" alt=\"\" class=\"wp-image-8027\" srcset=\"http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/fft_click_figure_03-1024x768.png 1024w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/fft_click_figure_03-300x225.png 300w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/fft_click_figure_03-768x576.png 768w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/fft_click_figure_03.png 1120w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">Figure 3. The magnitude response of a 996.996.8261718750000 Hz sine tone that has been dithered and quantised with 24 bit precision.<\/figcaption><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">Now, the energy at all the frequencies other than 996.8-ish Hz is the energy in the noise floor generated by the dither. (If you&#8217;re wondering why it&#8217;s almost 200 dB down, and not 141 dB down (6*24-3), it&#8217;s because the total energy in all those FFT bins add up to a noise floor that&#8217;s 141 dB below the sine tone.)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Okay. All of those plots show things that I&#8217;ve seen before &#8211; and are things that I would expect to see when measuring a device.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">But then, this week, I did a measurement that produced the magnitude response shown in Figure 4.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/fft_click_figure_04-1024x768.png\" alt=\"\" class=\"wp-image-8028\" srcset=\"http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/fft_click_figure_04-1024x768.png 1024w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/fft_click_figure_04-300x225.png 300w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/fft_click_figure_04-768x576.png 768w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/fft_click_figure_04.png 1120w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">Figure 4. A 996.996.8261718750000 Hz sine tone and something else&#8230;<\/figcaption><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">This is NOT something I&#8217;ve seen before, so it raised one of my two eyebrows. In retrospect, I should have known what would cause this, but at the time, I was very confused. It&#8217;s not a noise floor because it&#8217;s too flat. It&#8217;s not distortion because it doesn&#8217;t have harmonics. So what is it?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The answer is actually really simple. <\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The sine tone is visible as the spike in the magnitude plot, just like in all the others. <\/li>\n\n\n\n<li>The flat horizontal line is the result of a single-sample click that happened sometime in the 65536 samples that I used to do the FFT. <\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The sum (or mix) of the sine + click results in the magnitude response plot you see above. If you&#8217;re looking at the signal itself, it just means that one of the 65536 samples has an error, and isn&#8217;t sitting on the sine curve. I&#8217;ve shown an example of this in Figure 5.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"560\" height=\"420\" src=\"http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/fft_click_figure_05.png\" alt=\"\" class=\"wp-image-8030\" srcset=\"http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/fft_click_figure_05.png 560w, http:\/\/www.tonmeister.ca\/wordpress\/wp-content\/uploads\/fft_click_figure_05-300x225.png 300w\" sizes=\"auto, (max-width: 560px) 100vw, 560px\" \/><figcaption class=\"wp-element-caption\">Figure 5. The sample with the error is shown in red. All other 65535 samples are behaving as they should<\/figcaption><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">The greater the error of that one sample value, the higher the floor in Figure 4.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Of course, for these plots, I simulated everything in Matlab. However, the actual result was even more interesting \/ confusing, since the DUT didn&#8217;t have a flat magnitude response. So, instead of a nice, horizontal line like the one I&#8217;ve shown in Figure 4, I could see <em>something like<\/em> the response of the system as well, but I&#8217;ll stay away from the details of that to keep things simple here.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This week, I was testing a device that required that I look WAY down into the floor caused by the noise+distortion artefacts in the presence of a signal. One trick to do this is to play a sinusoidal wave through the system and do an FFT of the output. However, as I described in this [&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,26],"tags":[],"class_list":["post-8024","post","type-post","status-publish","format-standard","hentry","category-analysis","category-audio","category-digital-audio","category-what-i-learned"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p48hIM-25q","_links":{"self":[{"href":"http:\/\/www.tonmeister.ca\/wordpress\/wp-json\/wp\/v2\/posts\/8024","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=8024"}],"version-history":[{"count":3,"href":"http:\/\/www.tonmeister.ca\/wordpress\/wp-json\/wp\/v2\/posts\/8024\/revisions"}],"predecessor-version":[{"id":8032,"href":"http:\/\/www.tonmeister.ca\/wordpress\/wp-json\/wp\/v2\/posts\/8024\/revisions\/8032"}],"wp:attachment":[{"href":"http:\/\/www.tonmeister.ca\/wordpress\/wp-json\/wp\/v2\/media?parent=8024"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.tonmeister.ca\/wordpress\/wp-json\/wp\/v2\/categories?post=8024"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.tonmeister.ca\/wordpress\/wp-json\/wp\/v2\/tags?post=8024"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}