freqdemod-quickstart-5

Author information

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

Date

2014/07/23 -- 2014/07/26

Abstract

Read in data from a wav file an analyze it.

Preliminaries

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:

find . -name '*.pyc' -delete
python setup.py develop

We should now be able to import parts of the package in the usual way using an import statement


In [1]:
from freqdemod.demodulate 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 [7]:
%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

Load audio signal and plot it


In [8]:
import matplotlib.pyplot as plt
import numpy as np
import wave
import sys

spf = wave.open('output.wav','r')

# Extract Raw Audio from Wav File

signal = spf.readframes(-1)
signal = np.fromstring(signal, 'Int16')
fs = spf.getframerate()

t = np.linspace(0, len(signal)/fs, num=len(signal))

plt.figure(facecolor='w')
plt.title('Signal Wave...')
plt.plot(t,signal)
plt.ylabel('amplitude [a.u.]')
plt.xlabel('time [s]')
plt.show()



In [9]:
1.0/fs


Out[9]:
2.2675736961451248e-05

Process the amplitude versus time data


In [10]:
S = Signal(signal,"V","a.u.",1.0/fs)
S.binarate("end")
S.window(tw=10.0E-3)
S.fft()
S.filter(bw=0.1E3)
S.ifft()
S.trim()
S.fit(dt_chunk_target=0.50E-3)


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-10-de71d6130ecc> in <module>()
----> 1 S = Signal(signal,"V","a.u.",1.0/fs)
      2 S.binarate("end")
      3 S.window(tw=10.0E-3)
      4 S.fft()
      5 S.filter(bw=0.1E3)

TypeError: __init__() takes at most 2 arguments (5 given)

Plot the results


In [8]:
S.plot_signal()
S.plot_fft(autozoom="no")
S.plot_fft(autozoom="yes")
S.plot_phase()
S.plot_phase_fit()



In [ ]: