Pergunta

I am a little new to this (and programming). I am trying to write a script that will help me analyze a large .wav file. It will, in theory, run a fft on time segments, output data corresponding to power v. frequency, perform a peak power search on a range of frequencies and append that to another new array which I will use to build a histogram later.

The step I am stuck on is selecting a frequency range and having the screen print the maximum power for that frequency range (my attempts are after the plt.show() ) I want to be able to return a peak power for the range of frequencies 260-270Hz... any suggestions (I have made adjustments in that main block to return dbm v Hz already)?

for i in range(reads-1):
    if i > 0:
        break
    print 'working on set {:d} \n'.format(i) 
    waveData = wavFile.readframes(int(Windowsize))
    waveDataunpack = struct.unpack(formatstring,waveData)
    fftData = ((np.fft.rfft(waveDataunpack)/Windowsize))
    freqs = np.fft.fftfreq(Windowsize+1, float(1.0/rate))
    plt.plot(freqs[:16385],10*np.log10(np.abs(fftData)))
    plt.ylabel('power (dBm)')
    plt.xlabel('frequency (Hz)')
    plt.ylim((0,50))
    plt.xlim((0,500)) 
    #plt.show()

    pointy = fftData[freqs.index(260)]
    #print pointy
    #print(fftData.max)
    #print max(10*np.log10(np.abs(fftData)));
Foi útil?

Solução

I found the answer to my range problem with enumeration.

ind = [i for i, x in enumerate(windowed_freqs) if x >= 240 and x <= 285]

#now take the DB data only at the indicies where x is between the proper range.
value = fftData_inDB[ind]

#print freqs[ind]
maxval=-1000
maxind=0
for j in ind:
    if fftData_inDB[j] > maxval:
        maxval = fftData_inDB[j]
        maxind = j
print 'max power in range is {} dBm'.format(maxval)
print 'corresponding frequency is {} Hz'.format(freqs[maxind])
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top