0

Introduction

I am trying to find peaks in amplitude within a spectrogram I have produced that plots frequency against time and amplitude as the third axis.

I have looked through and attempted to code a solution using scipy.signal.find_peaks_cwt however the official reference guide did not explain what was meant by the widths parameter.

Question:

When finding peaks using scipy.signal.find_peaks_cwt will it return the frequency-time coordinates? If not is there another library or method to use to return the coordinates of local maxima?

What is the widths parameter within scipy.signal.find_peaks_cwt?

As the scipy.signal.find_peaks_cwt deals with arrays why do you still need to plot a spectrogram in order to find local maxima?

Here is the code i have been using to create the spectrogram:

 import numpy as np import matplotlib.pyplot as plt import scipy.io.wavfile from scipy import signal def create_spectrogram(audio): rate, data = scipy.io.wavfile.read(audio) data_1D = data.flatten() plt.specgram(data_1D, NFFT = 64, Fs = 64, noverlap=32) plt.savefig("melody") plt.show() if __name__ == '__main__': audio = "melody.WAV" create_spectrogram(audio) 

Here is the outputted Spectrogram:

Here is the outputted Spectrogram:

Links: scipy.signal.find_peaks_cwt reference guide: https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.signal.find_peaks_cwt.html

2
  • Please read how to create a minimal reproducible example and add the missing information to your Post by editing it :) If you haven't read How to Ask yet i recommend to do so :) I highly recommend to follow the 2 guides i linked as the people on SO are more likely to answer questions when the posts follow these guides. What i'm missing in particular is - What have u tried so far? What errors/problems do you face? Do you may have codesnippets that show what you tried so far? Commented Jan 6, 2018 at 17:53
  • find_peaks_cwt is for 1-D array. If you want to find local peaks in your 2-D spectrogram, please read this: stackoverflow.com/questions/3684484/… Commented Jan 6, 2018 at 22:34

1 Answer 1

0

Could you please give a bit more information as to how exactly is your data stored in your code? Is it a numpy array, a scipy.signal.spectrogram or simple python lists? A snippet of code would help a lot in trying to help you find a good solution.

For the moment the only "easy" way I would suggest is to have a look at numpy.amax(), choosing wisely the value given to the axis parameter, should get you the maximum you are looking for.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.