lab #8 follow-up: sounds and signals* * figures from kaplan, d. (2003) introduction to scientific...

23
Lab #8 Follow-Up: Sounds and Signals* * Figures from Kaplan, D. (2003) Introduction to Scientific Computation and Programming CLI Engineering.

Upload: everett-bishop

Post on 25-Dec-2015

221 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lab #8 Follow-Up: Sounds and Signals* * Figures from Kaplan, D. (2003) Introduction to Scientific Computation and Programming CLI Engineering

Lab #8 Follow-Up:

Sounds and Signals*

* Figures from Kaplan, D. (2003) Introduction to Scientific Computation and Programming CLI Engineering.

Page 2: Lab #8 Follow-Up: Sounds and Signals* * Figures from Kaplan, D. (2003) Introduction to Scientific Computation and Programming CLI Engineering

• Recall transducer concept convert input signal

into numbers.

• Signal: a quantity that changes over time– Body temperature– Air pressure (sound)– Electrical potential on skin (electrocardiogram)– Seismological disturbances– Stock prices

Intro to Sounds & Signals

Page 3: Lab #8 Follow-Up: Sounds and Signals* * Figures from Kaplan, D. (2003) Introduction to Scientific Computation and Programming CLI Engineering

• We will study audio signals (sounds), but the same issues apply across a broad range of signal types.

• Two different approaches to doing the same thing:

– Commercial GUI program (Audacity, Pro Tools)– Programmatic (Python)

Intro to Sounds & Signals

Page 4: Lab #8 Follow-Up: Sounds and Signals* * Figures from Kaplan, D. (2003) Introduction to Scientific Computation and Programming CLI Engineering

13.1 Basics of Computer Sound>>> x, fs, bits = wavread("fh.wav")>>> len(x)41777 >>> min(x), max(x)('\x00', '\xff')>>> fs11025>>> bits8

Page 5: Lab #8 Follow-Up: Sounds and Signals* * Figures from Kaplan, D. (2003) Introduction to Scientific Computation and Programming CLI Engineering

Basics of Computer Sound

Page 6: Lab #8 Follow-Up: Sounds and Signals* * Figures from Kaplan, D. (2003) Introduction to Scientific Computation and Programming CLI Engineering

Basics of Computer Sound

Page 7: Lab #8 Follow-Up: Sounds and Signals* * Figures from Kaplan, D. (2003) Introduction to Scientific Computation and Programming CLI Engineering

Basics of Computer Sound

• x contains the sound waveform (signal) – essentially, voltage levels representing transduced air pressure on microphone.

• fs is the sampling frequency (rate) – how many time per second (Hertz, Hz), did we measure the voltage?

• bits is the number of bits used to represent each sample.

Page 8: Lab #8 Follow-Up: Sounds and Signals* * Figures from Kaplan, D. (2003) Introduction to Scientific Computation and Programming CLI Engineering

Questions

• Why does the sound waveform range from hexadecimal 00 to FF, whereas we plot it as -1 to +1?

– These values are essentially arbitrary. One nice feature of a ±x representation is that zero means silence. But the audio player likes values between 0 and 255.

• What role does the sampling frequency play in the quality of the sound?– The more samples per second, the closer the

sound is to a “perfect” recording.

Page 9: Lab #8 Follow-Up: Sounds and Signals* * Figures from Kaplan, D. (2003) Introduction to Scientific Computation and Programming CLI Engineering

Questions

• What happens if we double (or halve) the sampling frequency at playback, and why?

• What is it about the waveform that determines the sound we're hearing (which vowel), and the speaker's voice?

Page 10: Lab #8 Follow-Up: Sounds and Signals* * Figures from Kaplan, D. (2003) Introduction to Scientific Computation and Programming CLI Engineering

Questions

• What is it about the waveform that determines the sound we're hearing (which vowel), and the speaker's voice?–Most of this information is encoded in the

frequencies that make up the waveform – roughly, the differences between locations of successive peaks – and not in the actual waveform values themselves.

–We can do some useful processing on the “raw” waveform, however – e.g., count syllables:

Page 11: Lab #8 Follow-Up: Sounds and Signals* * Figures from Kaplan, D. (2003) Introduction to Scientific Computation and Programming CLI Engineering

Syllable Counting by Smoothing and Peak-Picking

Page 12: Lab #8 Follow-Up: Sounds and Signals* * Figures from Kaplan, D. (2003) Introduction to Scientific Computation and Programming CLI Engineering

Perception and Generation of Sound

• Sound is the perception of small, rapid vibrations in air pressure on the ear.

• Simplest model of sound is a function P(t) expressing pressure P at time t:

P(t) = A sin(2πft + φ)

where A = amplitude (roughly, loudness)

f = frequency (cycles per second)φ = phase (roughly, starting point)

• This is the equation for a pure musical tone (just one pitch)

Page 13: Lab #8 Follow-Up: Sounds and Signals* * Figures from Kaplan, D. (2003) Introduction to Scientific Computation and Programming CLI Engineering

Perception and Generation of Sound

– Inverse of frequency is period (distance between peaks):

Page 14: Lab #8 Follow-Up: Sounds and Signals* * Figures from Kaplan, D. (2003) Introduction to Scientific Computation and Programming CLI Engineering

Perception and Generation of Sound

–E.g., whistling a musical scale:

Page 15: Lab #8 Follow-Up: Sounds and Signals* * Figures from Kaplan, D. (2003) Introduction to Scientific Computation and Programming CLI Engineering

Transducing and Recording Sound

• Convert sound pressure to voltage, then digitize voltage into N discrete values in interval [x

min, x

max], by sampling at frequency F

s.

• This is done by a analog /digital converter.• Another device must pre-amplify sound to match

input expectations of a/d converter.• N is typically a power of 2, so we can use bits to

express sampling precision (minimum 8 for decent quality). This is called quantization.

• Various things can go wrong if we don't choose these values wisely....

Page 16: Lab #8 Follow-Up: Sounds and Signals* * Figures from Kaplan, D. (2003) Introduction to Scientific Computation and Programming CLI Engineering

A segment of the sound “OH” transduced to voltage.

Top: The preamplifier has been set appropriately so that the analog voltage signal takes up a large fraction of the A/D voltage range. The digitized signal closely resembles the analog signal even though the A/D conversion is set to 8 bits.

Bottom: The preamplifier has been set too low. Consequently, there is effectively only about 3 bits of resolution in the digitized signal; most of the range is unused.

Transducing and Recording Sound

0 2 4 6 8 10 12 14-4

-2

0

2

4

Vol

tage

Appropriate preamplification

0 2 4 6 8 10 12 14-96

-64

-32

0

32

64

96

A/D

uni

ts

AnalogDigital

0 2 4 6 8 10 12 14

-0.1

0

0.1

Vol

tage

Time (ms)

Preamplification too low

0 2 4 6 8 10 12 14

-4

-2

0

2

4

A/D

uni

ts

Page 17: Lab #8 Follow-Up: Sounds and Signals* * Figures from Kaplan, D. (2003) Introduction to Scientific Computation and Programming CLI Engineering

Figure 13.6.

Clipping of a signal (right) when the preamplifier has been set too high, so that the signal is outside of the −5 to 5 V range of the A/D converter.

Transducing and Recording Sound

Page 19: Lab #8 Follow-Up: Sounds and Signals* * Figures from Kaplan, D. (2003) Introduction to Scientific Computation and Programming CLI Engineering

Aliasing and the Sampling Frequency• Someone has an alias when they use more than

one name (representation)• In the world of signals, this means having more

than one representation of an analog signal, because of inadequate sampling frequency

• Familiar visual aliasing from the movies (when 32 frames per second is too slow)• Wagon wheel / propeller going backwards• Scan lines appearing on computer screen

• Inadequate Fs can result in aliasing for sounds

too....

Page 20: Lab #8 Follow-Up: Sounds and Signals* * Figures from Kaplan, D. (2003) Introduction to Scientific Computation and Programming CLI Engineering

Aliasing and the Sampling Frequency

Page 21: Lab #8 Follow-Up: Sounds and Signals* * Figures from Kaplan, D. (2003) Introduction to Scientific Computation and Programming CLI Engineering

Aliasing and the Sampling Frequency

Aliasing. A set of samples marked as circles. The three sine waves plotted are of different frequencies, but all pass through the same samples. The aliased frequencies are F +m/∆T, where m is any integer and ∆T is the sampling interval. The sine waves shown are m = 0, m = 1, and m = 2. 0 1 2 3

-1

0

1

Time (T)

Am

plitu

de

m = 0m = 1m = 2samples

Page 22: Lab #8 Follow-Up: Sounds and Signals* * Figures from Kaplan, D. (2003) Introduction to Scientific Computation and Programming CLI Engineering

Aliasing and the Sampling Frequency

• Nyquist's Theorem tells us that Fs should be at

least twice the maximum frequency Fmax

we wish to reproduce.

• Intuitively, we need two values to represent a single cycle: one for peak, one for valley:

Page 23: Lab #8 Follow-Up: Sounds and Signals* * Figures from Kaplan, D. (2003) Introduction to Scientific Computation and Programming CLI Engineering

Aliasing in the Time Domain