So we can import the package in the usual way, use setup.py
development mode. Here we are following directions here. In the base directory, run:
python setup.py develop
We should now be able to import parts of the package in the usual way using an import statement
In [42]:
from freqdemod import Signal
Execute the the first line below if you want the plots to show inline. If instead you want each plot to display in a separate pop-up window, then don't execute the first line. Set up plotting defaults so the plots will look nice inline:
In [43]:
%matplotlib inline
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 [44]:
fd = 50.0e3 # digitization frequency
f0 = 2.00e3 # signal frequency
nt = 60e3 # number of signal points
sn = 1.0 # signal zero-to-peak amplitude
sn_rms = 0.01 # noise rms amplitude
dt = 1 / fd
t = dt * np.arange(nt)
signal = sn * np.sin(2*np.pi*f0*t) + np.random.normal(0, sn_rms, t.size)
Plot the test signal
In [45]:
plt.plot(1E3*t[0:100], signal[0:100])
plt.xlabel('time [ms]')
plt.ylabel('amplitude [nm]')
plt.show()
In [46]:
s = Signal() # Create a signal
s.load_nparray(signal,"x","nm",dt) # Load the data into the file
In [47]:
s.time_mask_binarate("middle") # Pull out the middle section
s.time_window_cyclicize(3E-3) # Force the data to start and end at zero
s.fft() # Fourier transform the data
s.freq_filter_Hilbert_complex() # Take the complex Hilbert transform
s.freq_filter_bp(1.00) # Apply a 1 kHz wide bandpass filter
s.time_mask_rippleless(15E-3) # Set up a filter to remove ripple
s.ifft() # Inverse Fourier transform the data
s.fit_phase(221.34E-6) # Fit the phase vs time data
In [48]:
latex = False
Begin by re-plotting the data
In [49]:
s.plot('y', LaTeX=latex)
Plot the intermediate results
In [50]:
s.plot('workup/time/mask/binarate', LaTeX=latex)
In [51]:
s.plot('workup/time/window/cyclicize', LaTeX=latex)
In [52]:
s.plot('workup/freq/FT', LaTeX=latex, component='abs')
In [53]:
s.plot('workup/freq/filter/Hc', LaTeX=latex)
In [54]:
s.plot('workup/freq/filter/bp', LaTeX=latex)
In [55]:
s.plot('workup/time/mask/rippleless', LaTeX=latex)
In [56]:
print(s)
In [57]:
s.plot('workup/time/z', LaTeX=latex, component='both')
In [58]:
s.plot('workup/time/a', LaTeX=latex)
In [59]:
s.plot('workup/time/p', LaTeX=latex)
In [60]:
s.plot('workup/fit/y', LaTeX=latex)
In [61]:
s.list()
In [62]:
s.close()