In [1]:
%pylab inline
import scipy
import scipy.signal
import scipy.fftpack
import numpy as np

Fs=962 # Sample rate, Hz

Populating the interactive namespace from numpy and matplotlib


In [2]:
f_data = file("baz")
f_data.close()

plot(data[0:1000])

Out[2]:
[<matplotlib.lines.Line2D at 0x1070979d0>]

In [3]:
y = data[200:1500]

# sample spacing
T = 1.0 / Fs
# Number of samplepoints
N = len(y)

w = scipy.signal.blackman(N)
ywf = scipy.fftpack.fft(y*w)

xf = np.linspace(0.0, 1.0/(2.0*T), N/2)

figure(figsize=(20,5))
subplot(1,2,1)
semilogy(xf[1:N/2], 2.0/N * np.abs(ywf[1:N/2]), '-r')
grid()

subplot(1,2,2)
plot(y)

None

In [4]:
y = data[15400:17500]

# sample spacing
T = 1.0 / Fs
# Number of samplepoints
N = len(y)

w = scipy.signal.blackman(N)
ywf = scipy.fftpack.fft(y*w)

xf = np.linspace(0.0, 1.0/(2.0*T), N/2)

figure(figsize=(20,5))
subplot(1,2,1)
semilogy(xf[1:N/2], 2.0/N * np.abs(ywf[1:N/2]), '-r')
grid()

subplot(1,2,2)
plot(y)

None

In [10]:
?np.linspace

In [20]:
dt = 1.0/ Fs
x = data

t = np.linspace(0,len(x)*dt, len(x), endpoint=False)

NFFT = 1024       # the length of the windowing segments

# Pxx is the segments x freqs array of instantaneous power, freqs is
# the frequency vector, bins are the centers of the time bins in which
# the power is computed, and im is the matplotlib.image.AxesImage
# instance

figure(figsize=(20,20))
ax1 = subplot(2,1,1)
plot(t, x)
subplot(2,1,2, sharex=ax1)
Pxx, freqs, bins, im = specgram(x, NFFT=NFFT, Fs=Fs, noverlap=900,
cmap=cm.binary)
show()

In [15]:
plot(t)

Out[15]:
[<matplotlib.lines.Line2D at 0x1083e0a50>]

In []: