<<

Analog

Music 171: Fundamentals of • Tamara Smyth, [email protected] A , of which a sinusoid is only one example, is Department of Music, a set, or sequence of numbers. University of California, San Diego (UCSD) • The term “analog” refers to the fact that it is October 15, 2019 “analogous” of the signal it represents. • A “real-world” signal is captured using a which has a diaphragm that is pushed back and forth according to the compression and rarefaction of the sounding .

Figure 1: The electrical signal used to represent the pressure variations of a is an .

• The microphone transforms this displacement into a time-varying —an analog electrical signal.

1 Music 171: Fundamentals of Digital Audio 2

Continuous-Time Signals Discrete-Time, Digital Signals

• Analog signals are continuous in time. • When analog signals are brought into a , they must be made discrete (finite and countable). • A continuous-time signal is an infinite and uncountable sequence of numbers, as are the possible • A discrete-time signal is a finite sequence of values each number can have. numbers, with finite possible values for each number. – – between a start and end time, there are infinite number values are limited by how many bits are possible values for time t and the waveform’s used to represent them (bit depth); instantaneous amplitude x(t). – can be stored on a digital storage medium. • A continuous signal cannot be stored, or processed, in a computer since it would require infinite data. • Analog signals must be discretized (digitized) to produce a finite set of numbers for computer use.

• Sampling: the process of taking individual values of a continuous-time signal (at regular time intervals).

Music 171: Fundamentals of Digital Audio 3 Music 171: Fundamentals of Digital Audio 4 Analog to Digital Conversion Sampling

• The process by which an analog signal is digitized is • Sampling: process of taking values (samples) of the called analog-to-digital or “a-to-d” conversion analog waveform at regularly spaced time intervals. • analog-to-digital converter (ADC): the device x(t) x[n] = x(nTs) that discretizes (digitizes) an analog signal. ADC • The ADC must accomplish two (2) tasks: 1. sampling: Ts = 1/fs – taking values (samples) at regular time intervals; Figure 2: The ideal analog-to-digital converter. 2. quantization: – assign a number to the value (using limited computer bits). • Sampling Rate: number of samples taken per second (Hz);

– fs = 48 kHz (professional studio)

– fs = 44.1 kHz (CD)

– fs = 32 kHz () • Sampling Period: time interval (in seconds) between samples:

Ts =1/fs seconds.

Music 171: Fundamentals of Digital Audio 5 Music 171: Fundamentals of Digital Audio 6

Sampled Sinusoids Question 1

• Sampling corresponds to transforming the continuous • If the following sinusoid was sampled at fs = 16 Hz, time variable t into a set of discrete times that are – what is the duration of the signal shown? integer n multiples of the sampling period Ts: 1 t −→ nTs. 0.8

• Integer n corresponds to the index in the sequence. 0.6 • Continuous sinusoid: 0.4 0.2 x(t)= A sin(ωt + φ). 0

• Discrete sinusoid −0.2

−0.4 x(n)= A sin(ωnTs + φ), −0.6 a sequence of numbers that may be indexed by n. −0.8

−1 0 5 10 15 20 25 Sample Index

• What would the duration be if fs = 32?

Music 171: Fundamentals of Digital Audio 7 Music 171: Fundamentals of Digital Audio 8 • Answer 1 If fs = 32, the duration is shorter: 24 3 24 × T = = = .75 s. s 32 4 • If fs = 16, what is the duration shown?

1

0.8

0.6

0.4

0.2

0

−0.2

−0.4

−0.6

−0.8

−1 0 5 10 15 20 25 Sample Index

• The sampling period (time between samples) is

Ts =1/16 s. Since 24 samples are shown, the duration is 24 3 24 × T = = =1.5 s. s 16 2

Music 171: Fundamentals of Digital Audio 9 Music 171: Fundamentals of Digital Audio 10

Question 2 Answer 2 (Method 1)

• If the following sinusoid was sampled at fs = 16 Hz, • If fs = 16, what is the of the sinusoid? – what is the frequency of the sinusoid? 1

0.8 1

0.6 0.8

0.4 0.6

0.2 0.4

0 0.2

−0.2 0

−0.4 −0.2

−0.6 −0.4

−0.8 −0.6

−1 −0.8 0 5 10 15 20 25 Sample Index −1 0 5 10 15 20 25 Sample Index • Method 1: – 16 samples corresponds to 1 second, – there are 2 cycles in 1 second (after 16 samples), – the frequency is 2 Hz.

Music 171: Fundamentals of Digital Audio 11 Music 171: Fundamentals of Digital Audio 12 • Answer 2 (Method 2) If fs = 32, then the frequency is higher: 1 32 f = = =4 Hz. T 8

• If fs = 16, what is the frequency of the sinusoid?

1

0.8

0.6

0.4

0.2

0

−0.2

−0.4

−0.6

−0.8

−1 0 5 10 15 20 25 Sample Index

• Method 2: the period of the sinusoid is 8 1 T =8 × T = = , s 16 2 and the frequency is 1 1 f = = =2 Hz. T 2

Music 171: Fundamentals of Digital Audio 13 Music 171: Fundamentals of Digital Audio 14

Sampling and Reconstruction Importance of Knowing Sampling Rate

• Once x(t) is sampled to produce x(n), time scale • If the signal is digitized and reconstructed using the is lost. same sampling rate, the frequency and duration will • x(n) may represent a number of possible . be preserved. • If reconstruction is done using a different sampling Continuous 2-Hz Sinusoid 1 rate, the time interval between samples 0.5 changes resulting in a change in 0

-0.5 – overall signal duration,

-1 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 – time to complete one cycle (period) and thus Time (s) 2-Hz Sinusoid Sampled at 32 Hz 1 sounding frequency. 0.5

0

-0.5

-1 0 5 10 15 20 25 30 Sample index 2-Hz Sinusoid Sampled at 32 Hz and Reconstructed at 16 Hz 1

0.5

0

-0.5

-1 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 Time (s)

• Reconstructing at half the sampling rate (Fs/2) will double the time between samples (2/Fs), making the sinusoid twice as long and halving the frequency.

Music 171: Fundamentals of Digital Audio 15 Music 171: Fundamentals of Digital Audio 16 Question 3 Answer 3

• A 220-Hz sinusoid is sampled at fs1 = 44100. It is • then played on an audio system having a different If a 220-Hz sinusoid sampled at fs1 = 44100 Hz is played back at fs2 = 22050 Hz (fs1/2), then the sampling rate of fs2 = 22050 Hz. – – At what frequency will the sinusoid sound? period between the samples will be twice as long: 1 1 2 2 Ts2 = = = = , fs2 22050 44100 fs1

– and the period of will double: 2 2 T2 =2T1 = = s, f1 220

– and the corresponding frequency will be halved (sound an octave lower): 1 220 f2 = = = 110 Hz. T2 2

Music 171: Fundamentals of Digital Audio 17 Music 171: Fundamentals of Digital Audio 18

Sampling in Practice II Question 4

• In the Beatles track “In My Life” (1:28) there is a • What is the sampling rate and frequency of the Baroque-style piano solo composed and played by following sinusoid?

George Martin: 1

– piano solo 0.8 Problem: George Martin’s couldn’t play fast enough! 0.6 Solution: 0.4

0.2 – play an octave lower and at half tempo 0 – record at 1/2 sampling rate (or “speed” if analog), −0.2 – play back at twice the rate at which it was −0.4 recorded. −0.6

Effect: The creates a sort of harpsichord −0.8 sound at the regular tempo and pitch. Why? −1 0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2 • Listen to how the original sound regains a piano Time (s) quality when played at 1/2 the sampling rate: – piano solo at 1/2 sampling rate • Note: Beatles recordings were actually analog, but the same principles apply!

Music 171: Fundamentals of Digital Audio 19 Music 171: Fundamentals of Digital Audio 20 Answer 4 Implications of Sampling

• Is a sampled sequence only an approximation of the • Give the sinusoid’s sampling rate and frequency. original? 1 • perfectly 0.8 Is it possible to reconstruct a sampled signal? 0.6 • 0.4 Will anything less than an infinite sampling rate

0.2 introduce error?

0 • How frequently must we sample in order to

−0.2 “faithfully” reproduce an analog waveform?

−0.4

−0.6

−0.8

−1 0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2 Time (s)

• The period is 2 seconds (or, there is 1/2 cycle after 1 second) and the frequency is 1/2 Hz. • The sinusoid has 8 samples in 1 second and thus the sampling rate is fs =8 Hz. • The period has 16 samples and is thus 16 × 1/8=2 seconds long. The frequency is thus .5 Hz.

Music 171: Fundamentals of Digital Audio 21 Music 171: Fundamentals of Digital Audio 22

Nyquist Sampling Theorem Digital Audio System

• The Nyquist Sampling Theorem states that:

A bandlimited continuous-time signal can be x(t) low−pass low−pass x(nTs) filter ADCCOMPUTER DAC filter sampled and perfectly reconstructed from its samples if the waveform is sampled over twice as fast as it’s highest frequency component. • • Nyquist limit: the highest frequency component Low-pass filter (left):

that can be accurately represented: – prevents components with frequency > fs/2 from entering the ADC. fmax < fs/2. • COMPUTER: • Nyquist frequency: sampling rate required to – accurately represent up to fmax: sound storage/processing; – processing may introduce components with fs > 2fmax. > fs/2. • No information is lost if sampling above 2fmax. • Low-pass filter (right): • No information is gained by sampling much faster – defines audible up to fs/2; than 2fmax. – does not prevent introduction of components • Is fs = 44, 100 Hz (CD-quality) enough? with frequency > fs/2 (“damage” already done)!

• What happens when frequencies exceed fs/2?

Music 171: Fundamentals of Digital Audio 23 Music 171: Fundamentals of Digital Audio 24 Undersampling What is an Alias?

• Discrete sinusoids have infinite aliases but it is the one lowest in frequency (< f /2) that will sound. • If a signal is undersampled, it will be interpreted as s the alias lying in the permitted range (f < fs/2); A 1−Hz Sinusoid Sampled at 2 Hz 1

0 A 3 Hz Sinusoid (critically sampled) 1 −1 0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2 Time (s) 0.5 A 3−Hz Sinusoid (Under)Sampled at 2 Hz 1 0

0

Amplitude −0.5

−1 −1 0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 Time (s) A 5−Hz Sinusoid (Under)Sampled at 2 Hz A 3 Hz Sinusoid (undersampled) is Interpreted as 1 Hz 1

1 0

0.5 −1 0 0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2 Time (s) −0.5 Amplitude −1 • ± 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 Infinite sinusoids (with frequencies f0 lfs) will Time (s) produce the same sample values as the sinusoid at f0. • Challenge: show by proving the following equality: • Undersampling a 3-Hz sinusoid at f =4 causes its s ± frequency to be interpreted as 1Hz. A cos(2πf0nTs + φ)= A cos(2π(f0 lfs)nTs + φ),

Music 171: Fundamentals of Digital Audio 25 Music 171: Fundamentals of Digital Audio 26

Aliasing / Folding over Folding Frequency (Nyquist Limit)

• • Let fin be the input signal and fout be the signal at Top 2 plots (blue): sinusoid has (infinite) aliases, the output (after the lowpass filter). but its frequency does not exceed f /2—GREAT! s • If fin is less than the Nyquist limit (fs/2) fout = fin, otherwise there is a folding over fs/2.

−2fs −fs 0 fs 2fs Folding of Frequencies About fs/2 2500

2000 −2fs −fs 0 fs 2fs

1500

−2fs −fs 0 fs 2fs

Folding Frequency fs/2 1000 Output Frequency

−2fs −fs 0 fs 2fs 500

0 • 0 500 1000 1500 2000 2500 Bottom 2 plots (red): sinusoid with frequency Input Frequency > fs/2 will have a negative frequency component with an alias in the sounding bandwidth (shaded). • The folding occurs because of aliases of the negative frequency components.

Music 171: Fundamentals of Digital Audio 27 Music 171: Fundamentals of Digital Audio 28 Foldover

Music 171: Fundamentals of Digital Audio 29 Music 171: Fundamentals of Digital Audio 30

Quantization Quantization (linear)

• Where sampling is the process of taking a sample at • The signal below has 11 possible values to which the regular time intervals... instantaneous amplitude may be quantized.

• Quantization is the process of assigning a value 10

(from a finite number of possibilities) to the 9

amplitude of the signal at a time sample. 8

use bits to store such data. 7 quantization 6 • The higher the number of bits used to represent a error value, the greater the number of possible values and 5 the more precise the sampled amplitude will be. 4 3 • With n bits, 2n possible values that can be 2 represented. 1

• For CD quality audio, the number of bits is n = 16: 0 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 – each sample can have 216 = 65, 536 possible values; – the highest possible amplitude is 215 = 32, 768, (since audio signals are positive and negative). • Does quantization introduce error?

Music 171: Fundamentals of Digital Audio 31 Music 171: Fundamentals of Digital Audio 32 Quantization Error Bit Depth

• In a linear converter, when the actual sample value • Computers use bits to store sample values—the falls between these values (solid blue lines), it is number of bits used is called the bit depth: the quantized (or rounded) to the nearest value. greater the bit depth,

10 – the greater the number of possible values,

9 – the more precise the sampled amplitude will be. 8 • With n bits, 2n possible values that can be 7 represented. quantization 6 error – for CD quality audio, n = 16, 5 – 16 4 each sample can have 2 = 65, 536 possible

3 values, – 15 2 the highest possible amplitude is 2 = 32, 768,

1 (since audio signals are positive and negative).

0 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

• This introduces a quantization error that will be uniformly distributed between 0 and 1/2 (error will never be greater than a factor of 1/2 the increment).

Music 171: Fundamentals of Digital Audio 33 Music 171: Fundamentals of Digital Audio 34

Signal to Quantization Error (SQNR)

• When is a result of quantization error, we determine its audibility using the signal-to-quantization-noise-ratio (SQNR), determined by the ratio of – the maximum amplitude (2n−1) to – the maximum quantization noise (1/2 for a linear converter). • To determine audibility, the SQNR is provided in decibels (dB): 2n−1 20log dB = 20log (2n) dB 10  1/2  10 × = n 20log10(2) dB ≈ n × 6 dB ≈ 96 dB (for 16 bits).

Music 171: Fundamentals of Digital Audio 35