Module 3 - Digital Signal
Speech Processing > Module 3 > Digital Speech Signals > Videos > Digital signal
음성 처리의 첫 번째 단계는 시간 영역에서 신호를 캡처하여 컴퓨터에서 디지털 버전으로 만드는 것입니다.
다음은 음파를 측정하는 데 사용되는 마이크입니다.
마이크의 출력은 아날로그 전압입니다.
이를 디지털 신호로 변환하여 저장하고 컴퓨터로 조작할 수 있도록 해야 합니다.
아날로그 신호를 디지털 신호로 변환하려면 어떻게 해야 할까요?
다시 말해, 여기서 무슨 일이 일어나고 있을까요?
아날로그 영역에서는 모든 것이 원활하고 연속적으로 움직입니다.
예를 들어 이 아날로그 시계의 바늘을 보세요.
시계 바늘은 가장 가까운 초 단위뿐만 아니라 무한히 정밀하게 시간을 알려줍니다.
하지만 이와는 대조적으로 디지털 영역에서는 무언가가 취할 수 있는 값의 수가 정해져 있고 정밀도가 유한합니다.
따라서 디지털 시계는 가장 가까운 초까지만 시간을 알려줍니다.
디지털 시계는 시간을 불연속적으로 만들었으며, 이는 현실의 근사치입니다.
그렇다면 컴퓨터는 왜 아날로그 값을 저장할 수 없을까요?
컴퓨터는 2진수만 저장할 수 있기 때문입니다.
모든 것은 2진수로 표현되어야 합니다.
컴퓨터 내부의 한정된 저장 공간에 저장해야 합니다.
따라서 파형(waveform)의 경우 두 가지 의미가 있습니다.
1) 파형의 진폭은 2진수여야 하므로 고정된 정밀도로 표현해야 합니다.
2) 진폭(amplitude)을 초당 유한한 횟수만큼만 저장할 수 있으며, 그렇지 않으면 무한한 저장 공간이 필요합니다.
먼저 이 이진수를 생각해 봅시다.
1비트에는 두 가지 가능한 값이 있습니다.
2비트를 사용하면 4가지 값을 얻을 수 있습니다.
3비트를 사용하면 8개의 값을 얻을 수 있습니다.
파형의 진폭은 2진수로 저장해야 합니다.
하지만 먼저 시간을 디지털로 만드는 것, 즉 시간을 불연속적으로 만드는 것을 고려해 봅시다.
이 음성 파형을 확대해 봅시다.
매끄럽고 연속적인 것처럼 보이지만 좀 더 확대하고 계속 확대하면 이 파형이 불연속적인 샘플을 가지고 있음을 알 수 있습니다.
이 플롯의 점들을 연결하는 선은 단지 보기 좋게 하기 위한 것이며 파형을 보는 데 도움을 주기 위한 것입니다.
실제로 진폭은 이 고정된 시간 간격으로만 저장됩니다.
이 플롯의 각 점은 파형의 샘플입니다.
먼저 파형을 얼마나 자주 샘플링할지 결정해 봅시다.
개별 샘플을 연결하는 선으로 일반적인 방식으로 이 사인파를 그리고 있는데, 이 샘플을 볼 수 없으므로 각 샘플에 점을 하나씩 찍어 보겠습니다.
이 샘플은 너무 자주 샘플링되어 개별 포인트를 거의 볼 수 없습니다.
하지만 샘플링 속도를 줄이겠습니다.
초당 샘플 수가 줄어들고 이제 개별 샘플을 볼 수 있습니다.
선은 시각적 보조 수단일 뿐이며 파형의 값은 해당 샘플 지점에서만 정의된다는 점을 기억하세요.
샘플링 속도를 계속 줄이면 여기까지입니다.
이보다 더 낮추면 사인파를 저장할 수 없습니다.
사이클당 한 번도 오르내리지 않습니다.
특정 주파수를 저장하려면 파형의 주기당 최소 두 개의 샘플이 필요하다는 사실을 발견했습니다.
다시 말해, 캡처할 수 있는 최고 주파수는 샘플링 주파수의 절반입니다.
이는 매우 특별한 값으로, 이름도 있을 정도로 특별한데, 이를 나이퀴스트 주파수(Nyquist frequency)라고 합니다.
디지털 파형에는 나이퀴스트 주파수 이상의 주파수가 포함될 수 없으며, 나이퀴스트 주파수(Nyquist frequency)는 샘플링 주파수의 절반에 불과합니다.
하지만 만약 주파수가 나이퀴스트 주파수(Nyquist frequency)보다 높은 신호를 샘플링하려고 하면 어떻게 될까요?
여기 사인파가 있고 이 사인파의 샘플을 나이퀴스트 주파수(Nyquist frequency)보다 덜 자주 채취해 봅시다.
무슨 일이 일어나고 있는지 더 쉽게 볼 수 있도록 이 점들 사이에 선을 그려보겠습니다.
이 파형은 원래 사인파와는 전혀 다른 모양입니다!
사인파를 충실하게 표현하지 않은 새로운 신호를 생성한 것입니다.
원래 신호 및 샘플링 주파수와 관련된 새로운 주파수를 생성하는 이러한 효과를 앨리어싱(aliasing)이라고 합니다.
이는 피해야 할 현상입니다!
아날로그 신호에서 샘플링할 때마다 먼저 나이퀴스트 주파수 이상의 모든 주파수를 제거해야 하며, 그렇지 않으면 앨리어싱이 발생합니다.
이와 같은 디지털 신호를 샘플링할 때도 샘플링 주파수를 줄여야 합니다.
샘플링 주파수의 효과를 들어보겠습니다.
이 신호들은 모두 올바르게 샘플링된 신호입니다.
샘플링 속도를 변경하기 전에 나이퀴스트 주파수 이하의 모든 것을 제거했습니다.
음성의 경우 샘플링 속도는 16kHz가 적당하며 이 정도면 괜찮게 들립니다.
샘플링 속도를 줄여서 들어보겠습니다.
일부 고주파가 손실되었습니다.
고주파가 더 많이 손실되었습니다.
그리고 훨씬 더 많이요.
샘플링 속도가 4kHz로 매우 낮더라도 음성은 여전히 알아들을 수 있습니다.
음높이는 여전히 인식할 수 있지만 일부 소리가 손실되었습니다.
마찰음은 더 높은 주파수에 있기 때문에 사라지기 시작합니다.
제가 몇 가지 다른 용어를 혼용해서 사용하고 있다는 것을 눈치채셨길 바랍니다.
'샘플링 빈도(sampling frequency)'라고도 하고, '샘플링 속도(sampling rate)'라고도 하고, 그냥 '샘플 속도(sample rate)'라고도 합니다. 모두 같은 의미의 상호 교환 가능한 용어입니다.
그래서 우리는 시간을 불연속적으로 만드는 것을 다루었습니다.
sampling rate를 선택하는 것이 가장 중요한 결정입니다.
자동 음성 인식의 경우 16kHz도 괜찮지만, 음성 합성의 경우 일반적으로 이보다 더 높은 샘플링 속도를 사용합니다.
이제 진폭을 디지털 또는 이산 진폭(amplitude discrete)으로 만들어 보겠습니다.
다음은 제가 샘플링한 파형입니다: 샘플링 속도를 선택했고 시간 간격이 균일한 샘플이 있습니다.
이제 각 샘플의 값을 적어야 하고, 이를 이진수로 적어야 하는데, 이는 이진수에 사용할 비트 수를 선택해야 한다는 것을 의미합니다.
2비트를 사용하기로 선택하면 4단계로 나뉘게 됩니다.
따라서 이러한 각 샘플은 사용 가능한 가장 가까운 값으로 저장해야 하는데, 이를 양자화(quantisation)라고 합니다.
비트 심도(bit depth)를 선택해야 하지만 매우 일반적인 값이 있는데, 샘플당 16비트이므로 2를 제곱하여 16개의 사용 가능한 개별 레벨을 얻을 수 있습니다.
진폭 축의 음수 부분과 양수 부분을 모두 아우르는 데 사용해야 합니다.
따라서 일부 소프트웨어에서 진폭 축에 샘플 값으로 레이블이 지정된 것을 볼 수 있습니다.
값 중 하나가 0이어야 하기 때문에 -32,768에서 +32,767까지가 될 수 있습니다.
각 샘플을 저장하는 데 사용되는 비트 수를 비트 심도라고 합니다.
비트 심도를 변경하고 특히 가장 일반적인 값인 16비트에서 더 작은 값으로 줄였을 때 어떤 효과가 있는지 들어보겠습니다.
괜찮게 들립니다.
꽤 괜찮게 들립니다.
헤드폰으로 들어보면 약간의 차이가 들릴 수 있습니다.
꽤 거칠게 들립니다.
마음의 준비를 하세요. 2비트로 내려갑니다...
꽤 끔찍하네요!
하지만 샘플링 주파수를 변경하는 효과와는 완전히 다릅니다.
비트 심도를 낮추는 것은 원래 신호에 노이즈를 추가하는 것과 같습니다.
실제로 각 샘플을 가능한 가장 가까운 값으로 위 또는 아래로 이동해야 하기 때문에 원본 신호에 노이즈가 추가됩니다.
비트 수가 적을수록 값이 적기 때문에 더 많은 노이즈가 발생하며, 노이즈는 양자화된 신호와 원본 사이의 오차를 의미합니다.
비트 심도를 줄이는 경우는 거의 없으며, 거의 모든 경우에 16비트를 사용합니다.
2비트를 사용하면 실제로 해당 값을 볼 수 있습니다.
이 파형을 자세히 살펴보면 파형 내에 네 가지 다른 값만 있음을 알 수 있습니다.
이는 2진수 비트로 얻을 수 있는 네 가지 값과 관련이 있습니다.
마이크가 제공하는 아날로그 신호로 시간 영역에서 시작했습니다.
이는 마이크로 측정한 압력 변화의 아날로그 신호입니다.
하지만 이제 우리는 그 신호의 디지털 버전을 갖게 되었습니다.
디지털화된다는 것은 이제 컴퓨터를 사용하여 신호에 대한 모든 종류의 정교하고 흥미로운 작업을 수행할 수 있다는 것을 의미합니다.
매우 편리하죠.
하지만 디지털 신호에는 한계가 있다는 사실을 항상 염두에 두어야 합니다.
우리는 근사치를 만들었습니다.
항상 염두에 두어야 할 가장 중요한 한계는 샘플링 주파수입니다.
이는 애플리케이션에 따라 달라질 수 있는 부분입니다.
비트 심도 역시 염두에 두어야 할 사항이지만, 실용적인 측면과 목적상 범용 비트 심도인 16을 사용하겠습니다.
양자화 노이즈는 무시할 수 있는 수준이며 일반적으로 이 값을 변경하지 않을 것입니다.
이제 디지털 신호가 생겼으니 음성 처리를 할 준비가 되었습니다.
가장 중요한 프로세스 중 하나는 푸리에 분석을 사용하여 시간 영역에서 주파수 영역으로 이동하는 것입니다.
The very first step in processing speech is to capture the signal in the time domain and create a digital version of it in our computer.
Here's a microphone being used to measure a sound wave.
The output of the microphone is an analogue voltage.
We need to convert that to a digital signal so we can both store it and then manipulate it with a computer.
How do we convert an analogue signal to a digital one?
In other words, what is happening here?
In the analogue domain, things move smoothly and continuously.
Look at the hands on this analogue watch, for example.
It tells the time with infinite precision, not just to the nearest second.
But in stark contrast, in the digital domain, there are a fixed number of values that something can take: there is finite precision.
So this digital clock does only tell the time to the nearest second.
It has made time discrete, and that's an approximation of reality.
So why cannot computers store analogue values?
It's because computers only store binary numbers, nothing else.
Everything has to be represented as a binary number.
It has to be placed in the finite amount of storage available inside the computer.
So, for our waveform, there are two implications of that.
1) we have to represent the amplitude of the waveform with some fixed precision, because it's going to have to be a binary number.
2) we can only store that amplitude a finite number of times per second, otherwise we would need infinite storage.
Start by considering these binary numbers.
With one bit, we have two possible values.
With two bits, we get four values.
With three bits, we get eight values, and so on.
The amplitude of our waveform has to be stored as a binary number.
But let's first consider making time digital: making time discrete.
Let's zoom into this speech waveform.
It appears to be smooth and continuous, but zoom in some more, and keep zooming in, and eventually we'll see that this waveform has discrete samples.
The line joining up the points on this plot is just to make it pretty; it's to help you see the waveform.
In reality, the amplitude is only stored at these fixed time intervals.
Each point in this plot is a sample of the waveform.
Let's first decide how frequently we should sample the waveform.
I'm drawing this sine wave in the usual way with a line joining up the individual samples, and you can't see those samples, so I'll put a point on each sample.
This is sampled so frequently, we can barely see the individual points.
But let's reduce the sampling rate.
There are fewer samples per second, and now you can see the individual samples.
Remember, the line is just a visual aid: the waveform's value is defined only at those sample points.
Keep reducing the sampling rate, and that's as far as we can go.
If we go any lower than this, we won't be able to store the sine wave.
It won't go up and down once per cycle
We have discovered that, to store a particular frequency, we need to have a least two samples per cycle of the waveform.
Another way of saying that is: the highest frequency that we can capture is half of the sampling frequency.
That's a very special value, so special it has a name, and it's called the Nyquist frequency.
A digital waveform cannot contain any frequencies above the Nyquist frequency, and the Nyquist frequency is just half the sampling frequency.
But what would happen then, if we did try to sample a signal whose frequency is higher than the Nyquist frequency?
Here's a sine wave and let's take samples of it less often than the Nyquist frequency.
To make it easier to see what's happening, I'm going to draw a line between these points.
This waveform doesn't look anything like the original sine wave!
We've created a new signal that's definitely not a faithful representation of the sine wave
This effect of creating a new frequency, which is related to the original signal and to the sampling frequency, is called aliasing.
It's something to be avoided!
Whenever we sample on analogue signal, we must first remove all frequencies above the Nyquist frequency, otherwise we'll get aliasing.
We must also do that if we take a digital signal like this one on reduce its sampling frequency.
Let's listen to the effect of sampling frequency.
These are all correctly-sampled signals.
We've removed everything below the Nyquist frequency before changing the sampling rate.
For speech, a sampling rate of 16 kHz is adequate, and that sounds fine.
Let's listen to reducing the sampling rate.
We've lost some of the high frequencies.
We've lost even more of the high frequencies
And even more of them.
Even at this very low sampling rate of 4 kHz, speech is still intelligible.
We can still perceive pitch, but we've lost some of the sounds.
The fricatives are starting to go because they're at higher frequencies.
Hopefully, you've noticed that I've been using a few different terms interchangeably.
I've said 'sampling frequency', I've said 'sampling rate', or perhaps just 'sample rate'.
Those are all interchangeable terms that mean the same thing.
So we've dealt with making time discrete.
That's the most important decision: to choose the sampling rate.
For Automatic Speech Recognition, 16 kHz will be just fine, but for Speech Synthesis typically we'd use a higher sampling rate than that.
Let's turn over to making amplitude digital or amplitude discrete.
Here's waveform that I've sampled: I've chosen the sampling rate and we have samples evenly spaced in time.
Now I've got to write down the value of each sample, and I've got to write that down as a binary number, and that means I have to choose how many bits to use for that binary number.
Maybe I'll choose to use two bits, and that will give me four levels.
So each one of these samples would just have to be stored as the nearest available value: that's called quantisation.
We need to choose a bit depth, but there is a very common value, and that's 16 bits per sample, and that gives us 2 to the power 16 available discrete levels.
We have to use them to span both the negative and positive parts of the amplitude axis.
So just sometimes in some pieces of software, you might see the amplitude axis labelled with a sample value.
That would go from -32,768 up to +32,767 because one of the values has to be zero.
The number of bits used to store each sample is called the bit depth.
Let's listen to the effect of changing the bit depth, and in particular reducing it from this most common value of 16 bits to some smaller value.
That sounds absolutely fine.
That sounds pretty good.
Listen on headphones, and you might hear small differences.
That sounds pretty nasty.
Brace yourself: we're going down to two bits...
Pretty horrible!
It's quite different though to the effect of changing the sampling frequency.
Reducing the bit depth is like adding noise to the original signal.
In fact, it is adding noise to the original signal because each sample has to be moved up or down to the nearest possible available value.
With fewer bits, there are fewer values and therefore more noise is introduced, noise being the error between the quantised signal and the original.
Very rarely do we bother reducing the bit depth, and we stick with 16 bits for almost everything.
With two bits, we can actually see those values.
If we look carefully on this waveform, we can see there are only four different values within the waveform.
Those relate to the four possible values we get with two binary bits.
We started in the time domain, with an analogue signal provided by a microphone.
That's an analogue of the pressure variation measured by that microphone.
But now we have a digital version of that signal.
Going digital means that we can now do all sorts of sophisticated, exciting operations on the signal using a computer.
That's extremely convenient.
But you must always be aware that the digital signal has limitations.
We have made approximations.
The most important limitation to always bear in mind is the sampling frequency.
That's something we might want to vary, depending on our application.
Bit depth is also something to bear in mind, but in practical terms and for our purposes, we're just going to use a universal bit depth of 16.
That's plenty: the quantisation noise is negligible, and we won't generally be varying that value.
Now we have a digital signal, we're ready to do some speech processing.
One of the most important processes is to use Fourier analysis to take us from the time domain to the frequency domain.