I have 2 graphs on one figure.
Graph one - subplot(2,1,1) velocities vs ( Time or SampleIndex) depending in input args
Graph two - subplot(2,1,2) psd() - power spectrum to help us find the resonances in velocities
As system goes through a number of different states, the resonances change during the cycle, so I need to zoomIn GraphOne to an area of interest, then re-calc the power spectrum on that portion of data only.
I have something that works in the xaxis=SampleIndex scenario, but fails in the xaxis=Time scenario, I am wondering if I am going about it the right way.
The following page has 4 graphs that show what I have working now (2 graphs of velocity vs SampleNo), and the failing case (2 graphs of Velocity Vs Time)
I'll describe what I got.
I connected my function RecalcPowerSpectrum to ReleaseButton event
pylab.connect( 'button_release_event', RecalcPowerSpectrum)
It's ugly and crude, but if GraphOne is a velocity vs sampleIndex, the following works.
My issues start when you look at how I am slicing (if thats the right word) the array I pass into psd() and where those values come from.
def RecalcPowerSpectrum( event ): global myAxis
xlim = myAxis.get_xlim()
xstart = int(xlim)
xend = int(xlim)
if xstart != lastXstart or xend != lastXend:
print '%s event detected, re-calc power spectrum' % event.name
lastXstart, lastXend = xstart, xend
lastXlimits = xlim
print 'xlim1 =', xstart
print 'xlim2 =', xend pylab.cla()
if secondGraph == 'fft':# (plot UDR1 points)
Fs = 2 * targetvel
fftdata = pylab.psd(vel[2*xstart:2*xend], NFFT=winsize, Fs=Fs, detrend=pylab.mlab.detrend_linear, window=pylab.mlab.window_hanning, noverlap=overlap)
else: #must be a fft2 (plot UDR2 points)
Fs = targetvel
fftdata = pylab.psd(combined[xstart:xend], NFFT=winsize, Fs=Fs, detrend=pylab.mlab.detrend_linear, window=pylab.mlab.window_hanning, noverlap=overlap)
This fails when I run my program to plot with xaxis in time as the values returned by get_xlim() are small (0.46408074411240841, 0.53334652681575301), once I int() these values they are both 0
Clearly I am trying to work with the wrong values. I actually want to get the indexes of these values. So I can pass the proper slice of the original array into the psd function.
So my questions.
1) Is there a way to get the indexes (not the values) of the portion of the line actually showing on screen
2) Is there a way to get a copy of the portion of the data displayed on screen (in a new array) ?
3) Is there a better way of linking psd so it performs the spectrum analysis only on the portion of data on screen?
*Thanks for your help