Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 38

Human survival requires not only natural conditions such as water, food, sunshine and air, but also

living conditions suitable for self-sustainability. Everyone's living environment is almost the same
on a large scale, but from a small scale, it is very different. Everyone is born in a specific family.
Therefore, a different family will affect a person. At home, what we feel is the love of our parents
without worry. When we grow up and go to such a complex environment as society, we will
suddenly feel confused. People don't treat us like that to their parents in life. Therefore, we must
learn to adapt to it, try to change ourselves, and integrate ourselves into society as soon as
possible, so that our life journey will be smooth.
This mentality counts in almost every stage of our life.First when a student keep learning new
skills,he always asks for more and desires to explore the unknown world.Therefore there is an
excellent chance that he stands out in peer groups.Second,in the workplace,office workers with
such attitude generally finish his tasks in a higher
quality,and they are more likely to climb up the ladder more quickly than their colleagues who
content themselves with the skills they already have Besides in our daily life people who keep
learning new skills are more positive and everyone around them must be fond of making friends
with them.
All in all,we must keep learning new skills so as to adapt to the fast-changing world.One the one
handwe should make friends with people who have such attitudeand let their positive energy
influence us.On the otherwe should bear in mind that what remains unchanged is change itselfso
we should never stop learning new skills.
导入数据

绘制脑电头皮图

显示通道名 显示电极名

2d 3d

绘制通道对应光谱图
在 Percent data to sample 输入框内更改采样率为 15,即展示当采样
为 15%数据时得到的结果,也可以默认设置为 100,得到结果分别如下图

15 100

1. 导入数据
2.2d 图

3.滤波

高通滤波 低通

滤波前后对比图
4. 跑 ICA 通道 1 地形图频谱图
1.数据预览

时间范围 10s

2.定位电极

2d 图
3.重参考及滤波处理(高通 0.5hz-低通 40hz)

插值坏导没做

4 跑 ICA(去伪迹)

IC1,IC2 数据集中在头壳外边眼电电极
去除完的图像
5.分段与基线校正

6. 插值坏导和剔除坏导
7. 创建事件清单

CSDN 大牛
加载数据
该数据集包含 154 个事件,共有两种类

型该实验中,有两种类型的事件"square" 和"rt"。“square“事件对应的是显显示器中绿色正
方形的外观,"rt"对应于受试者的反映时间的事件
1 数据预览

电压刻度调整至 50 微伏滚动时间窗口为 10s

调整通道数为 16 -----------------------------------------
\\
绘制脑电头皮图可视化通道位置(显示通道名 显示通道号)

绘制通道光谱图(采样 15%和 100%的效果图)


绘制所选通道的头皮位置(通道 1)

\\
滤波(下边缘频率 10hz,上边缘频率 50hz)

重新参考数据操作(平均参考)

选用平均参考
重参考及滤波后的图
提取数据 epoch

提取数据 epoch 移除基线值

在头皮图单轴绘制 ERP 数据
默认绘制 ERP 方差最大时刻的地形图,
本图在 289ms
在地形矩阵中绘制 ERP 轨迹

绘制一些列的 2D ERP scalp maps(输入需要的 epoch 延迟)

输入所需的延迟 0:100:500
绘制一些列的 3D ERP scalp maps
\\
选择 epoch 并绘制数据平均值
创建两种两种时间段,一半的目标刺激呈现在位置 1,另一半的目标刺激呈现在位置 2
4 5 指的是输入数据集的索引

绘制 ERP 图像(输入通道 27,输入 smoothing(平滑) 1 表示在临近的 epochs 进行平滑绘


图的时候,所取的值)
图中最上面的为电极的头皮位置,中间部分为 ERP 图,下面部分为电极的 ERP.
绘制平滑的 ERP(平滑宽度设置为 10)
对 ERP image 的 trial 进行排序
eeglab 默认按照 trial 在实验过程中出现的顺序排列。在 pop_erpimage.m 界面上点击 Epoch-
sorting field 按钮并选择 Latency,点击 Event type 选择 rt。并在 Event time range 输入-200
800 ms

