In [1]:
import os, sys
module_path = os.path.abspath(os.path.join(os.getcwd(), '..'))
sys.path.append(module_path)
from freqdemod import Signal
Run the "magic" that tells ipython to put the plots inline and not in a pop-up window.
In [2]:
%matplotlib inline
Import useful packages and set the figure-plotting defaults
In [3]:
import numpy as np
import matplotlib.pylab as plt
font = {'family' : 'serif',
'weight' : 'normal',
'size' : 20}
plt.rc('font', **font)
plt.rcParams['figure.figsize'] = 8, 6
In [4]:
import h5py
with h5py.File('JAM_9p90__copy.h5', 'r') as h5f:
s = h5f['s'][:]
S = Signal(s,"x","nm",1/1.15E6)
Chop the data so it is a factor of two in length. Apply a windowing function so that the signal begins and ends at zero. Plot the signal vs time, automatically zooming in to early, middle, and late times.
In [5]:
S.binarate("middle")
S.window(tw=1.0E-3)
S.plot_signal()
FFT the windowed signal and apply the right-hand and band-pass filtes. The plotting option autozoom
controls whether all positive frequencies are plotted, or just frequencies centered on the band-pass filter.
In [6]:
S.fft()
S.filter(bw=1.0E3)
S.plot_fft(autozoom="no")
S.plot_fft(autozoom="yes")
Inverse FFT the filtered and FT-ed data, creating arrays of the phase and amplitude. Trim the resulting arrays to remove filter ripple. Plot the phase vs time. The plotting option delta="yes"
fits the phase data to a line and plots the difference between the measured phase and the best-fit line.
In [7]:
S.ifft()
S.trim()
S.plot_phase()
S.plot_phase(delta="yes")
Fit the phase data vs time data. The plotting option delta="yes"
presents the frequency data as a shift relative to the resonance frequency determined by the .filter
function. The plotting option baseline=0.1
uses instead the first 0.1 seconds of data as the reference for computing the frequency shift.
In [8]:
S.fit(dt_chunk_target=0.50E-3)
S.plot_phase_fit()
S.plot_phase_fit(delta="yes")
S.plot_phase_fit(delta="yes",baseline=0.1)
Finally, print out a report describing the data and how we analyzed it
In [9]:
print(S)
In [9]: