Menu

[r134]: / trunk / htdocs / examples / specgram_demo.py  Maximize  Restore  History

Download this file

47 lines (30 with data), 1.1 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from __future__ import division
import os, sys
from matplotlib.matlab import specgram, show, meshgrid, pcolor, set, gca
from matplotlib.backends.backend_gtk import show_xvfb
from Numeric import fromstring, arange, Int16, Float, log10
filename = '/cruncher1/data/Seizure/Patients/2104212/eegs/ictal_2000_06_19.eeg'
channels = 128
Fs = 400
def read_nicolet(tmin, tmax):
"""Load Nicolet BMSI data."""
if tmin<0: tmin=0
fh = file(filename, 'rb')
indmin = Fs*tmin
numsamples = os.path.getsize(filename)/(channels*2)
indmax = min(numsamples, Fs*tmax)
byte0 = int(indmin*channels*2)
numbytes = int( (indmax-indmin)*channels*2 )
fh.seek(byte0)
data = fromstring(fh.read(numbytes), Int16).astype(Float)
data.shape = -1, channels
t = (1/Fs)*arange(indmin, indmax)
return t, data
t, data = read_nicolet(0,10)
x = data[:,5]
Pxx, freqs, t = specgram(x, NFFT=512, Fs=Fs, noverlap=412)
T, F = meshgrid(t,freqs)
pcolor(T, F, 10*log10(Pxx), shading='flat')
set(gca(), 'ylim', [0,100])
#print Pxx.shape, freqs.shape, t.shape
show()
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.