Extract the timing of a specific sound (beep) from an Audio File
20 views (last 30 days)
Show older comments
Hi all,
I am very new to working with audio files using matlab.
I have an audio file (recording of a sports game) and it not only contains sounds of the game, but also contains mutiple 'Beep' sounds layered over the game sounds. The beep sound has an frequency of 300Hz.
What I need to do is to find the exact timing (onset and offset) of the beep sounds.
Is there a way to extract the timing of a specific sound (beep) from an .mp4 file?
Any help would be greatly appreciated.
Thank you in advance.
0 Comments
Answers (1)
Star Strider
on 12 Oct 2023
It would help to have the file.
I assume that the background sounds also contain 300 Hz elements, so unless there is something unique about the beep sounds (amplitude, for example) it might be difficult to extract them specifically.
I would first use pspectrum with the 'spectrogram' option (I prefer it to the spectrogram function because pspectrum produces the power spectrum and spectrogram produces the power spectral density) to see how easy it is to detect the beeps visually. One option is then to use that option and then determine the beginning and end of the beeps from that output (use all three of them to estimate the times of that specific frequency).
The other option is to create a narrow 300 Hz (perhaps 290 Hz to 310 Hz) bandpass filter (for best results, use the 'ImpulseResponse','iir' name-value pair) and then search the filtered output for a signal with a specific amplitude that matches the amplitude of the beep. Use the associated time vector to get the necessary times.
Depending on the chartacteristics of the recording, this could either be straightforward or impossible.
2 Comments
Hee Dong Yoon
on 12 Oct 2023
Thank you for the reply.
I will look into the details you have provided.
Meanwhile, it would be great if you can take a look into my file. I attached the audio file as you requested.
There are two 'beep' sounds in the file, each starting around 8 and 24 seconds.
I want to extract the onset, offset and duration of the 'beep' sounds.
Thank you again very much.
Star Strider
on 12 Oct 2023
My pleasure!
I get the impression that this is a homework assignment. If it is not, I will post the full solution, however for the time being I will leave it as it is here, suggesting that using the ischange function works to provide the correct time indices of the edge times, and from them you can derive everything else.
This is my initial analysis —
Uz = unzip('08.zip');
[y,Fs] = audioread(Uz{1});
L = size(y,1);
tv = linspace(0, L-1, L).'/Fs;
figure
plot(tv, y)
grid
figure
pspectrum(y(:,1), Fs, 'spectrogram')
colormap(turbo)
figure
pspectrum(y(:,2), Fs, 'spectrogram')
colormap(turbo)
[p,f,t] = pspectrum(y(:,1), Fs, 'spectrogram');
figure
surfc(t,f,p, 'EdgeColor','none')
colormap(turbo)
colorbar
xlabel('Time (s)')
ylabel('Frequency (Hz)')
zlabel('Magnitude')
ylim([200 400])
y_filt300 = bandpass(y, [295 305], Fs, 'ImpulseResponse','iir');
[eh,el] = envelope(y_filt300(:,1), 1E+4, 'peaks');
figure
plot(tv, y_filt300)
hold on
plot(tv, [eh,el], '-g', 'LineWidth',2)
hold off
grid
I leave the rest to you (three lines of code to get the logical indices, time values at those indices, and the duration of each beep).
.
See Also
Categories
Find more on Audio I/O and Waveform Generation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



