SUNY Geneseo Department of Mathematics
Wednesday, February 8
Math 230 02
Spring 2017
Prof. Doug Baldwin
Coding (and other) book activities: are they graded?
No. They’re good practice for you, but I treat all the book’s interactive activities as optional.
The theorem: to correctly reproduce a sampled waveform, you must sample it at least twice per cycle (i.e., at a frequency at least double the highest frequency in the waveform).
Goal: Read a sound file into Matlab and then resample it to ever-lower sampling rates until we can hear Nyquist aliasing.
Relevant ideas from the reading
wavread
function reads .wav files into Matlab (but note: in the latest Matlab the function is now audioread
)audioread
looks like [ySound,frequency] = audioread( 'filename.wav' )
Here’s what we did in Matlab to read and play a sound file:
>>[ ySound, freq ] = audioread( 'Vogelfaenger.wav' );
>> sound( ySound, freq )
In other words, pick every 2nd sample, every 4th sample, etc.
Relevant ideas from the reading
myArray( [3,4,5] )
would pick out elements 3, 4, and 5myArray( [3,4,5] ) = [10,20,30]
Here’s how we resampled the music clip and played the results:
>> ySound2 = ySound( 2:2:length(ySound), : );
>> freq2 = freq / 2;
>> sound( ySound2, freq2 )
>> ySound12 = ySound( 1:12:length(ySound), : );
>> freq12 = freq/12;
>> sound( ySound12, freq12 )
Plotting in Matlab
Read sections 6.3 and 6.4