在 pop_erpimage.m 界面上点击 Epoch-sorting field 按钮并选择 Latency,点击 Event type 选择


rt。并在 Event time range 输入-200 800 ms。Align 设置为 inf

\\
在 ERP 中按 Phase Value 对 Trials 进行排序
eeglab 默认按照 trial 在实验过程中出现的顺序排列。在 pop_erpimage.m 界面上,清除
Epoch-sorting field、Event type、Align 和 Event time range。在 Sort trials by phase section 中
Frequency 中输入 10(Hz),在 Window Center 输入 0
在 ERP 中按 Phase Value 对 Trials 进行排序
输入如下参数
上图的最上方子图的 ERP image。倒数第二个子图是 ERSP(Event Related Spectral Power),
表示的是功率的平均变化(单位为 dB)。在这个子图中,曲线没有超出蓝色区域,表示在
选择的频率 10.13Hz(见右下角)相对基线水平(25.93dB),功率没有显著变化。最下方
的子图的 ITC。它表示的相对刺激呈现而言,相位同步化的程度。10.13Hz 表示选择分析的
频段。可以看出在 300Hz 附近相位同步化显著增强

Eeglab 默认按照 trial 在实验过程中出现的顺序排列


\\
ICA 分解数据
Run ica
绘制 2-D Component Scalp Maps(绘制 1:12 个独立成分)

绘制 Component headplots(1:12)
学习和删除 ICA 组件

绘制 component spectra and maps


估计独立成分的贡献,假设考察 27 号
绘制独立成分 ERPs

\\
绘制独立成分 ERP 贡献

上图中黑色包络线是各个时间点的所有 channel 的最大值和最小值,彩线是各个独立成分


