DEV Community

Cover image for Understanding how analog signal is captured ๐ŸŽผ
ECecillo
ECecillo

Posted on • Edited on

Understanding how analog signal is captured ๐ŸŽผ

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

Notes
ADC Analog-to-digital converter - Wikipedia 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

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:

  • Analog: represented in continuous values (a curve on which points can be found).
  • Digital: 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 sin(x)sin(x) 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 y=sinโก(x)y=\sin(x) over an interval from โˆ’2ฯ€-2\pi to 2ฯ€2\pi to see what it looks like:

Sine function with cycle represented with red dot lines

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 2ฯ€2\pi 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 sin(x)sin(x) .

The sin(x)sin(x) function is periodic, with a period of 2ฯ€2\pi .
It repeats every 2ฯ€2\pi radians.
Here, we can observe two periods with the first one between [โˆ’2ฯ€;0][-2\pi;0] and the second between [0;2ฯ€][0;2\pi] .

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

The amplitude of sin(x)sin(x) 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 sin(x)sin(x) function is 12ฯ€\frac{1}{2\pi} 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 sin(x)sin(x) 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 2s2s .

Lastly, frequency is expressed in HzHz .

So with all of this information, we should be able to go and draw our sin(x)sin(x) 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 1Hzโˆ—1s=1cycles1Hz * 1s = 1 cycles ?

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

Phase

The phase tells us where our signal starts.

The phase of sin(x)sin(x) is zero, which means the wave starts at zero at time zero.
However, the phase can be adjusted with a phase shift, like in sin(x+ฯ•)sin(x+\phi) , where ฯ•ฯ• 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 sin(x)sin(x) 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!

Top comments (0)