I am trying to understand the frequency bins returned by the matplotlib.mlab.psd()
function.
Using the following code I can inspect the frequencies which are returned and I'm not convinced they are correct.
import matplotlib.mlab as ml
import numpy as np
sampf=500.
nfft=2**4
testdat=np.random.randn(10000,)
p2,f2=ml.psd(testdat, nfft,sampf,sides='twosided')
p1,f1=ml.psd(testdat, nfft,sampf,sides='onesided')
print testdat.shape
print "Twosided"
print "\tbin1 : {:f} ".format(f2[0])
print "\tbin2 : {:f} ".format(f2[1])
print "\tbinlast : {:f} ".format(f2[-1])
print "onesided"
print "\tbin1 : {:f} ".format(f1[0])
print "\tbin2 : {:f} ".format(f1[1])
print "\tbinlast : {:f} ".format(f1[-1])
print "recreate"
f3=np.arange(nfft)*(sampf/2.)/nfft
print "\tbin1 : {:f} ".format(f3[0])
print "\tbin2 : {:f} ".format(f3[1])
print "\tbinlast : {:f} ".format(f3[-1])
which gives this output:
Twosided
bin1 : -250.000000
bin2 : -218.750000
binlast : 218.750000
onesided
bin1 : 0.000000
bin2 : 31.250000
binlast : 250.000000
recreate
bin1 : 0.000000
bin2 : 15.625000
binlast : 234.375000
Am I right in thinking that the maximum frequency (binlast) for the 2 sided case should be half the sampling frequency?
Following this SO post I think it should range to sampf/2.