matlab代码实现eeg单通道数据滤波 去眼电等预处理
时间: 2024-01-19 18:03:30 浏览: 265
Matlab-Import-Filter-2-4-src.rar_.eeg文件_EEG_EEG MATLAB_EEG 预处理_S
以下是一个示例MATLAB代码,用于对单通道EEG数据进行滤波和去除眼电等预处理:
```
% Load EEG data
eeg = load('eeg_data.mat'); % Replace with your own data file
% Define filter parameters
fs = 256; % Sampling rate (Hz)
nyquist_freq = fs/2;
low_cutoff_freq = 1; % Low-pass filter cutoff frequency (Hz)
high_cutoff_freq = 50; % High-pass filter cutoff frequency (Hz)
filter_order = 4; % Filter order (higher order = steeper roll-off)
% Design filter coefficients for low-pass filter
[b_low, a_low] = butter(filter_order, low_cutoff_freq/nyquist_freq, 'low');
% Design filter coefficients for high-pass filter
[b_high, a_high] = butter(filter_order, high_cutoff_freq/nyquist_freq, 'high');
% Apply the filters to the EEG data
eeg_low = filtfilt(b_low, a_low, eeg); % Low-pass filtered data
eeg_filt = filtfilt(b_high, a_high, eeg_low); % High-pass filtered data
% Remove eye blink artifacts using ICA
[weights, sphere] = runica(eeg_filt);
ica_data = weights*sphere*eeg_filt; % Apply ICA weights to the filtered data
% Plot the original and processed data
t = 0:1/fs:(length(eeg)-1)/fs; % Time vector
figure;
subplot(2,1,1);
plot(t, eeg);
xlabel('Time (s)');
ylabel('Amplitude (\muV)');
title('Original EEG data');
subplot(2,1,2);
plot(t, ica_data(1,:));
xlabel('Time (s)');
ylabel('Amplitude (\muV)');
title('Processed EEG data (filtered and eye blink artifacts removed)');
```
请注意,这只是一个示例代码,并且需要根据您自己的数据进行修改和调整。此外,还有其他方法可以在MATLAB中进行EEG数据预处理,具体取决于您的数据类型和分析目的。
阅读全文