信号数据shannon entropy计算

news/2024/5/19 17:36:52 标签: python, eeg, 香农熵, 信号处理, 脑机接口
python">import math
import numpy as np
def shannon_entropy(single,k):
    '''
        single:1-D信号
        k: 分多少个bin
    '''
    numofx = single.shape[0]
    maxV = np.max(single)
    minV = np.min(single)
    bin = np.linspace(minV,maxV,k+1)

    bin_numx = [0]*k    # 落在每个bin的数据点数目

    for x in single:    # 计算落在每个bin的数据点数目
        for i in range(k):   # 看落在哪个bin
            if x <= bin[i]:
                bin_numx[i-1] += 1
    
    shannon_ent = 0

    for i in bin_numx:
        shannon_ent -= (i/numofx) * math.log((i/numofx),2)
    
    return shannon_ent

a = np.array([1,2,3,4,54,6,7,8,99])
b = shannon_entropy(a,2)

print(b)


http://www.niftyadmin.cn/n/770327.html

相关文章

信号数据C0 Complexity计算

参考论文&#xff1a;The study of c0 complexity on epileptic absence seizure def C0_complexity(single):计算C0复杂度 x fft(single)N x.shape[0]avgx np.average(x) # 计算幅度谱的平均值new_x []for i in x:if abs(i) > avgx:new_x.append(i)else:new_x.appe…

多条eeg数据对比图绘制

画图&#xff0c;输入多条数据&#xff0c;进行可视化对比。建议10以内。import plotly.graph_objs as go import numpy as np from plotly.subplots import make_subplots def plot_various_chns(data,names []):画图&#xff0c;输入多条数据&#xff0c;进行可视化对比。建…

mne计算CSP

# get CSP feature from mne.decoding import CSP csp CSP(n_components10, regNone, logTrue, norm_traceTrue) csp_train csp.fit_transform(train_data, train_label) 其中 train_data 的格式为[trial,channel,time]&#xff1b;train_label的为[trial,] 详情可以参考mne…

pip 配置下载源

pip官方镜像源 官方&#xff1a; https://pypi.python.org/simple 国内镜像源 清华&#xff1a;https://pypi.tuna.tsinghua.edu.cn/simple 阿里云&#xff1a;http://mirrors.aliyun.com/pypi/simple/ 中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/ 华中理工大…

Nan 数据的检测与处理

print(is exist nan: , end) print(np.isnan(x).any())# 查找位置 nan_inx np.where(np.isnan(x)) print(nan_inx)# 替换 x[np.isnan(x)]0.00001print(is exist nan: , end) print(np.isnan(x).any())

EEG数据预处理的一些坑,模型loss=nan的原因与解决方法

在使用深度学习模型对数据进行分类时&#xff0c;出现lossnan的现象。 原因&#xff1a;数据中有接近0的坏数据或者Nan 例如&#xff1a; 解决方法&#xff1a;去掉就好 nan的检测与去除可以参考此处。

CSP学习资料与精简总结

其实是一种降维方法&#xff0c;将原始数据投影到CSP空间中&#xff0c;在该投影方向上&#xff0c;一类信号的方差被 极大化&#xff0c;一类极小化。 学习资料&#xff1a; 运动想象中共空间模式算法&#xff08;CSP&#xff09;的实现_zhoudapeng01的专栏-CSDN博客_csp算法…

论文笔记: Deep Learning With Convolutional Neural Networks for EEG Decoding and Visualization

Deep Learning With Convolutional Neural Networks for EEG Decoding and Visualization 概述 此笔记主要对模型部分进行描述。 因为CNN可以端到端地解决问题&#xff0c;因此考虑将其用到EEG的处理中&#xff0c;因为EEG信号与图片信号有所不同&#xff0c;因此直接使用原…