<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: ECecillo</title>
    <description>The latest articles on DEV Community by ECecillo (@ececillo).</description>
    <link>https://dev.to/ececillo</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F799529%2F6ee2387e-c805-47b5-9474-1c82479bc308.jpg</url>
      <title>DEV Community: ECecillo</title>
      <link>https://dev.to/ececillo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ececillo"/>
    <language>en</language>
    <item>
      <title>Workshop ⚒️ - Create sound with sin(x) 🎧</title>
      <dc:creator>ECecillo</dc:creator>
      <pubDate>Tue, 02 Apr 2024 10:31:50 +0000</pubDate>
      <link>https://dev.to/ececillo/workshop-create-sound-with-sinx-1ccf</link>
      <guid>https://dev.to/ececillo/workshop-create-sound-with-sinx-1ccf</guid>
      <description>&lt;h2&gt;
  
  
  Before we start
&lt;/h2&gt;

&lt;p&gt;Hello 👋, this article is part of a series on signal processing and is an opportunity for me to document the different concepts I had to grasp to code my audio encoder.&lt;/p&gt;

&lt;p&gt;If this subject interests you and you want to learn more, I invite you to follow me or visit &lt;a href="https://dev.to/ececillo/traveling-to-the-realm-of-audio-processing-and-encoding-summary-4a33"&gt;this post&lt;/a&gt; that I update as I write new articles 😁.&lt;/p&gt;

&lt;p&gt;I am open to any remarks or suggestions for improvement; feel free to share your feedback in the comments to contribute to the enrichment of this series of articles 💪.&lt;/p&gt;

&lt;p&gt;Happy reading 😉.&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;What I propose to you today is to conduct a small workshop consisting of creating a sound from a few basic mathematical formulas that will be based on the notions we have seen previously + new ones that will complete our understanding of analogue signals and digitisation.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The goal of this article is not to code a complex program but to illustrate concepts.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I will only give you the necessary algorithms to do it yourself, and at the end, I will put a sandbox where you can directly launch the program that I coded on my side with the language of my choice 😉.&lt;/p&gt;

&lt;p&gt;There will be no copy-paste in this article, so you will need to be at least comfortable with the language of your choice.&lt;/p&gt;

&lt;p&gt;Settle in comfortably, grab something to drink ☕️, and if that's all good, let's go 🚀!&lt;/p&gt;

&lt;p&gt;Code part&lt;/p&gt;

&lt;h3&gt;
  
  
  Creating a Curve and Retrieving Points
&lt;/h3&gt;

&lt;p&gt;We saw that the shape of an analogue signal fundamentally was based on sinusoidal curves.&lt;br&gt;
Therefore, we will need to use our function 

&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;sin(x)sin(x)&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;span class="mord mathnormal"&gt;in&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;x&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 for this.&lt;/p&gt;

&lt;p&gt;Then, once we have our signal curve, we will need to digitise it. Usually, to go from an analogue to a digital signal, we already have small electronic equipment that does it for us: the ADCs. (Analog-Digital-Controller)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6vujq3jzyw29vkvyns7f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6vujq3jzyw29vkvyns7f.png" alt="Analog-Digital-Controller image" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A small illustration of an ADC that one can find on the internet 😉.&lt;/p&gt;

&lt;p&gt;However, for simplicity, we will not go through all the necessary steps to digitise an analogue signal, because for a 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;sin(x)sin(x)&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;span class="mord mathnormal"&gt;in&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;x&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 curve, it would be a bit overkill 😅.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;We will detail the digitization process in another article.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To play a sound, we need values that we will calculate based on 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;sin(x)sin(x)&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;span class="mord mathnormal"&gt;in&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;x&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
, we will proceed with what is called sampling.&lt;/p&gt;
&lt;h4&gt;
  
  
  Sampling
&lt;/h4&gt;

&lt;p&gt;Sampling is the first step in analog-to-digital conversion (digitization).&lt;br&gt;
It consists of taking "pictures" or samples of the analogue signal at regular intervals to be able to retrieve the original signal from key points.&lt;/p&gt;

&lt;p&gt;This step is very important since the rest of the digitization will be based on these data!&lt;/p&gt;

&lt;p&gt;The frequency at which these samples are selected is called &lt;strong&gt;sampling frequency&lt;/strong&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;But wait, I've already heard of frequency, does it correspond to this then?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;No, that's why I will clarify a bit the difference between the two from here and specify their impact on the sound we perceive to avoid confusion 😁.&lt;/p&gt;
&lt;h3&gt;
  
  
  Frequency of an Analog Signal
&lt;/h3&gt;

&lt;p&gt;The frequency of an analogue signal indicates &lt;strong&gt;how many cycles occur in one-second&lt;/strong&gt;.&lt;br&gt;
For example, a frequency of 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;1Hz1Hz&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;1&lt;/span&gt;&lt;span class="mord mathnormal"&gt;Hz&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 indicates that one wave takes one second to complete a cycle.&lt;/p&gt;

&lt;p&gt;Increasing the frequency produces sounds of different intensities and pitches.&lt;/p&gt;

&lt;p&gt;You can find examples here: &lt;a href="https://www-users.cse.umn.edu/~rogness/math1155/soundwaves/" rel="noopener noreferrer"&gt;Examples of the impact of frequency on 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;sin(x)sin(x)&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;span class="mord mathnormal"&gt;in&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;x&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;We will see in another article the relationship between frequency and musical notes 🎼.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3&gt;
  
  
  Sampling Frequency
