python - Differentiate between local max as part of peak and absolute max of peak -
i have taken amplitude data 10-second clip of mp3. performed fast-fourier-transform on data clip in frequency domain (shown in first figure). determine frequencies peaks located at.
i started smoothing data, can seen below in blue , red plots. created threshold peaks must on in order considered. horizontal blue line on third plot below. can seen, peak detection code worked, extent.
the problem having evident in final plot shown below. code finding maxima local maxima part of overall peak. need way filter out these local maxima each peak, getting single marker. i.e. peak shown below want marker @ absolute peak, not @ each minor peak along way.
my peak detection code shown below:
for i, item in enumerate(xavg): #xavg contains smoothed data points if xavg[i] > threshold: #points must above threshold #if not first or last point (so index isn't out of range) if (i > 0) , (i < (len(xavg)-1)): #greater points on either side if (xavg[i] > xavg[i-1]) , (xavg[i] > xavg[i+1]): max_locations.append(i)
edit: think didn't state problem enough. want find locations of 5 or highest spikes on plot, not highest point overall. trying give clip audio fingerprint marking dominant frequencies.
edit2: more code show i'm doing regards fft , smoothing:
def movingaverage(interval, window_size): window = np.ones(int(window_size))/float(window_size) return np.convolve(interval, window, 'same') fft = np.fft.rfft(song) xavg = movingaverage(abs(fft), 21)
peak finding pretty tricky, avoid trying implement own code if possible. try using scipy.signal.find_peaks_cwt, there few parameters can play around with. function think don't need smooth data before hand, since 1 of parameters list of lengths on smooth data. speaking algorithm smooths data on 1 length scale, looks peaks, smooths on length scale, looks peaks, etc.. looks peaks appear @ or length scales.
Comments
Post a Comment