Understanding how analog signal is captured 🎼
Tags: learning, beginners, analog, signal
Published: 2023-11-02 18:38:18

## Before we start

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. 

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.

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 💪.

## Sound waves 🌊

### Air pressure 💨 or more simply sound waves 🌊

Sound waves are variations of pressure in the air that propagate in the form of waves.

#### A wave?

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.
Waves are characterised by:
- their frequency,
- wavelength,
- amplitude,
- speed.

They can be classified into two major categories: 
- **mechanical**
- **electromagnetic**.

We will be particularly interested in mechanical waves since sound waves are part of these.

## Transducers and their role in transmitting an electrical signal ⚡️

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. 
For this, we use what are called transducers.

I know the word may sound daunting, but it's quite simple if we take an example.

Let's go with the following example:

![Guitarist generating sound waves to a microphone](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wtpeflwzsq7wfykw1xeo.png)

> Notes
> ADC [Analog-to-digital converter - Wikipedia](https://en.wikipedia.org/wiki/Analog-to-digital_converter) is responsible for digitizing a signal😉. 
> We will detail its operation in another article 😁.

Here we have our sound waves, and now a microphone will capture them.

Depending on the type of microphone, we will have different components representing our transducer.

Let's take dynamic microphones as an example, which have the following components:
- **Diaphragm**: The diaphragm is the component that directly receives the sound waves. It vibrates in response to the pressure variations caused by these waves.
- **Voice Coil**: Attached to the diaphragm, the voice coil moves with it.
- **Permanent Magnet**: 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.
- **Electromagnetic Induction**: 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.

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.

![Sound waves colliding with microphone diaphragm and turning it into electrical energy, analog signal](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/537t7mz7920vuxc66j7u.png)

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

## What is a signal already? 🧐

A signal is a physical representation of information to be transmitted or a medium used to carry information.

Signals can be classified into:
- **<u>Analog</u>**: represented in continuous values (a curve on which points can be found).
- **<u>Digital</u>**: represented in discrete values (a series of binary numbers that can represent a signal).

## What's the difference between a digital signal 🧮 and an analog signal 🔌?

### **Digital Signal** 🧮

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

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.

We will focus mainly on analog signals for the rest of this article.

### **Analog Signal** 🔌

Analog signals are more faithful to the original since they capture the entirety of the waveform, unlike digital signals, which are a discrete approximation.

> This is why purists prefer analog! (Or just that they are snobs 👀)

An analog signal in its simplest form corresponds to something we've already seen in our school life.

> A sinusoidal curve of course!

Yes, that {% katex inline %}sin(x){% endkatex %} function isn't just for looking pretty on paper, but actually represents sound, for example!

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 🥶)

> Don't worry, we won't be covering Fourier series in this article!

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 💪.

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 😁.

#### **Periodicity**

##### **Period**

> The period of a wave is the time required to complete one cycle.

##### **Cycle**

> A complete repetition of the wave's shape over its entire period.

We will represent the function {% katex inline %}y=\sin(x){% endkatex %} over an interval from {% katex inline %}-2\pi{% endkatex %} to {% katex inline %}2\pi{% endkatex %} to see what it looks like:

![Sine function with cycle represented with red dot lines](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mty52qm0eahxusollde6.png)

> Wait, why do we use radiants instead of time? 🤨

Well, that's an excellent question!

Having our x-axis as radiants allows us to make a full period in one go using {% katex inline %}2\pi{% endkatex %} without specifying any frequency.

However, if we wanna use time we will have to know the frequency at which our sin function needs to oscillate.

We will see in the moment what the frequency is and it’s impact on our function {% katex inline %}sin(x){% endkatex %}.

The {% katex inline %}sin(x){% endkatex %} function is periodic, with a period of {% katex inline %}2\pi{% endkatex %}.
It repeats every {% katex inline %}2\pi{% endkatex %} radians.
Here, we can observe two periods with the first one between {% katex inline %}[-2\pi;0]{% endkatex %} and the second between {% katex inline %}[0;2\pi]{% endkatex %}.

#### **Amplitude**

> The amplitude is the maximum height reached by the wave relative to its position at rest.

![arrow measuring the distance between x-axis and curve representing signal](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tgl86w8pdtpfbc0fx8v0.png)

The amplitude of {% katex inline %}sin(x){% endkatex %} is 1, which means the values (heights) of the function vary between -1 and 1.

#### **Frequency**

> The frequency indicates how many cycles occur in **one second**.

The frequency of our {% katex inline %}sin(x){% endkatex %} function is {% katex inline %}\frac{1}{2\pi}{% endkatex %} cycles per unit on the x-axis.

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 {% katex inline %}sin(x){% endkatex %} function using time.

In our first graph, we can see that we have 2 cycles.

We know that frequency indicates how many cycles occur in one second so for 2 cycles we need {% katex inline %}2s{% endkatex %}.

Lastly, frequency is expressed in {% katex inline %}Hz{% endkatex %}.

So with all of this information, we should be able to go and draw our {% katex inline %}sin(x){% endkatex %} function.

> But wait, I still don't know what to do with the time and frequency 🗿.

Ah yes, and what if I told you that {% katex inline %}1Hz * 1s = 1 cycles{% endkatex %} ?

How many seconds do I need to make 2 cycles?

> 2 !

Good job 💪.

So we now have our same graph but in seconds!

![Sinus function expressed on 2 seconds interval](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jw6rbkr6qn8scrqw6dw7.png)

#### **Phase**

> The phase tells us where our signal starts.

The phase of {% katex inline %}sin(x){% endkatex %} is zero, which means the wave starts at zero at time zero.
However, the phase can be adjusted with a phase shift, like in {% katex inline %}sin(x+\phi){% endkatex %}, where {% katex inline %}ϕ{% endkatex %} is the phase shift.

This allows for adjusting the horizontal position of a sinusoidal wave on the time axis (usually the x-axis).

## What's next?

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 😩.

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 {% katex inline %}sin(x){% endkatex %} function and learning a little more about this exciting topic 😁!

Don't hesitate to give me your feedback in the comments to correct or improve this article!