&lt;/h3&gt;

&lt;p&gt;The sampling frequency indicates the number of samples we take per second to represent the analogue signal digitally.&lt;br&gt;
The higher the sampling frequency, the more precise the digital representation will be.&lt;/p&gt;
&lt;h3&gt;
  
  
  Frequency of an Analog Signal and Sampling Frequency
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1tenypfs6vzs4c9s6fzr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1tenypfs6vzs4c9s6fzr.png" alt="Analogy with sound frequency and sampling rate" width="800" height="819"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Understanding the Correlation Between Wave Frequency and Sampling
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Frequency of a signal&lt;/strong&gt;: It determines the number of zigzags or cycles the signal has over a certain distance.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sampling frequency&lt;/strong&gt;: It determines how frequently we place points along these zigzags to capture the signal's information.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you increase the signal frequency (more zigzags) but keep the sampling frequency constant (the markers are always spaced the same distance), then yes&lt;/p&gt;

&lt;p&gt;, you will cross more zigzags, but you will still cross the same number of markers over a given distance.&lt;/p&gt;

&lt;p&gt;In terms of audio, this means that if you have a constant sampling frequency (say 44.1 kHz &amp;lt;=&amp;gt; 44,100 samples per second), but you increase the frequency of the wave you generate, you will have more wave cycles (more "high-pitched notes") in the same period, but each note will still be represented by the same number of samples.&lt;/p&gt;

&lt;p&gt;According to the Nyquist-Shannon theorem, the sampling frequency must be &lt;strong&gt;at least twice as high as the highest frequency&lt;/strong&gt; present in the analogue signal to avoid &lt;strong&gt;aliasing&lt;/strong&gt; (signal distortion caused by higher frequencies).&lt;/p&gt;

&lt;p&gt;However, the more we increase the number of samples per second, the larger our file size will be because we need to store much more information.&lt;/p&gt;
&lt;h4&gt;
  
  
  Illustration of the Nyquist-Shannon Principle
&lt;/h4&gt;

&lt;p&gt;The main idea of the theorem is that we must be able to place at least 2 points per cycle on a signal to identify its curve.&lt;/p&gt;

&lt;p&gt;If we take the following example where we have a signal of 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;20Hz20Hz&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;20&lt;/span&gt;&lt;span class="mord mathnormal"&gt;Hz&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 with a sampling frequency of 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;30Hz30Hz&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;30&lt;/span&gt;&lt;span class="mord mathnormal"&gt;Hz&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
, then we might end up with the following result:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F67vl5tpjvxq6ts67by1w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F67vl5tpjvxq6ts67by1w.png" alt="Undersampling graph with sin function" width="800" height="433"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We have more than 1 point for one of the cycles which might complicate retrieving the original signal 😬.&lt;/p&gt;

&lt;p&gt;This time let's see what happens with a sampling frequency of 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;80Hz80Hz&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;80&lt;/span&gt;&lt;span class="mord mathnormal"&gt;Hz&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb9yp20yb35j9z9zvwy49.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb9yp20yb35j9z9zvwy49.png" alt="Good sampling graph of sin function" width="800" height="433"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A very important thing to observe here is the phase value of the signal which is zero. (this is important for later)&lt;/p&gt;

&lt;p&gt;The samples represented by our red crosses are calculated every 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;12.5ms12.5ms&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;12.5&lt;/span&gt;&lt;span class="mord mathnormal"&gt;m&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 which we calculate from:&lt;br&gt;

&lt;/p&gt;
&lt;div class="katex-element"&gt;
  &lt;span class="katex-display"&gt;&lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;1sampling frequency=... seconds\frac{1}{\text{sampling frequency}} = \text{... seconds}&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mopen nulldelimiter"&gt;&lt;/span&gt;&lt;span class="mfrac"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord text"&gt;&lt;span class="mord"&gt;sampling frequency&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="frac-line"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord"&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mclose nulldelimiter"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;=&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord text"&gt;&lt;span class="mord"&gt;... seconds&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/div&gt;


&lt;p&gt;Here, it is therefore 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;180Hz=0.0125s\frac{1}{80Hz}=0.0125s&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mopen nulldelimiter"&gt;&lt;/span&gt;&lt;span class="mfrac"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;&lt;span class="mord mtight"&gt;80&lt;/span&gt;&lt;span class="mord mathnormal mtight"&gt;Hz&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="frac-line"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;&lt;span class="mord mtight"&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mclose nulldelimiter"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;=&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;0.0125&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 or 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;125ms125ms&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;125&lt;/span&gt;&lt;span class="mord mathnormal"&gt;m&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 after conversion to milliseconds.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;But wait, we said that twice the sampling frequency was enough, why did we take four times that of the wave frequency here?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If we had taken a frequency of 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;40Hz40Hz&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;40&lt;/span&gt;&lt;span class="mord mathnormal"&gt;Hz&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 here's what it would have looked like:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F38bp3fxz1e8lcz82n2pw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F38bp3fxz1e8lcz82n2pw.png" alt="Bad sampling because of the phase" width="800" height="433"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Strange, right? Why are all our points at zero here?&lt;/p&gt;

