BCI系统的ITR(信息传输率)函数python+matlab代码

最近在做降低实验复杂度的问题,分析一下需要用的ITR代码,包含Matlab和python代码。

1.引入ITR

        由于BCI在输入、转换算法、输出和其他特征方面存在很大差异,因此通常很难进行比较。虽然不同的系统可能会被证明对不同的应用程序最有价值,但一个标准的性能度量将作为跟踪BCI开发的通用基准而有用。通信系统的一个标准度量是比特率,即单位时间内通信的信息量,比特率取决于速度和精度。虽然每个BCI系统的有效性在很大程度上取决于它所应用的应用程序,但比特率为比较不同系统和测量系统内部的改进提供了客观的衡量标准。

2.ITR公式,单位bits/min

 其中:

●其中,T表示平均判断时长,M表示类别个数,P表示识别正确率。ITR的单位是bits/min。

●特别需要指出,当正确率P小于1/N时,ITR强制为0。

变量关系如下:

 3.ITR函数代码

 3.1 matlab代码

源码出处:GitHub - mnakanishi/TRCA-SSVEP: Task-related component analysis (TRCA)-based algorithm for detecting steady-state visual evoked potentials (SSVEPs) toward a high-speed brain-computer interface (BCI).Task-related component analysis (TRCA)-based algorithm for detecting steady-state visual evoked potentials (SSVEPs) toward a high-speed brain-computer interface (BCI). - GitHub - mnakanishi/TRCA-SSVEP: Task-related component analysis (TRCA)-based algorithm for detecting steady-state visual evoked potentials (SSVEPs) toward a high-speed brain-computer interface (BCI).https://github.com/mnakanishi/TRCA-SSVEP

function [ itr ] = itr(n, p, t)
% Calculate information transfer rate (ITR) for brain-computer interface 
% (BCI) [2]
% function [ itr ] = itr(n, p, t)
% 
% Input:
%   n   : # of targets
%   p   : Target identification accuracy (0 <= p <= 1) 
%   t   : Averaged time for a selection [s]
%
% Output:
%   itr : Information transfer rate [bits/min] 
%
% Reference:
%   [1] M. Cheng, X. Gao, S. Gao, and D. Xu,
%       "Design and Implementation of a Brain-Computer Interface With High 
%        Transfer Rates",
%       IEEE Trans. Biomed. Eng. 49, 1181-1186, 2002.
% 
% Masaki Nakanishi, 22-Dec-2017
% Swartz Center for Computational Neuroscience, Institute for Neural
% Computation, University of California San Diego
% E-mail: masaki@sccn.ucsd.edu

if nargin < 3
    error('stats:itr:LackOfInput', 'Not enough input arguments.'); end

if p < 0 || 1 < p
    error('stats:itr:BadInputValue',...
        'Accuracy need to be between 0 and 1.');
elseif p < 1/n
    warning('stats:itr:BadInputValue',...
        'The ITR might be incorrect because the accuracy < chance level.');
    itr = 0;
elseif p == 1
    itr = log2(n)*60/t;
else
    itr = (log2(n) + p*log2(p) + (1-p)*log2((1-p)/(n-1)))*60/t;
end

3.2 python代码

import math

def itr(n, p, t):
    if not all(isinstance(i, (int, float)) for i in [n, p, t]):
        raise TypeError("Inputs must be numeric.")
    if p < 0 or p > 1:
        raise ValueError("Accuracy needs to be between 0 and 1.")
    elif p < 1/n:
        print("Warning: The ITR might be incorrect because the accuracy < chance level.")
        itr = 0
    elif p == 1:
        itr = math.log2(n) * 60 / t
    else:
        itr = (math.log2(n) + p*math.log2(p) + (1-p)*math.log2((1-p)/(n-1))) * 60 / t
    return itr

注意:MATLAB 中的 nargin 函数在 Python 中没有直接的对应项。在这里,我使用了 all 函数和类型检查来确保输入为数字,以确保与 MATLAB 的 nargin 检查相同的行为。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值