的的 ERP。如果只想要了解对 200-500ms 数据 ERP 贡献最大的独立成分,可进行下列操作
绘制 Component ERP-image
\\
Decomposing channel data
为了检测 ERSP(event-related spectral perturbation)和 ITC(inter-trial coherence
得到的结果分为两个子图,上方是 ERSP 子图,下方是 ITC 子图。
ERSP 子图:该子图左方的 panel 是基线的平均功率谱,而各个时间点的 ERSP 包络线。而
top image 是相对基线,每个时间点、每个频率的频谱功率改变(event-related changes in
spectral power (from pre-stimulus baseline) at each time during the epoch and at each frequency
(< 50 Hz))。
ITC 子图:A significant ITC indicates that the EEG activity at a given time and frequency in single
trials becomes phase-locked (not phase-random with respect to the time-locking experimental
event).

Computing component time/frequency transforms


由于各个独立成分更可能直接反应大脑的 EEG source,因此这里将对独立成分进行时频分解。
这步操作选择 FFT,是因为相对 wavelets 而言,选择 FFT 可以计算更低的频率。
\\等价偶极子定位

加载数据
定位电极
飞星数据预处理
加载数据

绘制 2D 图

此时图像
重参考(平均参考)

滤波(0.5-45)
此时图像

跑 ica
去眼电
此时图像

分段 2 8 分段

叠加平均看 PZ,在 300 处


时频分析 看通道 17 的

横轴时间 纵轴频率

绘制 ERP 图像
独立成分分析法
沟通也许是两颗心之间的捷径,没有沟通人与人之间会出现误解、

扭曲的局面,给工作和生活带来极大的害处。沟通的品质决定了生活

的品质,良好的沟通能够使我们很坦诚地生活。沟通能够拓展个人

关系的网络使对方感受到你的尊重和理解,能够迅速激发他人对你

的理解,让他人自愿地带给更多的协助;还能够避免人际之间无谓

的争论,不伤双方的感情,减少因误解所造成的压力。沟通是管理

工作的灵魂,是提高工作效率,实现共同目标,满足各种需要的重

要工具。美国通用电气公司就是靠着感情沟通式的管理,以惊人的速
度发展起来的,这种沟通式管理给人以深刻的启迪。国内外事业有成
的名企,无不视沟通为管理的真谛。沟通如同黑暗中的一缕阳光,让
一切有了生机和活力

学小波变换
//

clear

Fs = 128; % 采样频率 128hz

T = 1/Fs; % 计算采样周期

L = 256; % 信号长度,持续时间
t = (0:L-1)*T; % 设置采样时间点

x = 5 + 7*cos(2*pi*15*t - 30*pi/180) + 3*cos(2*pi*40*t - 90*pi/180); %构造 cos 为底原始信号

y = x + randn(size(t)); %添加噪声扰乱该信号

figure;

plot(t,y) %以 t 为横坐标,y 为纵坐标绘制连线图

title('加噪声的信号')

xlabel('时间(s)')

ylabel('X(t)')

N = 2^nextpow2(L); %取不小于 L 的最小的 2 的幂,因为 FFT 算法要求信号的长度为 2 的幂,当 NFFT 大于信号长度时,fft 函

数以零补齐。

Y = fft(y,N)/N*2; %作 FFT 分析时,幅值大小与输入点数有关,要得到真实的幅值大小,只要将变换后的结果乘以 2 除以 N

即可(Y 除以 N 得到双边谱,再乘以 2 得到单边谱)

f = Fs/N*(0:1:N-1); %经过 fft 变换后,频域上各个样点的频率值

A = abs(Y); %幅值(绝对值函数)

P = angle(Y); %相值(求复数相角,提取相位)

figure;

subplot(211);plot(f(1:N/2),A(1:N/2)); %函数 fft 返回值的数据结构具有对称性,因此只取前一半傅立叶变换之后的结果

title('幅值频谱')

xlabel('频率(Hz)')

ylabel('幅值')

subplot(212);plot(f(1:N/2),P(1:N/2));

title('相位谱频')

xlabel('频率(Hz)')

ylabel('相位')

//

figure;

spectrogram(y,128,120,128,Fs,'yaxis');

title('时频图');

//

Fs=1e4; %采样频率 10000hz

t=0:1/Fs:4;%时间长度为 4 秒,采样间隔 1/Fs

t1=0:1/Fs:1;

%10Hz 的信号

x1=[sin(2*pi*10*t1)';zeros(Fs*3,1)];

%1000Hz 的信号

x2=[zeros(Fs,1);sin(2*pi*1000*t1)';zeros(Fs*2,1)];

%2000Hz 的信号

x3=[zeros(Fs*2,1);sin(2*pi*2000*t1)';zeros(Fs,1)];

%3000Hz 的信号

x4=[zeros(Fs*3,1);sin(2*pi*3000*t1)'];

figure(1);

subplot(411);

plot(t,x1);
subplot(412);

plot(t,x2);

subplot(413);

plot(t,x3);

subplot(414);

plot(t,x4);

x=x1+x2+x3+x4;

figure(2);

subplot(211);

plot(t,x);

title('时域图');

axis([0 4 -2 2]);

%FFT 代码

X=fft(x);

N=length(x);

f=(1:N/2)*Fs/N;

subplot(212);

plot(f,abs(X(1:N/2)));

xlabel('f (Hz)');

ylabel('|X(f)|');

title('频谱图');

%STFT 关键代码

figure(3);

spectrogram(x,128,120,128,Fs,'yaxis');

title('时频图');

//

fs = 1000; % 采样频率 1khz

t = 0:1/fs:4-1/fs; %设置采样时间点,时间长度为 4 秒,采样间隔 1/Fs

L=4000; % 信号长度,持续时间

signal=fenduan(t);

plot(t,signal);

f = (0:(L-1))*(fs/L); %0 到 L 步长为 1 进行 f=(L-1)*fs/L 数组运算

Y = fft(signal); %对信号进行 fft 运算

figure

subplot(2,2,1);

plot(f,abs(Y*2/L)) %求幅值(对 Y 取绝对值函数起求幅值的作用)傅立叶变化是一种积分变换,积分的时候一般积分符号

后面的表达式是 f(x)dx,写成离散求和的时候通常只写 f[n]的求和,略去了与 dn 相乘,所以得到的结果就要除以 N,才是正

确的而变换后的频谱通常将 0 频移到中间,分为对称的为正负频率(模对称,幅角反对称)有时表示频谱的时候只需要用其一

半正频率部分就够了所以除以 N 之后还要乘以 2,表示把正负频率的加在一起

xlim([0,100]) %设置 x 轴限制

title('幅值频谱');
%窗口大小,一般取 2 的幂次

wlen = 256;

%hop size 即移动步长,一般要取一个小于 wlen 的数,推荐取 2 的幂次

hop = wlen/4;

%FFT 点数,理论上应该不小于 wlen,推荐取 2 的幂次

nfft = 256;

%选择一个窗函数

win = blackman(wlen, 'periodic');

%引入 spectrogram 函数

% Input: x 一维信号, win - 窗函数,wlen - hope 移动长度, nfft FFT 点数,fs 采样率

% Output:S 输入信号 x 的短时傅里叶变换,F- 频率向量,T- 时间向量

[S, F, T] = spectrogram(signal, win, wlen - hop, nfft, fs);

subplot(2,2,2);

PlotSTFT_2(T, F, S,win); %对 STFT 变换后的可视化函数

title('spectrogram');

signal = signal(end:-1:1); %把信号反转过来

subplot(2,2,3);

plot(f,abs(Y*2/L))

xlim([0,100])

title('幅值频谱');

% 窗口大小,一般取 2 的幂次

wlen = 256;

% hop size 即移动步长,一般要取一个小于 wlen 的数,推荐取 2 的幂次

hop = wlen/4;

% FFT 点数,理论上应该不小于 wlen,推荐取 2 的幂次

nfft = 256;

win = blackman(wlen, 'periodic');

[S, F, T] = spectrogram(signal, win, wlen - hop, nfft, fs);

subplot(2,2,4);

PlotSTFT_2(T, F, S,win);

title('spectrogram');

//

close all; clear; clc;

fs = 1000;

t = 0:1/fs:1 - 1/fs;

% 窗口大小,推荐取 2 的幂次

wlen = 256;

% hop size 即移动步长,一般要取一个小于 wlen 的数,推荐取 2 的幂次

hop = wlen/4;

% FFT 点数,理论上应该不小于 wlen,推荐取 2 的幂次

nfft = 256;

x = [10 * cos(2 * pi * 10 * t), 20 * cos(2 * pi * 20 * t),...


30 * cos(2 * pi * 30 * t), 40 * cos(2 * pi * 40 * t)];

figure;

subplot(2, 2, 1);

plot(x);

% 随便选的一个窗函数

win = blackman(wlen, 'periodic');

[S, f, t] = mystft(x, win, hop, nfft, fs);

subplot(2, 2, 2);

PlotSTFT(t,f,S);

x = x(end:-1:1);

subplot(2, 2, 3);

plot(x);

win = blackman(wlen, 'periodic');

[S, f, t] = mystft(x, win, hop, nfft, fs);

subplot(2, 2, 4);

PlotSTFT(t,f,S);

//

fs = 1000;

t = 0:1/fs:4-1/fs;

L=4000;

% x = [10 * cos(2 * pi * 10 * t), 20 * cos(2 * pi * 20 * t),

% 30 * cos(2 * pi * 30 * t), 40 * cos(2 * pi * 40 * t)];

% fplot(@(t) 10 * cos(2 * pi * 10 * t),[0 1],'g')

% hold on

% fplot(@(t) 20 * cos(2 * pi * 20 * t),[1 2],'g')

% hold on

% fplot(@(t) 30 * cos(2 * pi * 30 * t),[2 3],'g')

% hold on

% fplot(@(t) 40 * cos(2 * pi * 40 * t),[3 4],'g')

% hold off

% grid on

signal=fenduan(t);

signal = signal(end:-1:1);

plot(t,signal);

//

function m=fenduan(t)
m=10*cos(2*pi*20*t).*(t>=0 & t<1)+80*cos(2*pi*80*(t-1)).*(t>1 &
t<=2)+60*cos(2*pi*60*(t-2)).*(t>2 & t<=3)+40*cos(2*pi*40*(t-3)).*(t>3 &
t<=4);
end
%构造 cos 为底原始信号,四段 cos 信号组合而成
function PlotSTFT_2(T, F, S, win)
wlen = length(win); %窗长
C = sum(win)/wlen;
S = abs(S)/wlen/C;
S = 20*log10(S + 1e-6);
%figure(1)
surf(T, F, S)
shading interp;
axis tight;
view(0, 90);
%set(gca, 'FontName', 'Times New Roman', 'FontSize', 14);
xlabel('Time, s');
ylabel('Frequency, Hz');
title('Amplitude spectrogram of the signal');

hcol = colorbar;
%set(hcol, 'FontName', 'Times New Roman', 'FontSize', 14);
ylabel(hcol, 'Magnitude, dB');
End
fs = 1000;

t = 0:1/fs:4-1/fs;

L=4000;

% x = [10 * cos(2 * pi * 10 * t), 20 * cos(2 * pi * 20 * t),

% 30 * cos(2 * pi * 30 * t), 40 * cos(2 * pi * 40 * t)];

% fplot(@(t) 10 * cos(2 * pi * 10 * t),[0 1],'g')

% hold on

% fplot(@(t) 20 * cos(2 * pi * 20 * t),[1 2],'g')

% hold on

% fplot(@(t) 30 * cos(2 * pi * 30 * t),[2 3],'g')

% hold on

% fplot(@(t) 40 * cos(2 * pi * 40 * t),[3 4],'g')

% hold off

% grid on

signal=fenduan(t);

plot(t,signal);

f = (0:(L-1))*(fs/L); %0 到 L 步长为 1 进行 f=(L-1)*fs/L 数组运算

Y = fft(signal); %对信号进行 fft 运算

figure

subplot(2,2,1);

plot(f,abs(Y*2/L)) %求幅值(对 Y 取绝对值函数起求幅值的作用)傅立叶变化是一种积分变换,积分的时候一般积分符号

后面的表达式是 f(x)dx,写成离散求和的时候通常只写 f[n]的求和,略去了与 dn 相乘,所以得到的结果就要除以 N,才是正

确的而变换后的频谱通常将 0 频移到中间,分为对称的为正负频率(模对称,幅角反对称)有时表示频谱的时候只需要用其一

半正频率部分就够了所以除以 N 之后还要乘以 2,表示把正负频率的加在一起

xlim([0,100]) %设置 x 轴限制


%窗口大小,一般取 2 的幂次

wlen = 256;

%hop size 即移动步长,一般要取一个小于 wlen 的数,推荐取 2 的幂次

hop = wlen/4;

%FFT 点数,理论上应该不小于 wlen,推荐取 2 的幂次

nfft = 256;

%选择一个窗函数

win = blackman(wlen, 'periodic');

%引入 spectrogram 函数

% Input: x 一维信号, win - 窗函数,wlen - hope 移动长度, nfft FFT 点数,fs 采样率

% Output:S 输入信号 x 的短时傅里叶变换,F- 频率向量,T- 时间向量

[S, F, T] = spectrogram(signal, win, wlen - hop, nfft, fs);

subplot(2,2,2);

PlotSTFT_2(T, F, S,win); %对 STFT 变换后的可视化函数

signal = signal(end:-1:1);

subplot(2,2,3);

plot(f,abs(Y*2/L))

xlim([0,100])

% 窗口大小,推荐取 2 的幂次

wlen = 256;

% hop size 即移动步长,一般要取一个小于 wlen 的数,推荐取 2 的幂次

hop = wlen/4;

% FFT 点数,理论上应该不小于 wlen,推荐取 2 的幂次

nfft = 256;

win = blackman(wlen, 'periodic');

[S, F, T] = spectrogram(signal, win, wlen - hop, nfft, fs);

subplot(2,2,4);

PlotSTFT_2(T, F, S,win);

title('spectrogram');

You might also like