Digital Signal Processing Basics

Acoustic Signal

I had a hard time understanding basics of digital signal processing. I think that the reason was the fact that sounds were not visible.

There is a way to "see" the sound, though. This YouTube video for example demonstrates that special cameras make the sound visible.
 

The sound is the virbation of particles in the air. Something invisible surrounding us rapidly moves back and forth. And our ears can hear this movement.

I am writing this post to cover very basics of digital signal processing that I was very slow to understand. I will write concepts of Analogue-to-Digital conversion, sampling and Nyquist frequency.

Analogue vs Digital

Apart from the sound not usually visible to us, I think that I initially mixed up the concept of the digital signal with the analogue signal. I was still new to the idea that computers represent everything in discrete numbers. Two important things:
  • An analogue signal is a continuous signal that is present everywhere in the world we live in. 
  • A digital signal is a discrete signal that is only present inside a computer.
Signals can include sound, light and temperature but I work on speech data and limit discussion to audio signals in this post.

Our computers and phones can convert a digital audio signal to an analogue audio signal when we press a play button. This is Digital-to-Analogue conversion. Conversion of analogue to digital or vice versa is so smooth. This makes an impression that the signals stored in computers are analogue but they are stored in digital. 

Analogue-to-Digital conversion is the process to discretise a continuous signal. Essentially a recording session to capture speech or singing with a microphone and to store data in a computer. 

Analogue-to-Analogue conversion also exists. Recoding a sound with a needle in a record disk is to the process of keeping information in an analogue device for example.


The next section introduces the process required for Analogue-to-Digital conversion: sampling.

Sampling

Sampling is the process to copy and replicate an analogue signal in discrete space. As the name suggests, sampling takes "samples" of an analogue signal to represent the signal in a digital device. In other words, the digital signal is an imperfect copy of an analogue signal but very close to the original signal.


This simple sine waveform looks like a continuous smooth line. This is because the programme is being nice to draw a continuous line instead of showing only actual samples.

This figure is the result of asking the programme to only produce actual samples of the same signal. The upper and lower peaks still look continuous because many samples concentrate at those regions. However, the middles of each cycle (around ampiltude +-0.50) are clearly spaced with gaps.

This signal has 1,000 samples and 5 cycles. Having less samples and cycles makes the effect of sampling even more obvious e.g., 100 samples and 1 cycle.
Now, even the upper and lower regions of the signal have visible gaps. Hopefully, the relationship of samples with representation of the digital signal is clear.

Sampling rate, Frequency and Confusion with "Frequency"

We have seen two signals so far:
  • 1,000 samples and 5 cycles per second
  • 100 samples and 1 cycle per second
There are two concepts to characterise signals: sampling rate and frequency. Both use the unit Hertz (Hz). These values mean a different thing, but use the same unit. This was a tricky part to me.

The sampling rate (also referred to as sampling frequency) is the number of samples per second. The first signal has 1,000 samples for 1 second. This means that the sampling rate of the first signal is 1,000 Hz. The sampling rate exists only in digital and not in analogue signals. 

The signal frequency is the number of cycles per second. There are 5 cycles for 1 second, and the frequency of the first signal is 5 Hz. The signal frequency exists both in digital and analogue signals.

The confusing part is that the (signal) frequency is relevant to the "pitch" of the audio signal, while the sampling frequency just measures the number of samples per second. We can use 1,000 samples or 100,000 samples (sampling rate = 1,000 or 100,000) to represent a signal of 5 Hz, for example. This is a terminology mess of "frequency" to me.

A further confusion can be made with the formula below:
Total number of samples = Frequency x Duration (sec)

This means:

  • A signal of 32,000 total samples and duration of 2 seconds is the frequency of 16,000 Hz
  • A signal of duration 5 seconds and 4 Hz has the number samples = 20 samples
  • A signal of 20,000 samples and 5,000 Hz has duration of 4 seconds
The frequency in this formula is the number of cycles per second in a signal, not the sampling rate.

To summarise:
  • The frequency is the concept for both analogue and digital signals.
  • Anything involing sampling (sampilng rate and number of samples) is the concept for digital signals.

Nyquist Frequency

Another concept of digital signal processing using "frequency" is the Nyquist frequency. Nyquist said "we need to have 1,000 samples to capture the signal of 500 Hz", or formally:
The sampling rate / 2 = the highest (signal) frequency to capture in the signal

What this means is that the signal is not correctly represented if the number of samples does not meet the Nyquist frequency. This phenomenon is called "aliasing". The figures below illustrate an example of aliasing.

This figure shows the signal of 5 Hz (5 cycles per second) with 100 samples. We can see that 100 samples are more than enough to represent the signal of 5 Hz. The figure is annotated with red circles. The number of these red circles is 10. This number corresponds to the Nyquist frequency of this signal to represent the 5 Hz (N / 2 = 5 Hz).  Keeping 1 sample in each red circle results in the figure below:

It's a very pointy signal. The signal is still 5 Hz. Nyquist is right that representing a signal of a certain (signal) frequency requires twice samples of the value of the frequency.

Summary

I hope that the post explained the basic concepts of digital signal processing. I focused on the concepts I had hard time understanding, that was the difference between analogue and digital signals, and the terminology of "frequency". 

Comments

Popular posts from this blog

How wav2vec2.0 takes input audio data

Understanding kaldi lattice-prune and beam