function RR = CCA(ch1,ch2,ch3,ch4,sampleRate)

Fs = sampleRate;
BandPassTAG = true;
if(BandPassTAG)
    X(:,1) = bp(double(ch1),Fs);
    X(:,2) = bp(double(ch2),Fs);
    X(:,3) = bp(double(ch3),Fs);
    X(:,4) = bp(double(ch4),Fs);
else
    X(:,1) = double(ch1);
    X(:,2) = double(ch2);
    X(:,3) = double(ch3);
    X(:,4) = double(ch4);
end

t = (1:length(X))/Fs;
i = 8;
index =1;
%figure(1); 
%plot(X(:,1));
while (i<14)
    Y1 = sin(2*pi*i*t);
    Y2 = cos(2*pi*i*t);
    %Y3 = sin(4*pi*10*t);
    %Y4 = cos(4*pi*10*t);
    Y = [Y1, Y2];% Y3 Y4];
    Y = reshape(Y,length(X),2);
    C = [X,Y];
    c = cov(C);
    %[Qx Rx E] = qr(X, 0);
%     figure(1); 
%     plot(X);
%     figure(2); 
%     plot(Y);
    [A B r U V] = canoncorr(X,Y); 
    r;
    RR(index,1) = r(1,1);
    QQ(index,1) = i;
    i = i+0.25;
    index = index +1;
end;
%figure();

plot(QQ(:,1),RR(:,1),'b');hold on;
xlabel('Hz');
ylabel('Accuracy %')
%======old==========
% %clear all;
% clc;
% %x1 = load('9Hz-9.25Hz-noEyeBlink.txt');
% %x1 = load('1234567890Hz-noEyeBlink.txt');
% %x1 = load('8-7-RefInFront.txt');
% Fs = 256;
% %x1 = load('home/yute/Data/VEP/Mike Chi/button_1_500Hz.mat');
% % x1(:,2) = x1(:,2)-mean(x1(:,1));
% % x1 = bp(x1,128);
% 
% startTime = 1;
% dataLength = 4;
% 
% endTime = startTime*Fs + dataLength*Fs-1;
% %X = x1(startTime*Fs:endTime,2);
% X = [eeg1_9(startTime*Fs:endTime), eeg2_9(startTime*Fs:endTime), eeg3_9(startTime*Fs:endTime)];
% X = bp(X, Fs);
% t = (1:length(X))/Fs;
% i = 8;
% index =1;
% %figure(1); 
% %plot(X(:,1));
% while (i<12)
%     Y1 = sin(2*pi*i*t);
%     Y2 = cos(2*pi*i*t);
%     %Y3 = sin(4*pi*10*t);
%     %Y4 = cos(4*pi*10*t);
%     Y = [Y1, Y2];% Y3 Y4];
%     Y = reshape(Y,length(X),2);
%     C = [X,Y];
%     c = cov(C);
%     %[Qx Rx E] = qr(X, 0);
% %     figure(1); 
% %     plot(X);
% %     figure(2); 
% %     plot(Y);
%     [A B r U V] = canoncorr(X,Y); 
%     r
%     RR(index,1) = r(1,1);
%     QQ(index,1) = i;
%     i = i+0.25;
%     index = index +1;
% end;
% figure(6);
% plot(QQ(:,1),RR(:,1),'b')
% xlabel('Hz');
% ylabel('Accuracy %')