0

I've been using psd() to compute power spectral density over a .wav file. I've shown it to my supervisor and he doesn't want it averaged to compute the Pxx:

The |FFT(i)|^2 of each segment are averaged to compute Pxx

He suggested I use PSD but overlap it manually a frame at a time instead of passing in the whole array of data. I've attempted it and it looks like this:

def spec_draw(imag_array):
    overlap_step = len(imag_array) / 128
    temp = []
    values = []
    for x in range(0, len(imag_array), overlap_step-overlap_step/2):
        try:
            for i in range(0, overlap_step):
                temp.append(imag_array[x+i])
        except:
            pass
        values.append(psd(temp, sides='onesided'))
        temp = []


    print values

Where imag_array is an array of data from a wave file. I've sent it to him and he doesn't understand Python very well and since he can't run it, he can't debug it. Does this look correct?

smci
  • 32,567
  • 20
  • 113
  • 146
Nanor
  • 2,400
  • 6
  • 35
  • 66
  • Is this Python 3.x or 2.x? If 2.x, `overlap_step = len(imag_array) / 128` would be integer division, so is it guaranteed that len(imag_array) is a multiple of 128? – smci Mar 20 '15 at 14:58
  • 1
    The naked `try... except: pass` which catches all exceptions is generally considered to be very bad style as it will suppress unexpected exceptions too. Is it there to catch `IndexError, ArithmeticError, MemoryError...?` Use a named list of exception-types instead. – smci Mar 20 '15 at 15:02

0 Answers0