-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_add_for_online_performance.m
70 lines (68 loc) · 3.14 KB
/
data_add_for_online_performance.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
data_index=data_index+1;
data_index_mod=mod(data_index-1,DATA_LENGTH)+1;
%在线滤波
data_unfilter(data_index_mod,:)=x(ch);%C++里扔进来的数据存起来
if data_index_mod<=filt_n+1
xx=[filter_b(2:data_index_mod),-filter_a(2:data_index_mod)];
yy=[data_unfilter(data_index_mod-1:-1:1,:);data(data_index-1:-1:1,:)];
else
xx=[filter_b(2:filt_n+1),-filter_a(2:filt_n+1)];
yy=[data_unfilter(data_index_mod-1:-1:data_index_mod-filt_n,:);
data(data_index_mod-1:-1:data_index_mod-filt_n,:)];
end
data(data_index_mod,:)=filter_b(1)*data_unfilter(data_index_mod,:);
if(size(xx,2)>0)
data(data_index_mod,:)=data(data_index_mod,:)+xx*yy;
end
%数据处理
if mod(data_index,slide)==0%每slide个数据处理一次
% if mod(data_index,TRIAL)>(TRIAL_TRAISIENT) || mod(data_index,TRIAL)==0
if(data_index_mod>segment)
index=index+1;
Y=data(data_index_mod-segment+1:data_index_mod,:)';%4个通道窗长内数据
for j=1:frecount
z1 = [reference_1{j};Y];%将两个矩阵合成一个矩阵
C_1 = cov(z1.'); %计算自协方差矩阵
Cxx_1 = C_1(1:sx, 1:sx) + 10^(-8)*eye(sx); %求得X的自协方差矩阵
Cxy_1 = C_1(1:sx, sx+1:sx+sy); %求得X和Y的互协方差矩阵
Cyx_1 = Cxy_1';
Cyy_1 = C_1(sx+1:sx+sy, sx+1:sx+sy) + 10^(-8)*eye(sy);%求得Y的自协方差矩阵
[Wx_1,r_1] = eig(inv(Cxx_1)*Cxy_1*inv(Cyy_1)*Cyx_1);%r is eigenvalues;A*Wx = r*Wx,r的index与Wx的列的index对应
r_1 = sqrt(real(r_1)); % Canonical correlations 典型相关系数
r_1 = diag(r_1);%矩阵转换成向量后上下翻转
% V = fliplr(Wx);%左右翻转
[r_1,~]= sort((real(r_1)),'descend');
%r_1 = flipud(r_1);
rou_1(j) = r_1(1);%fundamental
z1 = [reference_2{j};Y];%将两个矩阵合成一个矩阵
C_1 = cov(z1.'); %计算自协方差矩阵
Cxx_1 = C_1(1:sx, 1:sx) + 10^(-8)*eye(sx); %求得X的自协方差矩阵
Cxy_1 = C_1(1:sx, sx+1:sx+sy); %求得X和Y的互协方差矩阵
Cyx_1 = Cxy_1';
Cyy_1 = C_1(sx+1:sx+sy, sx+1:sx+sy) + 10^(-8)*eye(sy);%求得Y的自协方差矩阵
[Wx_1,r_1] = eig(inv(Cxx_1)*Cxy_1*inv(Cyy_1)*Cyx_1);%r is eigenvalues;A*Wx = r*Wx,r的index与Wx的列的index对应
r_1 = sqrt(real(r_1)); % Canonical correlations 典型相关系数
r_1 = diag(r_1);%矩阵转换成向量后上下翻转
% V = fliplr(Wx);%左右翻转
[r_1,~]= sort((real(r_1)));
r_1 = flipud(r_1);
rou_2(j) = r_1(1);%harmonics
end
R_1(index,:) = rou_1;
R_2(index,:) = rou_2;
[~,signal_1] = max(rou_1);Signal_1(index) = signal_1;
[~,signal_2] = max(rou_2);Signal_2(index) = signal_2;
if (signal_1~=signal_2)
Signal(index) = 5;
else
Signal(index) = signal_1;%按基波
end
trigger(index) = x(DATA_CHANNEL+1);
%end
end
else
signal_1=-1;
velocity=0;
variance=0;
output = [signal_1 velocity variance];
end