/*
read_bv.c
This file defines a mex-Function to load an eeg-File from a location.
data = read_bv(file, HDR, OPT);
read_bv(file, HDR, OPT); / with opt.data and opt.dataPos set
Arguments:
file - Name of EEG file (.eeg) is appended)
HDR - Information about the file (read from the *.vhdr header file)
.fs - Sampling rate
.nChans - Number of channels
.nPoints - Number of data points in the file (optional)
.scale - Scaling factors for each channel
.endian - Byte ordering: 'l' little or 'b' big
OPT - Struct with following fields
.chanidx - Indices of the channels that are to be read
.fs - Down sample to this sampling rate
.filt_b - Filter coefficients of IIR filter applied to raw data (b part) (optional)
.filt_a - Filter coefficients of IIR filter applied to raw data (a part) (optional)
.filt_subsample - Filter coefficients of FIR filter used for sub sampling (optional)
.data - A matrix where the data is stored (optional)
.dataPos - The position in the matrix[dataStart dataEnd fileStart fileend](optional)
The filter parts of the OPT structure are optional fields.
The default for the filt_subsample is a filter which takes the last value of
filtered block e.g. [0 ... 0 1]
2008/04/07 - Max Sagebaum
- file created
2008/04/25 - Max Sagebaum
- the char buffer was allocated with mxCalloc and freed
this was wrong I changed it to malloc
2008/05/20 - Max Sagebaum
- checked for linux compatibly
- fixed some errors in argument checking
2008/06/20/ - Max Sagebaum
- added option to load data into matrix
(c) Fraunhofer FIRST.IDA 2008
*/
#include <stdio.h>
#include "mex.h"
/*
* Define statements
*/
#define INT_16_SIZE 2 /* sizeof(short) */
#define mwSize int /* not available in Matlab 6 */
/* the field names for HDR and OPT*/
const char *FS_FIELD = "fs";
const char *N_CHANS_FIELD = "nChans";
const char *N_POINTS_FIELD = "nPoints";
const char *SCALE_FIELD = "scale";
const char *ENDIAN_FIELD = "endian";
const char *CHAN_ID_X_FIELD = "chanidx";
const char *FILT_A_FIELD = "filt_a";
const char *FILT_B_FIELD = "filt_b";
const char *FILT_SUBSAMPLE_FIELD = "filt_subsample";
const char *DATA = "data";
const char *DATA_POS = "dataPos";
/* the handle for the eeg-file */
static FILE *eegFile;
/* hdr data values */
static double rawDataSamplingRate;
static int rawDataChannelCount;
static double *rawDataScale;
static char rawDataEndian;
static int rawDataPoints;
/* opt non optional values */
static double *optChannelSelect;
static int optChannelSelectCount;
static double optSamplingRate;
/* the values for the IIR filter */
static int iirFilterSize = 0; /* the size of the IIR filter */
static int iirFilterOffset = 0; /* we access the buffers toroidal */
static double *bFilter; /* the b part of the IIR filter */
static double *aFilter; /* the a part of the IIR filter */
static double *xBuffer; /* the buffer for the unfiltered values */
static double *yBuffer; /* the buffer for the filtered values */
/* the values for the FIR filter */
static double *firFilter; /* a filter for the re sampling of the data */
static int firFilterPosition; /* the position in the filter */
static int firFilterSize; /* the size of the filter */
static double firFilterSum; /* the sum of the values in the filter */
static double *firFilterValues; /* the current values for the re sampling */
/* the positions of the samples when we write in a matrix*/
static double* dataPtr;
static int dataPtrSize; /* the number of rows in the data */
static int dataStart; /* the position of the first sample in the data*/
static int dataEnd; /* the position of the last sample in the data*/
static int fileStart; /* the first position of the data in the file*/
static int fileEnd; /* the last position of the data in the file*/
/*
* FORWARD DECLARATIONS
*/
static void rbv_init(int nrhs,const mxArray *prhs[]);
static bool
rbv_readDataBlock(double *dataBlock, short* dataBuffer, int channelCount ,bool swap);
static void rbv_readData( int nlhs, mxArray *plhs[]);
static double rbv_filterDataIIR(double value, int channel) ;
static void rbv_cleanup();
static void rbv_assert(bool aValue,const char* text);
/************************************************************
*
* mexFunction
*
************************************************************/
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
/* First check of argument counts and output */
rbv_assert(nrhs == 3, "Exactly three input arguments required.");
rbv_assert(nlhs <= 1, "One or two output arguments required.");
/* check the argument values and setup the filter, values, ... */
rbv_init(nrhs,prhs);
rbv_readData(nlhs,plhs);
rbv_cleanup();
}
/*************************************************************
*
* a quick and dirty solution for the file size
* I got it from http:/*bytes.com/forum/thread221370.html
* They mention that it will work with binary data(which is fine for us)
* but not with textual data.
*
* The function is only used, when HDR.nPoints was not set
*
* returns the length of a file (in bytes)
*
*************************************************************/
static int file_length(FILE *f)
{
int pos;
int end;
pos = ftell (f);
fseek (f, 0, SEEK_END);
end = ftell (f);
fseek (f, pos, SEEK_SET);
return end;
}
/************************************************************
*
* Checks if the input values are valid and sets up the values
* for reading the eeg-file
*
************************************************************/
static void rbv_init(int nrhs, const mxArray *prhs[])
{
const mxArray *FILE_NAME;
const mxArray *HDR;
const mxArray *OPT;
mxArray *tempPointer;
bool isAFilter, isBFilter; /* to check if filt_a and filt_b was set */
int lag; /* the difference between the sampling rate of the raw data and
and the sampling rate of the requested data */
int i; /* temp counting value */
double* tempDataPtr; /* pointer for OPT.dataPos */
char *charBuf; /* buffer for char reading (please free after usage) */
mwSize charBufLength; /* the size of the buffer */
/*
* opening the eeg file
*/
FILE_NAME = prhs[0];
charBufLength = mxGetNumberOfElements(FILE_NAME) + 1;
charBuf = malloc(charBufLength * sizeof(char));
if (mxGetString(FILE_NAME, charBuf, charBufLength) != 0) {
free(charBuf); charBuf = 0;
mexErrMsgTxt("Could not read file name.");
return;
}
eegFile = fopen(charBuf,"rb"); /* only r will cause an error rb stands */
/* for read binary */
rbv_assert(NULL != eegFile, "Could not open eeg file.");
free(charBuf); charBuf = 0;
/*
* HDR loading
*/
HDR = prhs[1];
rbv_assert(mxIsStruct(HDR),"HDR has to be a struct.");
/* see if we have our fields */
rbv_assert(mxGetFieldNumber(HDR,FS_FIELD) != -1,"The field HDR.fs was not set");
rbv_assert(mxGetFieldNumber(HDR,N_CHANS_FIELD) != -1,"The field HDR.nChans was not set");
rbv_assert(mxGetFieldNumber(HDR,SCALE_FIELD) != -1,"The field HDR.scale was not set");
rbv_assert(mxGetFieldNumber(HDR,ENDIAN_FIELD) != -1,"The field HDR.endian was not set");
/*
* load the field HDR.fs
*/
tempPointer = mxGetField(HDR,0,FS_FIELD);
rbv_assert(mxIsNumeric(tempPointer), "HDR.fs must b
没有合适的资源?快使用搜索试试~ 我知道了~
毕业设计&课设-脑机接口MATLAB工具箱.zip
共551个文件
m:463个
markdown:22个
vbs:11个
需积分: 0 0 下载量 125 浏览量
2024-01-08
23:07:06
上传
评论
收藏 2.54MB ZIP 举报
温馨提示
matlab算法,工具源码,适合毕业设计、课程设计作业,所有源码均经过严格测试,可以直接运行,可以放心下载使用。有任何使用问题欢迎随时与博主沟通,第一时间进行解答! matlab算法,工具源码,适合毕业设计、课程设计作业,所有源码均经过严格测试,可以直接运行,可以放心下载使用。有任何使用问题欢迎随时与博主沟通,第一时间进行解答! matlab算法,工具源码,适合毕业设计、课程设计作业,所有源码均经过严格测试,可以直接运行,可以放心下载使用。有任何使用问题欢迎随时与博主沟通,第一时间进行解答! matlab算法,工具源码,适合毕业设计、课程设计作业,所有源码均经过严格测试,可以直接运行,可以放心下载使用。有任何使用问题欢迎随时与博主沟通,第一时间进行解答! matlab算法,工具源码,适合毕业设计、课程设计作业,所有源码均经过严格测试,可以直接运行,可以放心下载使用。有任何使用问题欢迎随时与博主沟通,第一时间进行解答! matlab算法,工具源码,适合毕业设计、课程设计作业,所有源码均经过严格测试,可以直接运行,可以放心下载使用。有任何使用问题欢迎随
资源推荐
资源详情
资源评论
收起资源包目录
毕业设计&课设-脑机接口MATLAB工具箱.zip (551个子文件)
read_bv_matlab6.c 23KB
read_bv.c 20KB
brainserver.c 17KB
filter.c 9KB
ppWrite.c 4KB
winevents.c 2KB
wintest.c 2KB
headerfifo.c 1KB
winthreads.c 1KB
bbci_acquire_bv.cpp 28KB
bbci_acquire_tmsi_wlan.cpp 26KB
bbci_acquire_tmsi.cpp 26KB
bbci_acquire_enobio.cpp 16KB
QtCore4.dll 2.44MB
Enobio3GAPI.dll 97KB
inpout32.dll 96KB
inpoutx64.dll 96KB
WinBluetoothAPI.dll 14KB
.gitignore 13B
TMSiSDK.h 24KB
msvc_stdint.h 7KB
myRDA.h 3KB
filter.h 1KB
brainserver.h 1KB
headerfifo.h 693B
wintypes.h 438B
winthreads.h 437B
winevents.h 373B
bbci_acquire_tmsi.ilk 468KB
Enobio3GAPI.lib 11KB
procutil_getExtinctions.m 52KB
plotutil_channel1D.m 21KB
bbci_feedback_cursor.m 19KB
bbci_calibrate_csp.m 16KB
grid_plot.m 15KB
fig2subplot.m 14KB
file_readNIRx.m 14KB
file_readBV.m 13KB
bbci_calibrate_ERPSpeller.m 13KB
bbci_calibrate_ERPSpeller2.m 13KB
plot_scalp.m 12KB
pyff.m 12KB
proc_MARA.m 12KB
file_loadBV.m 11KB
bbci_acquire_sigserv.m 11KB
bbci_calibrate_NIRS.m 11KB
misc_checkType.m 11KB
mntutil_posExt55.m 11KB
proc_grandAverage.m 11KB
bbci_apply_setDefaults.m 11KB
procutil_selectTimeIntervals.m 10KB
plotutil_channel2D.m 10KB
bbci_apply_structures.m 10KB
plot_scalpEvolutionPlusChannel.m 9KB
train_RSLDAshrink.m 9KB
bbci_acquire_nirx.m 9KB
grid_addBars.m 9KB
clsutil_meanMTS.m 8KB
file_saveMatlab.m 8KB
bbci_import_dependencies.m 8KB
file_loadMatlab.m 8KB
reject_varEventsAndChannels.m 8KB
stat_rmanova.m 8KB
file_readNIRxHeader.m 8KB
plot_scalpOutline.m 7KB
proc_cspAuto.m 7KB
bbci_acquire_cognionics.m 7KB
file_readBVheader.m 7KB
find_artifacts.m 7KB
plot_scalpPatternsPlusChannel.m 7KB
bbci_acquire_lsl.m 7KB
proc_average.m 6KB
select_bandnarrow.m 6KB
stimutil_showDescription.m 6KB
bbci_adaptation_pcovmean.m 6KB
plot_barWithAntenna.m 6KB
plot_channel.m 6KB
select_timeival.m 6KB
mnt_setGrid.m 6KB
train_RLDAshrink.m 6KB
util_chanind.m 6KB
proc_segmentation.m 6KB
pyff_sendUdp.m 6KB
crossvalidation.m 5KB
bbci_calibrate_structures.m 5KB
util_toString.m 5KB
proc_rValues.m 5KB
procutil_movingAverage.m 5KB
startup_bbci_toolbox.m 5KB
mnt_restrictNIRSMontage.m 5KB
bbci_apply_initData.m 5KB
proc_spectrogram.m 5KB
plot_scoreMatrix.m 5KB
plot_cspAnalysis.m 5KB
proc_baseline.m 5KB
mnt_getNIRSMontage.m 5KB
util_printFigure.m 5KB
proc_classmeanDiff.m 4KB
bbci_acquire_randomSignals.m 4KB
tool_getERPAmplitude.m 4KB
共 551 条
- 1
- 2
- 3
- 4
- 5
- 6
资源评论
白话机器学习
- 粉丝: 8978
- 资源: 7681
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功