MATLAB: How to extract information from sound files

soundswav

I have a .wav file. When listening to this file, I can hear a tone then a beep then a tone and this repeats over 1000 times (tone1 – beep1 – tone2 -beep2…..) I want to get separate these. So I want to create separate .wav files for each tone-beep pair such that file1= tone1-beep1, file2 = tone2-beep2 etc. I have no idea where to even begin. Any help will be greatly appreciated

Best Answer

If the beep-tone pairs always take the same number of elements, can't you just use reshape() to put each stretch into its own row of a 2D matrix?
% Open standard demo sound that ships with MATLAB.
[theSound, freq] = audioread('guitartune.wav');
numberOfElements = length(theSound);
shortLength = numberOfElements/5;
fprintf('The sound has %d elements.\n', length(theSound));
promptMessage = sprintf('Do you want to play the original sound?');
titleBarCaption = 'Continue?';
button = questdlg(promptMessage, titleBarCaption, 'Yes', 'No', 'Yes');
if strcmpi(button, 'Yes')
% Play the original sound of 661,500 elements.
soundsc(theSound, freq);
end
promptMessage = sprintf('Do you want to play the short sound?');
titleBarCaption = 'Continue?';
button = questdlg(promptMessage, titleBarCaption, 'Yes', 'No', 'Yes');
if strcmpi(button, 'No')
return;
end
% Reshape into 5 rows of 132,300 elements.
soundSegments2D = reshape(theSound, [5, shortLength]);
% Play the sound from row #1
soundsc(soundSegments2D(1, :), freq/5);