0% found this document useful (0 votes)
32 views

Part 2 Basic Audio Mat Lab

The document discusses audio processing techniques in MATLAB. It demonstrates how changing the sample rate of an audio signal affects the playback duration and perceived pitch. Increasing the sample rate results in a shorter, higher pitched sound, like Donald Duck. Decreasing the sample rate produces a longer, lower pitched sound. The document also shows how to record audio from a microphone in MATLAB and save it as a wav file.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

Part 2 Basic Audio Mat Lab

The document discusses audio processing techniques in MATLAB. It demonstrates how changing the sample rate of an audio signal affects the playback duration and perceived pitch. Increasing the sample rate results in a shorter, higher pitched sound, like Donald Duck. Decreasing the sample rate produces a longer, lower pitched sound. The document also shows how to record audio from a microphone in MATLAB and save it as a wav file.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Part II Basic Audio Processing

1. Play the wav file


load handel.mat
wavplay(y, Fs);
2.

% Load the signals stored in handel.mat


% Playback of the signals

Play the music at different levels. If we change the sample rate during playback, it will affect the time
duration as well as the perceived pitch. In the following example, we shall increase the sample rates
gradually, so you will hear a shorter sound with high-pitch, similiar to the sound of the Disney cartoon
character Donald Fauntleroy Duck.

wavplay(y, 1.0*fs, 'sync');


wavplay(y, 1.5*fs, 'sync');
wavplay(y, 2.0*fs, 'sync');

% Playback at the original speed wavplay(y, 1.2*fs, 'sync');


% Playback at 1.5 times the original speed
% Playback at 2.0 times the original speed

3. On the other hand, if we lower the sample rate gradually, we shall get longer and lowpitched sounds.
wavplay(y,
wavplay(y,
speed
wavplay(y,
wavplay(y,

1.0*fs, 'sync');
0.9*fs, 'sync');

% Playback at the original speed


% Playback at 0.9 times the original

0.8*fs, 'sync');
0.6*fs, 'sync');

% Playback at 0.8 times the original


% Playback at 0.6 times the original

4. Record from microphone

fs=16000;
% Sampling rate
duration=2;
% Recording duration
fprintf('Press any key to start %g seconds of recording...', duration); pause
fprintf('Recording...');
y=wavrecord(duration*fs, fs); % duration*fs is the total number of sample points
fprintf('Finished recording.\n');
fprintf('Press any key to play the recording...'); pause;
fprintf('\n');
wavplay(y,fs);
5. Record from microphone and store as a file
fs=11025;
% Sampling rate
duration=2;
% Recording duration
waveFile='test.wav';
% Wav file to be saved
fprintf('Press any key to start %g seconds of recording...', duration);
pause
fprintf('Recording...');
y=wavrecord(duration*fs, fs);
fprintf('Finished recording.\n');
fprintf('Press any key to save the sound data to %s...', waveFile);
pause
nbits=8;

% Bit resolution wavwrite(y, fs, nbits, waveFile);


fprintf('Finished writing %s\n', waveFile);
fprintf('Press any key to play %s...\n', waveFile);
dos(['start ', waveFile]);
% Start the application for .wav file

You might also like