Converting matlab code to python

后端 未结 1 1541
迷失自我
迷失自我 2020-12-20 23:31

Okay so I have a datafile from an EEG scan (a binary file, data.eeg), and in matlab the code to read the file and plot a section of the data goes like this:



        
相关标签:
1条回答
  • 2020-12-20 23:40

    As discussed in the comments by yourself and @JoeKington, this should work (I removed the input stuff for testing)

    import numpy as np
    
    sample_rate = 400
    Nyquist = sample_rate/2.0
    fneeg = 'data.eeg'
    t = 10 
    ch = 32
    le = t*sample_rate
    EEG = np.fromfile(fneeg, 'int16').reshape(ch, le, order='F')
    

    Without the reshape, you get:

    In [45]: EEG
    Out[45]: array([ -39,  -25,  -22, ..., -168, -586,  -46], dtype=int16)
    
    In [46]: EEG.shape
    Out[46]: (128000,)
    

    With reshaping:

    In [47]: EEG.reshape(ch, le, order='F')
    Out[47]: 
    array([[ -39,  -37,  -12, ...,    5,   19,   21],
           [ -25,  -20,    7, ...,   20,   36,   36],
           [ -22,  -20,    0, ...,   18,   34,   36],
           ..., 
           [ 104,  164,   44, ...,   60,  -67, -168],
           [ 531,  582,   88, ...,   29, -420, -586],
           [ -60,  -63,  -92, ...,  -17,  -44,  -46]], dtype=int16)
    
    In [48]: EEG.reshape(ch, le, order='F').shape
    Out[48]: (32, 4000)
    
    0 讨论(0)
提交回复
热议问题