Download Lecture Notes on Sound Processing - Computing for Engineers | CS 1371 and more Study notes Computer Science in PDF only on Docsity!
CS
Introduction to Computing
for Engineers^ Processing Sound
Sound Basics in Matlab
LearningObjectivesLearn about howsound is stored,and how to accessand manipulatethe data
Topics •^ Anatomy of a sound •^ Sound representation in Matlab •^ Getting sound into and out ofMatlab •^ Sound analysis and processing
Sound Amplitude
•^ Usually reported in decibels^ –^ intensity of a sound in decibels is calculated as:
I= 10 logDB^
( I / I) 10 0
where I is the measured pressure fluctuation, and I^ is a reference pressure^0 » usually established as the lowest pressure fluctuation a reallygood ear can detect, 2
-4^ × 10 dynes / cm.
2
•^ a^ not-too-painful
sound
level
of,^ say,
100db
has^
a
pressure amplitude 10
10 (10 billion) times as loud as the
lowest perceivable sound.
Sound Frequency
•^ The normal human ear can detect sounds betweenabout 50Hz and 15kHz •^ High fidelity systems must be able to record andplay back sound in these frequency ranges. •^ Telephone conversations sound odd because thetelephone system limits the upper frequency to4kHz. •^ Excessive exposure to loud noise causes your earsto lose sensitivity in the upper and lower frequencyranges.
Matlab Capabilities
-^ Matlab has tools for reading sound files in two formats:^ –^ .wav
files ( wavread(…)
), and
-^ .au^ files (
auread(…)
-^ Both return three variables:^ –^ vector of sound values in the range (0 … 1),^ –^ sampling frequency in Hz (samples per second), and^ –^ number of bits used to record the data (8 or 16). •^ Examine the following example comparing two recordings at 16 bitand 8 bit resolution respectively. >>^ [b16,
F16,^
n]^ =^ wavread('brooklyn16.wav');
^ fprintf('bit
size^ of^ b is^ %d\n',
n);
bit^ size
of^ b
is^16
^ sound(b16,
F16)
^ [b8,
F8,^ n]
=^ wavread('brooklyn8.wav');
^ fprintf('bit
size^ of^ b^ is^ %d\n',
n);
bit^ size
of^ b is^8
^ sound(b8,
F8)
Basic digital sound processing
Fs
D / A Samplingfrequency Digital Processing wavread(…)
sound(…) Read fromdata file
Slicing and Concatenating Sound
•^ constructing an “audio ransom note”^ –^ choosing and assembling words from publishedspeeches.^ –^ strictly experimental in nature, but^ –^ can produce some interesting results. •^ There are a number of web sites that offer free .wav filescontaining memorable speech fragments from movies,TV shows and cartoons
[1].
[1]^ beware, however, when looking for materials. Some web sites store .wavfiles in a compressed form that Matlab cannot decode. When you find a file,save it to disk and make sure that Matlab’s wavread(…) function can open itcorrectly.
Slicing and Concatenating Sound
-^ assembling
parts^
of^ these
speeches
into^
a^ semi-coherent
conversation. • Consider the following scripts: ¾ Step^1
-^ find
the^ “problem
speech”
[houston,
Fsh]^ =^ wavread('a13prob.wav'); sound(houston,
Fsh);
¾^ Step
2 –^ extracting
the^ “problem
speech”
subplot(1,
2,^ 1)
plot(houston); clip^ =
prob^ = houston(clip:end)*2; subplot(1,
2,^ 2)
plot(prob)
Selected experimentally by plottingand listening^ Make it louder
Extract from “Gone with the Wind”
•^ remove “my dear” from the “frankly, my dear ..” speech,reducing its amplitude by a half ¾^ Step 3 – removing ‘my dear’
[damn, Fsd]^ =^ wavread('givdamn2.wav'); subplot(1,
2,^ 1)
plot(damn); lo^ =^ 4500; hi^ =^ 8700; sdamn^ =^ [damn(1:lo);
damn(hi:end)
]^ *^ .5;
subplot(1,
2,^ 2)
plot(sdamn);
Selected experimentally by plottingand listening
Make it softer
Slicing and Concatenating Sound^ Complete speech
“my dear” removed
Playing it Backwards
•^ Since the sound is a vector of data, reversing the vectorwill play it backwards: ¾^ Step 5 – reversing the speech
backwards
=^ speech(end:-1:1); sound( backwards,
Fst);
Changing Sound Pitch (the hard way) • manipulate “piano.wav” to produce a snippet of music. • This file is a recording 17
[1]^ of a single note played on a
piano. • If a sound is played at twice its natural frequency, it isheard as one musical octave higher. • The steps from one note to the next higher octave aredivided 12 half note steps. • These 12 half steps are logarithmically divided where thefrequency change is 2
•^ Practical issues:^ –^ Cannot concatenate notes because they are played at differentfrequencies^ –^ Duration of the notes must be managed •^ [1]^ credit: http://chronos.ece.miami.edu/~dasp/samples/samples.html
Code for playing a simple tune %
pitch length smallworld = [ 1 3;
% C 1 1; % C 3 2; % E 1 2; % C 2 3; % D 2 1; % D 2 4] % D l = length(smallworld); for i = 1:l^ f = freq(smallworld(i,1));^ d = dur(smallworld(i,1)) * smallworld(i,2);^ sound(note(1:d), f);^ pause(wait*smallworld(i,2)); end
Changing Sound Frequency (the right way) • The problem with the previous technique is that you arechanging the playback frequency. Consequently, youcan’t assemble the whole tune into a file that can besaved and played back by an ordinary music player. • We need a technique for changing the frequency of anote without changing its playback frequency. • We can accomplish this by adding or removing datasamples to extend or shorten the note vector.^ half = 2^(1/12)[note Fs] = wavread(‘piano.wav’);sound(note, Fs) % plays the note at its natural pitchsound(note(round(1:half^2:end)), Fs) 20
% raises a whole step
sound(note (round(1:half^-4:end)), Fs)
% lowers 2 whole steps