Analyzing a Power Spectrum of an Audio File for Patterns

42 Views Asked by At

I am currently trying measure whether or not a .wav file has a clicking noise or not. I'll attach my code below, but so far what I do is plot the power spectrum, and then I try to index into the Power (dB) matrix with indices from the time and frequency, but I keep getting an index out of bound error, and also not sure that my approach is the most efficient.

I was just thinking from looking at the plot of the clicky noise, I could see a drastic change in dB levels over a short amount of time, where I wouldn't see that with the quiet one. So, I thought I could detect these changes to see if it is clicky. Any help is appreciated, thanks!

A clicky noise file has a spectrum that looks like this:

clicky audio

A smooth noise file has a spectrum that looks like this:

enter image description here

I am trying to iterate through the dB matrix like this:

clicky = audioread('Quiet_servo60.wav'); %normalized

[S, F, T] = spectrogram(clicky(:,1),1000,500,1000,48000); %channel 1 spectrogram
S_dB = mag2db(abs(S));

figure;
imagesc(T, F, S_dB);
axis xy;
title('Spectrogram in dB');
xlabel('Time (s)');
ylabel('Frequency (Hz)');
colorbar;

diff = 15;
delta = 5;
count = 0;


for j = F
    freq = find(F==j);
    for i = T[0,length(T)-10]
        time = find(T==i);
        num = S_dB(time,freq);
        num_change = S_dB(time+delta, freq);
        if( abs(num-num_change) > diff)
            count = count + 1;
        end
    end
    count = 0;
end
            
0

There are 0 best solutions below