【BrainFlow】FFT

import argparse
import time
import brainflow
import numpy as np

from brainflow.board_shim import BoardShim, BrainFlowInputParams, LogLevels, BoardIds
from brainflow.data_filter import DataFilter, FilterTypes, AggOperations


def main ():
    BoardShim.enable_dev_board_logger ()

    # use synthetic board for demo
    params = BrainFlowInputParams ()
    board_id = BoardIds.SYNTHETIC_BOARD.value
    board = BoardShim (board_id, params)
    board.prepare_session ()
    #num_samples=.... 自己设置
    board.start_stream ()
    BoardShim.log_message (LogLevels.LEVEL_INFO.value, 'start sleeping in the main thread')
    time.sleep (10)
    #
    data = board.get_board_data ()
    board.stop_stream ()
    board.release_session ()
    #sample_rate 采样率 256
    sample_rate=BoardShim.get_sampling_rate(board_id)
    eeg_channels = BoardShim.get_eeg_channels (board_id)
    # demo for transforms
    num=1
    for count, channel in enumerate (eeg_channels):
        #print ('Original data for channel %d:' % channel)

        #采样点128
        fft_data = DataFilter.perform_fft (data[channel][:128])
        #print("fft_data.shape:"+str(fft_data.shape))#65   
        # len of fft_data is N / 2 + 1=65
        '''
            #为什么经过fft之后是N/2+1?
            因为N个样点的信号经过fft以后变成N个样点的频谱,
            这个频谱是关于第N/2+1样点左右对称的,所以真正有用的频谱数据只有前面一半,后面一半是镜像。
            所以取N/2+1
        '''

        #print ('Restored data after fft for channel %d:' % channel)
        n=1

        for each_data in fft_data:
            Fn = (n - 1) * sample_rate/128
            print(Fn)#输出频率
            n += 1

        #然后对每一个fft_data的采样点处理




if __name__ == "__main__":
    main ()
posted @ 2020-04-03 14:37  ICY2INVINCIBLE  阅读(263)  评论(0编辑  收藏  举报
Live2D