How to Find spectral Peaks from 2D array of Spectrogram? [closed]

I have computed a Spectrogram 2D array as :

How to develop a spectrogram (2D array) from audio signal?

Now, I want to find spectral peaks to find the respective temporal displacement. In python using STFT or spectrogram, I got the peaks as following : How do I find these peaks programmatically? I tried a way of finding maximum values per chuck and then finding max values in all the chunks. But I couldn't able to get the desired result. What are the ways of finding peaks in spectrogram?

• Just so you know, this question will most likely be closed as being off topic. STFT and spectrogram are words that belong in here but this is just finding maximum values in a matrix and you could try posting to Stack Overflow for more help or specific to Python help Apr 30 '20 at 11:58
• Peaks finding isn't as easy as it seems that finding max values from a 2D array and storing the indexes of respective time and frequencies. I have applied different ways to get the result still I am not successful in getting the desired results. I know if it was just finding max value in 2D array, I wouldn't even post it here rather googled it and tweaked the code or might have written myself. Apr 30 '20 at 12:02
• It doesn't matter if the problem is easy or hard, it needs to be on topic. What is the signal processing problem? Apr 30 '20 at 12:40
• What I want is that on each time index, there is a frequency bin and I want to find peaks in each bin. But I am looking critically at finding temporal displacement not just between each peak but some specific peaks as you can see in the data. Well, if its off topic then I won't ask here again.. and yeah its a SIGNAL PROCESSING PROBLEM with some programatic touch. Because I dont want that typical research paper equations here. I have researched and learnt that. Thanks btw.. cheers! May 2 '20 at 5:26
• Oh that is a different question though! You want to find where the peaks occur WITHIN a bin and not what bin do the peaks occur at? That is more than just keeping track of the maximum value at each row, typically people do a "coarse" search (finding the bin with max value) and then a "fine" search within that bin to get a more accurate picture of what frequency the peak is actually at May 2 '20 at 11:06

Maintain a 2D array/structure/hash table where you Maintain a time frequency pair. Let us take an example,

Let X(n,m) denote the spectrogram. Take N point FFTs and take M such FFT instances/time windows.

If you want both the spectral peak values an their location then simply modify the code as below, where Y is a 2D array ($$N\times 2$$) storing both the peak value and it's position.

For m= 0:M-1

For n=0:N-1
If X(n,m) >= Y(n,1)
Y(n,0) = m

Y(n,1)= X(n,m)
End

End

End

Initialize Y to be zero at start.

• I'd add that this approach would find a "peak" at every step, regardless if there is significant energy or not. It would find a peak if only noise was present Apr 30 '20 at 11:56
• @Engineer I didn't get what you are trying to mention here. This will keep a track of "at which window instance" a particular bin has its peak and what is the value of that corresponding peak. I interpret that to be the problem. He is simply interested in the peak values for each bin, whether they come from noise or signal, doesn't mention anything about it. He can later process this stored result as required, ex: thresholded it. Apr 30 '20 at 12:23
• Yes you're right. I think his picture shows clearly that there is not meaningful peak for every time step so you'd eventually have to make a decision Apr 30 '20 at 12:27