资源简介
CSP 用于处理EEG信号数据 特征提取算法
代码片段和文件信息
function CSPMatrix = learnCSP(EEGSignals)
%
%
% Copyright (C) 2010 Fabien LOTTE
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation either version 3 of the License or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program. If not see .
%
%this function learns the CSP (Common Spatial Patterns) filters to
%discriminate two mental states in EEG signals
%
%Input:
%EEGSignals: the training EEG signals composed of 2 classes. These signals
%are a structure such that:
% EEGSignals.x: the EEG signals as a [Ns * Nc * Nt] Matrix where
% Ns: number of EEG samples per trial
% Nc: number of channels (EEG electrodes)
% nT: number of trials
% EEGSignals.y: a [1 * Nt] vector containing the class labels for each trial
% EEGSignals.s: the sampling frequency (in Hz)
%
%Output:
%CSPMatrix: the learnt CSP filters (a [Nc*Nc] matrix with the filters as rows)
%
%by Fabien LOTTE (fprlotte@i2r.a-star.edu.sg)
%created: 02/03/2010
%last revised: 02/03/2010
%
%See also: extractCSPFeatures
%check and initializations
nbChannels = size(EEGSignals.x2);
nbTrials = size(EEGSignals.x3);
classLabels = unique(EEGSignals.y);
nbClasses = length(classLabels);
if nbClasses ~= 2
disp(‘ERROR! CSP can only be used for two classes‘);
return;
end
covMatrices = cell(nbClasses1); %the covariance matrices for each class
%computing the normalized covariance matrices for each trial
trialCov = zeros(nbChannelsnbChannelsnbTrials);
for t=1:nbTrials
E = EEGSignals.x(::t)‘;
EE = E * E‘;
trialCov(::t) = EE ./ trace(EE);
end
clear E;
clear EE;
%computing the covariance matrix for each class
for c=1:nbClasses
covMatrices{c} = mean(trialCov(::EEGSignals.y == classLabels(c))3);
end
%the total covariance matrix
covTotal = covMatrices{1} + covMatrices{2};
%whitening transform of total covariance matrix
[Ut Dt] = eig(covTotal); %caution: the eigenvalues are initially in increasing order
eigenvalues = diag(Dt);
[eigenvalues egIndex] = sort(eigenvalues ‘descend‘);
Ut = Ut(:egIndex);
P = diag(sqrt(1./eigenvalues)) * Ut‘;
%transforming covariance matrix of first class using P
transformedCov1 = P * covMatrices{1} * P‘;
%EVD of the transformed covariance matrix
[U1 D1] = eig(transformedCov1);
eigenvalues = diag(D1);
[eigenvalues egIndex] = sort(eigenvalues ‘descend‘);
U1 = U1(: egIn
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 3027 2010-10-28 17:26 CSP\learnCSP.m
文件 2845 2010-10-28 17:26 CSP\learnCSPLagrangian.m
目录 0 2011-07-08 17:22 CSP
----------- --------- ---------- ----- ----
5872 3
相关资源
- 雷达线性调频信号的模糊函数Matlab代
- LMS算法及归一化LMS算法的MATLAB代码
- 均匀球体与长方体重力异常正演模拟
- 小波降噪软硬阈值改进阈值matlab代码
- 小波神经网络MATLAB代码.zip
- 差分进化算法的Matlab代码,可运行
- 一维激波管问题upwind格式matlab代码
- 肤色模型人脸识别matlab代码
- 多元回归的交叉验证程序 可供做预测
- 小波去噪matlab代码
- 蚁群算法求解最短路径问题MATLAB代码
- RLS语音信号去噪matlab代码
- 图像处理/图像分割实验/prewitt/robert
- 基于图像处理的汽车牌照识别系统m
- 弹道图绘制-matlab代码
- ID3算法 matlab代码实现
- 矩形贴片天线Matlab仿真
- MATLAB代码,用于快速平滑滤波
- MATLAB代码,用于分峰拟合
- 碎纸片拼接问题所有的matlab代码
- 计算视频质量BDBR 和BD-PSNR的matlab代码
- 多路径匹配追踪广度优先MMP_BFMATLAB代
- 优化算法——粒子群算法(PSO)原理
- 森林火灾视频识别提取
- MODIS、Landsat等遥感影像批量空间插值
- 高斯混合概论假设密度滤波MATLAB代码
- 人工神经网络程序
- 追赶法的简单MATLAB代码
- 模式识别第四版matlab代码
- 16QAM数字通信系统——MATLAB代码
评论
共有 条评论