freqdemod-quickstart-4

Author information

John A. Marohn (jam99@cornell.edu)
Department of Chemistry and Chemical Biology
Cornell University
Ithaca, NY USA; 14853-1301

Date

2014/07/03 -- 2014/07/05

Abstract

Here we demonstrate some of the plotting features of freqdemod package.

Preliminaries

Set the working directory to be one directory up from the directory where this file is stored; load the module.


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

Analyze experimental data

The following code is drawn from freqdemod-quickstart-3. Begin by reading in the data.


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)


Signal
======
signal name: x
signal unit: nm
signal lenth = 524288
time step = 0.870 us
rms = 0.1486
max = 0.1885
min = -0.2339
 
Signal Report
=============
* Add a signal x[nm] of length 762375, time step 0.870 us, and duration 0.663 s

* Truncate the signal to be 524288 points long, a power of two. This was done by chopping points off the beginning and end of the signal array, that is, by using points 119043 up to 643331.

* Window the signal with a rising/falling blackman filter having a rise/fall time of 1000.000 us (1150 points).

* Fourier transform the windowed signal. It took 233.2 ms to compute the FFT.

* Reject negative frequencies; apply a bandpass filter (center frequency 60626.984 Hz, bandwidth 1000.0 Hz,  & order 50); and set the delay time to 1250.0 us. Make an improved estimate of the center frequency: 60632.456 Hz.

* Apply an inverse Fourier transform.

* Remove the leading and trailing ripple (1437 points) from the complex signal. Compute the signal phase and amplitude.

* Curve fit the phase data. The target chunk duration is 500.000 us; the actual chunk duration is 500.000 us (575 points). 906 chunks will be curve fit; 453.000 ms of data. It took 27.0 ms to perform the curve fit and obtain the frequency.

In [9]: