{"id":338,"date":"2019-11-05T00:13:31","date_gmt":"2019-11-05T00:13:31","guid":{"rendered":"https:\/\/synthnotes.ucsd.edu\/wp7\/?p=338"},"modified":"2019-11-05T00:15:26","modified_gmt":"2019-11-05T00:15:26","slug":"decimation","status":"publish","type":"post","link":"https:\/\/synthnotes.ucsd.edu\/wp7\/index.php\/2019\/11\/05\/decimation\/","title":{"rendered":"Decimation"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Decimation is a type of waveshaping that reduces the resolution of the input signal by eliminating the lower bits in the integer representation of the sample. For example, lets take a sample of value 0.5337 (within the typical range of 1.0 to -1.0) to 3 bit resolution. With 3 bits, we only have 8 values from -1.0 to 1.0: -1.0. -0.75, -0.5, -0.25, 0.0, 0.25, 0.5, 0.75. The value 0.5337 becomes 0.5 (as do all values between 0.5 and 0.75). This reduction in resolution will create noise which is not related to the amplitude of the signal. The less bits used, the great the decimation noise. If we consider 3-bit decimation a transfer function, it would look like this:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"alignleft is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/synthnotes.ucsd.edu\/wp7\/wp-content\/uploads\/2019\/11\/Screen-Shot-2019-11-04-at-2.49.14-PM.png\" alt=\"\" class=\"wp-image-340\" width=\"273\" height=\"334\" srcset=\"https:\/\/synthnotes.ucsd.edu\/wp7\/wp-content\/uploads\/2019\/11\/Screen-Shot-2019-11-04-at-2.49.14-PM.png 546w, https:\/\/synthnotes.ucsd.edu\/wp7\/wp-content\/uploads\/2019\/11\/Screen-Shot-2019-11-04-at-2.49.14-PM-245x300.png 245w\" sizes=\"auto, (max-width: 273px) 100vw, 273px\" \/><figcaption>3 bit decimation transfer function<\/figcaption><\/figure><\/div>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/synthnotes.ucsd.edu\/wp7\/wp-content\/uploads\/2019\/11\/Screen-Shot-2019-11-04-at-2.54.10-PM.png\" alt=\"\" class=\"wp-image-341\" width=\"275\" height=\"332\" srcset=\"https:\/\/synthnotes.ucsd.edu\/wp7\/wp-content\/uploads\/2019\/11\/Screen-Shot-2019-11-04-at-2.54.10-PM.png 549w, https:\/\/synthnotes.ucsd.edu\/wp7\/wp-content\/uploads\/2019\/11\/Screen-Shot-2019-11-04-at-2.54.10-PM-248x300.png 248w\" sizes=\"auto, (max-width: 275px) 100vw, 275px\" \/><figcaption>sin(2\u03c0x) after 3 bit decimation<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Using a transfer function like the above is one method of decimation. However, as with other types of waveshaping, it is more efficient to compute decimation directly, using the equation which would create the transfer function.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Implementation<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The following equation could be used to decimate a floating point signal.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span class=\"wp-katex-eq\" data-display=\"false\"> y[n] = \\lfloor(x[n] * 2^{(bits - 1)})\\rfloor\/(bits-1) <\/span><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Below are two C implementations of decimation to 3 bits. First using multiplication and division, and the second using logical bit operations. The logical operations are probably much less CPU intensive.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\/\/ decimation to 3 bits using multiplication and division\n\nfactor = pow(2.0, bits - 1.0);\noutput = floor(input * factor)\/factor;\n\n\/\/ decimation to 3 bits using logical operations\n\n\/\/ convert to 16-bit sample\ninput16 = (int)(input * 32768);\n\/\/ zero out all but the top 3 bits using bitwise and\n\/\/ binary literals only allowed in gcc, in hex use 0xe000\noutput16 = input16 &amp; 0b1110000000000000; \n\/\/ convert back to float using 1\/32768\noutput = output16 * 0.000030517578125;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The first technique is more clear, and more flexible. It is also probably not that much more CPU intensive. Finally, the first technique could use a floating point value for <em>bits<\/em>, and this would allow continuous change from one bit depth to another.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<figure class=\"wp-block-audio\"><audio controls src=\"https:\/\/synthnotes.ucsd.edu\/wp7\/wp-content\/uploads\/2019\/11\/decimate.wav\"><\/audio><figcaption>FM tone progressively decimated from 6 to 1 bit.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">When using decimation on recorded audio, you will notice that there is always distortion in the audio, and also that at low bit depths only the loudest sounds will be audible.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Decimation is a type of waveshaping that reduces the resolution of the input signal by eliminating the lower bits in the integer representation of the sample. For example, lets take a sample of value 0.5337 (within the typical range of 1.0 to -1.0) to 3 bit resolution. With 3 bits, we only have 8 values [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-338","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/synthnotes.ucsd.edu\/wp7\/index.php\/wp-json\/wp\/v2\/posts\/338","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/synthnotes.ucsd.edu\/wp7\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/synthnotes.ucsd.edu\/wp7\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/synthnotes.ucsd.edu\/wp7\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/synthnotes.ucsd.edu\/wp7\/index.php\/wp-json\/wp\/v2\/comments?post=338"}],"version-history":[{"count":10,"href":"https:\/\/synthnotes.ucsd.edu\/wp7\/index.php\/wp-json\/wp\/v2\/posts\/338\/revisions"}],"predecessor-version":[{"id":353,"href":"https:\/\/synthnotes.ucsd.edu\/wp7\/index.php\/wp-json\/wp\/v2\/posts\/338\/revisions\/353"}],"wp:attachment":[{"href":"https:\/\/synthnotes.ucsd.edu\/wp7\/index.php\/wp-json\/wp\/v2\/media?parent=338"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/synthnotes.ucsd.edu\/wp7\/index.php\/wp-json\/wp\/v2\/categories?post=338"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/synthnotes.ucsd.edu\/wp7\/index.php\/wp-json\/wp\/v2\/tags?post=338"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}