&lt;p&gt;Because of our phase value!&lt;/p&gt;

&lt;p&gt;Yes, it can skew our sampling and make us believe that our original signal is flat.&lt;/p&gt;

&lt;p&gt;This is a situation called &lt;strong&gt;undersampling&lt;/strong&gt; and illustrates why choosing the sampling frequency &lt;strong&gt;and&lt;/strong&gt; a value of &lt;strong&gt;sampling phase&lt;/strong&gt; (not to be confused with the signal's phase value) can be important.&lt;/p&gt;
&lt;h4&gt;
  
  
  Sampling Phase
&lt;/h4&gt;

&lt;p&gt;As the phase corresponds to where our signal starts, the sampling phase tells us where (amplitude) we will begin our sampling. We create a small offset so as not to be impacted by the signal's phase value.&lt;/p&gt;

&lt;p&gt;If I now define an offset of 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;1ms1ms&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;1&lt;/span&gt;&lt;span class="mord mathnormal"&gt;m&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 &lt;strong&gt;for our sampling phase&lt;/strong&gt;, I should start at a moment where our curve is not at an amplitude of 0.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fflm7vxgzwizaa1v6puov.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fflm7vxgzwizaa1v6puov.png" alt="Graph with adjusted sampling phase" width="800" height="433"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Great! We can now manage to observe when our curve seems to rise and fall.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;OK, I understand why we need a high frequency, but I see the frequency 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;44.1kHz44.1 kHz&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;44.1&lt;/span&gt;&lt;span class="mord mathnormal"&gt;k&lt;/span&gt;&lt;span class="mord mathnormal"&gt;Hz&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 everywhere, why do we use this sampling frequency?&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3&gt;
  
  
  The Human Ear and Science
&lt;/h3&gt;

&lt;p&gt;Humans are capable of hearing sounds that can vary between frequencies of 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;20Hz20Hz&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;20&lt;/span&gt;&lt;span class="mord mathnormal"&gt;Hz&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 and 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;20kHz20kHz&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;20&lt;/span&gt;&lt;span class="mord mathnormal"&gt;k&lt;/span&gt;&lt;span class="mord mathnormal"&gt;Hz&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
.&lt;br&gt;
As we saw earlier, the Nyquist-Shannon theorem indicated that we needed to have a sampling frequency twice as high as the frequency of a wave.&lt;/p&gt;

&lt;p&gt;So 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;2∗20kHz2*20kHz&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;2&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mbin"&gt;∗&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;20&lt;/span&gt;&lt;span class="mord mathnormal"&gt;k&lt;/span&gt;&lt;span class="mord mathnormal"&gt;Hz&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 (because it's the highest frequency that the human ear can perceive) gives us 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;40kHz40kHz&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;40&lt;/span&gt;&lt;span class="mord mathnormal"&gt;k&lt;/span&gt;&lt;span class="mord mathnormal"&gt;Hz&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;We're not far from our 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;44.1kHz44.1kHz&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;44.1&lt;/span&gt;&lt;span class="mord mathnormal"&gt;k&lt;/span&gt;&lt;span class="mord mathnormal"&gt;Hz&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
, but why do we have 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;4.1kHz4.1kHz&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;4.1&lt;/span&gt;&lt;span class="mord mathnormal"&gt;k&lt;/span&gt;&lt;span class="mord mathnormal"&gt;Hz&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 extra?&lt;/p&gt;

&lt;p&gt;There are several reasons for this, but the main one today is the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Margin for anti-aliasing filters:

&lt;ul&gt;
&lt;li&gt;We keep a margin of 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;4.1kHz4.1kHz&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;4.1&lt;/span&gt;&lt;span class="mord mathnormal"&gt;k&lt;/span&gt;&lt;span class="mord mathnormal"&gt;Hz&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 to allow the design of filters that eliminate frequencies that go beyond the audible bandwidth (wave frequency higher than 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;20kHz20kHz&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;20&lt;/span&gt;&lt;span class="mord mathnormal"&gt;k&lt;/span&gt;&lt;span class="mord mathnormal"&gt;Hz&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We will discuss the concept of psychoacoustics a bit later when we talk about quantization and signal filtering 😉.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Hey! I wanted to create a sound, not read a Lecture on signal processing!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now, we should have almost all the elements to determine our values on our 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;sin(x)sin(x)&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;span class="mord mathnormal"&gt;in&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;x&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 curve and listen to the sound generated by it!&lt;/p&gt;
&lt;h3&gt;
  
  
  Sampling with 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;sin(x)sin(x)&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;span class="mord mathnormal"&gt;in&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;x&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;We will need the following values:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The frequency of our signal.&lt;/li&gt;
&lt;li&gt;The sampling frequency.&lt;/li&gt;
&lt;li&gt;The desired duration for our signal.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Today, we will play the pitch &lt;a href="https://en.wikipedia.org/wiki/A440_(pitch_standard)" rel="noopener noreferrer"&gt;A440 (standard pitch)&lt;/a&gt; which corresponds to a signal frequency of 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;440Hz440Hz&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;440&lt;/span&gt;&lt;span class="mord mathnormal"&gt;Hz&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 and we will sample it with a frequency of 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;44.1kHz44.1kHz&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;44.1&lt;/span&gt;&lt;span class="mord mathnormal"&gt;k&lt;/span&gt;&lt;span class="mord mathnormal"&gt;Hz&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 because we can afford it, right!&lt;/p&gt;

&lt;p&gt;Lastly, I decided that we would have a duration of 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;4s4s&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;4&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 for our signal.&lt;/p&gt;

&lt;p&gt;To summarize:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Signal frequency: 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;440Hz440Hz&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;440&lt;/span&gt;&lt;span class="mord mathnormal"&gt;Hz&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
&lt;/li&gt;
&lt;li&gt;Sampling frequency: 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;44.1kHz44.1kHz&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;44.1&lt;/span&gt;&lt;span class="mord mathnormal"&gt;k&lt;/span&gt;&lt;span class="mord mathnormal"&gt;Hz&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
&lt;/li&gt;
&lt;li&gt;Duration: 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;4s4s&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;4&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If we make a graph of this thing, zooming in on the first ten milliseconds (otherwise it would be unreadable), we will have:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbzbj9s915kuusrjh5bc1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbzbj9s915kuusrjh5bc1.png" alt="Sinusoidal curve at 440Hertz" width="800" height="313"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;All this is cool, but now let's move on to our program for calculating points on these curves.&lt;/p&gt;

&lt;p&gt;Do you remember in the first article when I started to represent my 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;sin(x)sin(x)&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;span class="mord mathnormal"&gt;in&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;x&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 curve over a radians interval and explained that it was practical to express it in radians because 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;2π2π&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;2&lt;/span&gt;&lt;span class="mord mathnormal"&gt;π&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 corresponds to a period for 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;sin(x)sin(x)&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;span class="mord mathnormal"&gt;in&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;x&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
?&lt;/p&gt;

&lt;p&gt;In fact, the 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;2π2π&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;2&lt;/span&gt;&lt;span class="mord mathnormal"&gt;π&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 is much more useful than that; in trigonometry, it helps us for the sine and cosine functions to turn around a circle and define angles all along it.&lt;br&gt;
We can express these angles in radians (
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;ππ&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;π&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
) or in degrees (
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;2π=360°2π = 360°&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;2&lt;/span&gt;&lt;span class="mord mathnormal"&gt;π&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;=&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;360°&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx1ceu6dgyvrrnm3q2t2d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx1ceu6dgyvrrnm3q2t2d.png" alt="Trigonometric circle with radians and degrees associated" width="786" height="781"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Uh ok, but why are you talking about this again 🥶?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Actually, we need a way to know how I will move on my curve to find my points.&lt;/p&gt;

&lt;p&gt;We need a kind of compass that will indicate to us, considering all the samples and the duration of our signal, in which direction we will move on our 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;sin(x)sin(x)&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;span class="mord mathnormal"&gt;in&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;x&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 curve according to the curve's frequency.&lt;/p&gt;

&lt;p&gt;Our compass will therefore be an angle, and to have an angle, we can use our 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;2π2π&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;2&lt;/span&gt;&lt;span class="mord mathnormal"&gt;π&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
.&lt;/p&gt;

&lt;p&gt;We need to have a constant angle that considers all the samples we must have over the total duration of the signal, which is here four seconds.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Reminder: If the sampling frequency is the number of samples per second that we can have.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Then, calculating the total number of samples over a four-second interval consists of multiplying the sampling frequency by the number of seconds:&lt;/p&gt;


&lt;div class="katex-element"&gt;
  &lt;span class="katex-display"&gt;&lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;nsamps=4∗44100\text{nsamps} = 4 * 44100&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord text"&gt;&lt;span class="mord"&gt;nsamps&lt;/span&gt;&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;=&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;4&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mbin"&gt;∗&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;44100&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/div&gt;


&lt;p&gt;We just need to calculate the constant angle of all our samples:&lt;/p&gt;


&lt;div class="katex-element"&gt;
  &lt;span class="katex-display"&gt;&lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;angle=2πnsamps\text{angle} = \frac{2π}{nsamps}&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord text"&gt;&lt;span class="mord"&gt;angle&lt;/span&gt;&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;=&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mopen nulldelimiter"&gt;&lt;/span&gt;&lt;span class="mfrac"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;n&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;span class="mord mathnormal"&gt;am&lt;/span&gt;&lt;span class="mord mathnormal"&gt;p&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="frac-line"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord"&gt;2&lt;/span&gt;&lt;span class="mord mathnormal"&gt;π&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mclose nulldelimiter"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/div&gt;


&lt;p&gt;We will proceed with the following steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Calculate the total number of samples to be taken over the four seconds. 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;nsampsnsamps&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;n&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;span class="mord mathnormal"&gt;am&lt;/span&gt;&lt;span class="mord mathnormal"&gt;p&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Calculate the angle 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;θθ&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;θ&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 for all our samples 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;nsampsnsamps&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;n&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;span class="mord mathnormal"&gt;am&lt;/span&gt;&lt;span class="mord mathnormal"&gt;p&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;For each sample 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;ii&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;i&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 relative to the total number of samples 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;nsampsnsamps&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;n&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;span class="mord mathnormal"&gt;am&lt;/span&gt;&lt;span class="mord mathnormal"&gt;p&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Calculate the value 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;samplesample&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;span class="mord mathnormal"&gt;am&lt;/span&gt;&lt;span class="mord mathnormal"&gt;pl&lt;/span&gt;&lt;span class="mord mathnormal"&gt;e&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 of the sample 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;ii&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;i&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 with respect to 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;sin(θ∗frequency∗i)sin(θ * frequency * i)&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;span class="mord mathnormal"&gt;in&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;θ&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mbin"&gt;∗&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;f&lt;/span&gt;&lt;span class="mord mathnormal"&gt;re&lt;/span&gt;&lt;span class="mord mathnormal"&gt;q&lt;/span&gt;&lt;span class="mord mathnormal"&gt;u&lt;/span&gt;&lt;span class="mord mathnormal"&gt;e&lt;/span&gt;&lt;span class="mord mathnormal"&gt;n&lt;/span&gt;&lt;span class="mord mathnormal"&gt;cy&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mbin"&gt;∗&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;i&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;

&lt;/ol&gt;

&lt;p&gt;In algorithm:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Pre-define: 
    Duration, SampleRate, Frequency

Start:
    nsamps &amp;lt;- Duration * SampleRate
    angle &amp;lt;- (2 * π)/nsamps
    foreach i of nsamps
        sample &amp;lt;- sin(angle * Frequency * i)
End.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I invite you to first code this rather simple algorithm, but which already does everything we wanted.&lt;/p&gt;

&lt;h3&gt;
  
  
  Storing Our Values
&lt;/h3&gt;

&lt;p&gt;I don't know if you remember, but in the first article, I introduced you a bit to digital signals, I told you that these were a discrete representation (in binary form) of a signal.&lt;/p&gt;

&lt;p&gt;To store our sample values in the form of a digital signal, we need to transform these floating values into binary!&lt;/p&gt;

&lt;p&gt;This is a very important process that usually occurs in the last stages of digitization to be able to store the processed information on our computers.&lt;/p&gt;

&lt;p&gt;However, the more computer-savvy among you may know that depending on your OS, the computer does not read and store byte sequences (8 bits) in the same direction.&lt;/p&gt;

&lt;h4&gt;
  
  
  Little-Endian and Big-Endian
&lt;/h4&gt;

&lt;p&gt;There are thus two types of orders depending on your OS:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Big-Endian&lt;/strong&gt;: the most significant bit is first (at the lowest memory address), the least significant bit is last (at the highest address).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Little-Endian&lt;/strong&gt;: the least significant bit is first (at the lowest memory address), the most significant bit is last (at the highest address).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;See it a bit like the difference between reading a novel and reading a manga:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We read a novel from left to right where the most important information will be at the end of the book. (&lt;strong&gt;Little-Endian&lt;/strong&gt;)&lt;/li&gt;
&lt;li&gt;The manga, we read from right to left. (&lt;strong&gt;Big-Endian&lt;/strong&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you are coding the program on your side, I invite you to type the following command to find out if your OS is Little-Endian or Big-Endian.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;lscpcu | &lt;span class="nb"&gt;grep&lt;/span&gt; &lt;span class="s2"&gt;"Byte Order"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We will therefore complete our algorithm to be able to write the content of the variable 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;samplesample&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;span class="mord mathnormal"&gt;am&lt;/span&gt;&lt;span class="mord mathnormal"&gt;pl&lt;/span&gt;&lt;span class="mord mathnormal"&gt;e&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 in our loop in a file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Pre-define: 
    Duration, SampleRate, Frequency

Start:
    --- New ---
    fileName &amp;lt;- "out.bin"
    fd &amp;lt;- os.Create("path/to/write/file"+ fileName)
    --- EndNew ---

    nsamps &amp;lt;- Duration * SampleRate
    angle &amp;lt;- (2 * π)/nsamps
    foreach i of nsamps
        sample &amp;lt;- sin(angle * Frequency * i)

        --- New ----
        bufByte &amp;lt;- LittleEndian(sample)
        byteWritten &amp;lt;- fd.write(bufByte)
        show (" Wrote " + samples " in byte " + byteWritten)
        --- EndNew ---
End.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you have managed to code this algorithm, you should now have a file in which there is a binary representation of your signal 💪 🥳.&lt;/p&gt;

&lt;p&gt;To listen to it, you can use software like Audacity and open the file as a "raw audio file".&lt;br&gt;
You just need to switch to mono-channel and select the correct encoding.&lt;/p&gt;

&lt;p&gt;Otherwise, you can execute the following command, but you will need to install FFMPEG on your machine:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ffplay &lt;span class="nt"&gt;-f&lt;/span&gt; f32le &lt;span class="nt"&gt;-ar&lt;/span&gt;  44100 &lt;span class="nt"&gt;-showmode&lt;/span&gt; 1 out.bin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Demo 🖥
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://codesandbox.io/p/sandbox/suspicious-satoshi-d74tvv" class="ltag_cta ltag_cta--branded" rel="noopener noreferrer"&gt;Sandbox JavaScript + Bun 🥟 😁&lt;/a&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  To Conclude
&lt;/h3&gt;

&lt;p&gt;First of all, congratulations for making it this far, I know it must not have been easy, but I hope you learned a few things and had a little fun.&lt;/p&gt;

&lt;p&gt;If you are interested in this series, you can follow me so as not to miss new articles and leave a little comment if you like it.&lt;/p&gt;

&lt;p&gt;Otherwise, I'll see you next time for the next article which will be a bit softer on math, frequency, and music 🎧.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>beginners</category>
      <category>learning</category>
      <category>sampling</category>
      <category>signal</category>
    </item>
    <item>
      <title>🏕️ Traveling to the realm of Audio processing and Encoding - Summary</title>
      <dc:creator>ECecillo</dc:creator>
      <pubDate>Mon, 06 Nov 2023 21:31:15 +0000</pubDate>
      <link>https://dev.to/ececillo/traveling-to-the-realm-of-audio-processing-and-encoding-summary-4a33</link>
      <guid>https://dev.to/ececillo/traveling-to-the-realm-of-audio-processing-and-encoding-summary-4a33</guid>
      <description>&lt;p&gt;Hello 👋,&lt;/p&gt;

&lt;p&gt;Welcome to the summary of our article series designed to demystify signal processing and the fundamentals of audio through various explanations 🎧.&lt;/p&gt;

&lt;p&gt;Below, you'll find a comprehensive list of all the articles I've authored. Bookmark this page for convenient access 😁.&lt;/p&gt;

&lt;p&gt;Feel free to leave comments to help improve this series. I hope you find it educational and engaging 💪.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev.to/ececillo/understanding-how-analog-signal-is-captured-2edk"&gt;Understanding How Analog Signals Are Captured 🎤&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://dev.to/ececillo/workshop-create-sound-with-sinx-1ccf"&gt;Workshop ⚒️ - Crafting Sounds with sin(x) 🎧&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>Understanding how analog signal is captured 🎼</title>
      <dc:creator>ECecillo</dc:creator>
      <pubDate>Thu, 02 Nov 2023 18:38:18 +0000</pubDate>
      <link>https://dev.to/ececillo/understanding-how-analog-signal-is-captured-2edk</link>
      <guid>https://dev.to/ececillo/understanding-how-analog-signal-is-captured-2edk</guid>
      <description>&lt;h2&gt;
  
  
  Before we start
&lt;/h2&gt;

&lt;p&gt;In the upcoming articles, my aim is to code my own audio encoder, an adventure that will allow me to learn and document all the necessary concepts involved in such a project. This endeavour is purely educational and is by no means intended for production use. &lt;/p&gt;

&lt;p&gt;It is important to note that no prior knowledge is required to approach these articles. All terms will be defined and, when necessary, illustrated with diagrams to facilitate understanding.&lt;/p&gt;

&lt;p&gt;I am open to any comments or suggestions for improvement; feel free to share your feedback in the comments to contribute to the enrichment of this series of articles 💪.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sound waves 🌊
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Air pressure 💨 or more simply sound waves 🌊
&lt;/h3&gt;

&lt;p&gt;Sound waves are variations of pressure in the air that propagate in the form of waves.&lt;/p&gt;

&lt;h4&gt;
  
  
  A wave?
&lt;/h4&gt;

&lt;p&gt;Here, we're going to enter the realm of physics for a few seconds, but a wave is energy transported through space and/or time.&lt;br&gt;
Waves are characterised by:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;their frequency,&lt;/li&gt;
&lt;li&gt;wavelength,&lt;/li&gt;
&lt;li&gt;amplitude,&lt;/li&gt;
&lt;li&gt;speed.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;They can be classified into two major categories: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;mechanical&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;electromagnetic&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We will be particularly interested in mechanical waves since sound waves are part of these.&lt;/p&gt;

&lt;h2&gt;
  
  
  Transducers and their role in transmitting an electrical signal ⚡️
&lt;/h2&gt;

&lt;p&gt;Once our sound waves are out in nature, we need a device capable of bridging the gap between the physical world and the electronic world. &lt;br&gt;
For this, we use what are called transducers.&lt;/p&gt;

&lt;p&gt;I know the word may sound daunting, but it's quite simple if we take an example.&lt;/p&gt;

&lt;p&gt;Let's go with the following example:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwtpeflwzsq7wfykw1xeo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwtpeflwzsq7wfykw1xeo.png" alt="Guitarist generating sound waves to a microphone" width="800" height="268"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Notes&lt;br&gt;
ADC &lt;a href="https://en.wikipedia.org/wiki/Analog-to-digital_converter" rel="noopener noreferrer"&gt;Analog-to-digital converter - Wikipedia&lt;/a&gt; is responsible for digitizing a signal😉. &lt;br&gt;
We will detail its operation in another article 😁.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here we have our sound waves, and now a microphone will capture them.&lt;/p&gt;

&lt;p&gt;Depending on the type of microphone, we will have different components representing our transducer.&lt;/p&gt;

&lt;p&gt;Let's take dynamic microphones as an example, which have the following components:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Diaphragm&lt;/strong&gt;: The diaphragm is the component that directly receives the sound waves. It vibrates in response to the pressure variations caused by these waves.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Voice Coil&lt;/strong&gt;: Attached to the diaphragm, the voice coil moves with it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Permanent Magnet&lt;/strong&gt;: A permanent magnet surrounds or lives inside the voice coil. As the coil moves in response to the diaphragm's vibrations, it travels through the magnetic field created by the permanent magnet.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Electromagnetic Induction&lt;/strong&gt;: The movement of the voice coil through the magnetic field induces an electrical current in the coil, according to Faraday's law of electromagnetic induction. This generated electrical current is an analog signal that corresponds to the original sound waves.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here the components that represent our transducer are the diaphragm and voice coil that convert mechanical vibrations into electrical motion, the electrical part is ensured by the induction and magnet.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F537t7mz7920vuxc66j7u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F537t7mz7920vuxc66j7u.png" alt="Sound waves colliding with microphone diaphragm and turning it into electrical energy, analog signal" width="725" height="538"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This electrical signal is variable because its amplitude, frequency, or phase changes over time.&lt;br&gt;
This signal can take different forms, but for this article, we will focus primarily on analog and digital signals 😁.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a signal already? 🧐
&lt;/h2&gt;

&lt;p&gt;A signal is a physical representation of information to be transmitted or a medium used to carry information.&lt;/p&gt;

&lt;p&gt;Signals can be classified into:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;u&gt;Analog&lt;/u&gt;&lt;/strong&gt;: represented in continuous values (a curve on which points can be found).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;u&gt;Digital&lt;/u&gt;&lt;/strong&gt;: represented in discrete values (a series of binary numbers that can represent a signal).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What's the difference between a digital signal 🧮 and an analog signal 🔌?
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Digital Signal&lt;/strong&gt; 🧮
&lt;/h3&gt;

&lt;p&gt;A digital signal is a discrete representation (in binary form) of a signal, where values are quantized at specific intervals in time and amplitude.&lt;br&gt;
They are often preferred in modern applications because of their resistance to noise and their ease of processing and storage.&lt;/p&gt;

&lt;p&gt;We will study these signals in future articles, as they can quickly become very technical, and I want us to take it step by step towards this type of signal.&lt;/p&gt;

&lt;p&gt;We will focus mainly on analog signals for the rest of this article.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Analog Signal&lt;/strong&gt; 🔌
&lt;/h3&gt;

&lt;p&gt;Analog signals are more faithful to the original since they capture the entirety of the waveform, unlike digital signals, which are a discrete approximation.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This is why purists prefer analog! (Or just that they are snobs 👀)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;An analog signal in its simplest form corresponds to something we've already seen in our school life.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A sinusoidal curve of course!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Yes, that 

&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;sin(x)sin(x)&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;span class="mord mathnormal"&gt;in&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;x&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 function isn't just for looking pretty on paper, but actually represents sound, for example!&lt;/p&gt;

&lt;p&gt;The sinusoidal function is often used as a fundamental building block to represent more complex signals, as any periodic signal can be decomposed into a sum of sinusoidal and cosinusoidal functions (via Fourier series 🥶)&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Don't worry, we won't be covering Fourier series in this article!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;What's great about this function is that if we take a look at its properties, we're able to more easily manipulate complex waves that are the essence of analog signals 💪.&lt;/p&gt;

&lt;p&gt;So, prepare yourself a little coffee ☕️ and your brain 🧠, because you're going to see some Greek letters, but of course, we're going to explain them 😁.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Periodicity&lt;/strong&gt;
&lt;/h4&gt;

&lt;h5&gt;
  
  
  &lt;strong&gt;Period&lt;/strong&gt;
&lt;/h5&gt;

&lt;blockquote&gt;
&lt;p&gt;The period of a wave is the time required to complete one cycle.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h5&gt;
  
  
  &lt;strong&gt;Cycle&lt;/strong&gt;
&lt;/h5&gt;

&lt;blockquote&gt;
&lt;p&gt;A complete repetition of the wave's shape over its entire period.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We will represent the function 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;y=sin⁡(x)y=\sin(x)&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;y&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;=&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mop"&gt;sin&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;x&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 over an interval from 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;−2π-2\pi&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;−&lt;/span&gt;&lt;span class="mord"&gt;2&lt;/span&gt;&lt;span class="mord mathnormal"&gt;π&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 to 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;2π2\pi&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;2&lt;/span&gt;&lt;span class="mord mathnormal"&gt;π&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 to see what it looks like:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmty52qm0eahxusollde6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmty52qm0eahxusollde6.png" alt="Sine function with cycle represented with red dot lines" width="800" height="433"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Wait, why do we use radiants instead of time? 🤨&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Well, that's an excellent question!&lt;/p&gt;

&lt;p&gt;Having our x-axis as radiants allows us to make a full period in one go using 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;2π2\pi&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;2&lt;/span&gt;&lt;span class="mord mathnormal"&gt;π&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 without specifying any frequency.&lt;/p&gt;

&lt;p&gt;However, if we wanna use time we will have to know the frequency at which our sin function needs to oscillate.&lt;/p&gt;

&lt;p&gt;We will see in the moment what the frequency is and it’s impact on our function 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;sin(x)sin(x)&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;span class="mord mathnormal"&gt;in&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;x&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
.&lt;/p&gt;

&lt;p&gt;The 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;sin(x)sin(x)&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;span class="mord mathnormal"&gt;in&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;x&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 function is periodic, with a period of 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;2π2\pi&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;2&lt;/span&gt;&lt;span class="mord mathnormal"&gt;π&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
.&lt;br&gt;
It repeats every 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;2π2\pi&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;2&lt;/span&gt;&lt;span class="mord mathnormal"&gt;π&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 radians.&lt;br&gt;
Here, we can observe two periods with the first one between 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;[−2π;0][-2\pi;0]&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mopen"&gt;[&lt;/span&gt;&lt;span class="mord"&gt;−&lt;/span&gt;&lt;span class="mord"&gt;2&lt;/span&gt;&lt;span class="mord mathnormal"&gt;π&lt;/span&gt;&lt;span class="mpunct"&gt;;&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord"&gt;0&lt;/span&gt;&lt;span class="mclose"&gt;]&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 and the second between 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;[0;2π][0;2\pi]&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mopen"&gt;[&lt;/span&gt;&lt;span class="mord"&gt;0&lt;/span&gt;&lt;span class="mpunct"&gt;;&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord"&gt;2&lt;/span&gt;&lt;span class="mord mathnormal"&gt;π&lt;/span&gt;&lt;span class="mclose"&gt;]&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Amplitude&lt;/strong&gt;
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;The amplitude is the maximum height reached by the wave relative to its position at rest.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftgl86w8pdtpfbc0fx8v0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftgl86w8pdtpfbc0fx8v0.png" alt="arrow measuring the distance between x-axis and curve representing signal" width="600" height="302"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The amplitude of 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;sin(x)sin(x)&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;span class="mord mathnormal"&gt;in&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;x&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 is 1, which means the values (heights) of the function vary between -1 and 1.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Frequency&lt;/strong&gt;
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;The frequency indicates how many cycles occur in &lt;strong&gt;one second&lt;/strong&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The frequency of our 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;sin(x)sin(x)&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;span class="mord mathnormal"&gt;in&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;x&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 function is 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;12π\frac{1}{2\pi}&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mopen nulldelimiter"&gt;&lt;/span&gt;&lt;span class="mfrac"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;&lt;span class="mord mtight"&gt;2&lt;/span&gt;&lt;span class="mord mathnormal mtight"&gt;π&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="frac-line"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;&lt;span class="mord mtight"&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mclose nulldelimiter"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 cycles per unit on the x-axis.&lt;/p&gt;

&lt;p&gt;But as we said earlier, an analog signal is usually expressed using time so let's see what we need to do to express our 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;sin(x)sin(x)&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;span class="mord mathnormal"&gt;in&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;x&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 function using time.&lt;/p&gt;

&lt;p&gt;In our first graph, we can see that we have 2 cycles.&lt;/p&gt;

&lt;p&gt;We know that frequency indicates how many cycles occur in one second so for 2 cycles we need 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;2s2s&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;2&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
.&lt;/p&gt;

&lt;p&gt;Lastly, frequency is expressed in 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;HzHz&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;Hz&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
.&lt;/p&gt;

&lt;p&gt;So with all of this information, we should be able to go and draw our 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;sin(x)sin(x)&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;span class="mord mathnormal"&gt;in&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;x&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 function.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;But wait, I still don't know what to do with the time and frequency 🗿.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Ah yes, and what if I told you that 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;1Hz∗1s=1cycles1Hz * 1s = 1 cycles&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;1&lt;/span&gt;&lt;span class="mord mathnormal"&gt;Hz&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mbin"&gt;∗&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;1&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;=&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;1&lt;/span&gt;&lt;span class="mord mathnormal"&gt;cyc&lt;/span&gt;&lt;span class="mord mathnormal"&gt;l&lt;/span&gt;&lt;span class="mord mathnormal"&gt;es&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 ?&lt;/p&gt;

&lt;p&gt;How many seconds do I need to make 2 cycles?&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;2 !&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Good job 💪.&lt;/p&gt;

&lt;p&gt;So we now have our same graph but in seconds!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjw6rbkr6qn8scrqw6dw7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjw6rbkr6qn8scrqw6dw7.png" alt="Sinus function expressed on 2 seconds interval" width="800" height="433"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Phase&lt;/strong&gt;
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;The phase tells us where our signal starts.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The phase of 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;sin(x)sin(x)&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;span class="mord mathnormal"&gt;in&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;x&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 is zero, which means the wave starts at zero at time zero.&lt;br&gt;
However, the phase can be adjusted with a phase shift, like in 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;sin(x+ϕ)sin(x+\phi)&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;span class="mord mathnormal"&gt;in&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;x&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mbin"&gt;+&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;ϕ&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
, where 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;ϕϕ&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;ϕ&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 is the phase shift.&lt;/p&gt;

&lt;p&gt;This allows for adjusting the horizontal position of a sinusoidal wave on the time axis (usually the x-axis).&lt;/p&gt;

&lt;h2&gt;
  
  
  What's next?
&lt;/h2&gt;

&lt;p&gt;I know you probably want to know more about how we end up with a digital signal, but if I were to put everything into one article, it would be the size of a book and it's not necessarily pleasant to have to read an entire book in one sitting 😩.&lt;/p&gt;

&lt;p&gt;That's why I invite you to follow me so as not to miss the next article which will consist of creating a sound from our pretty 
&lt;span class="katex-element"&gt;
  &lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;sin(x)sin(x)&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;span class="mord mathnormal"&gt;in&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;x&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/span&gt;
 function and learning a little more about this exciting topic 😁!&lt;/p&gt;

&lt;p&gt;Don't hesitate to give me your feedback in the comments to correct or improve this article!&lt;/p&gt;

</description>
      <category>learning</category>
      <category>beginners</category>
      <category>analog</category>
      <category>signal</category>
    </item>
  </channel>
</rss>
