%% data = ch*time
%  snr = power(signalFreq)/ avg(power(freq w/o signalfreqIndex))
% example mySNR(data,[10 11 12 13], 11, 5)
% return 1) each channel's SNR of power(11)/avg.power(10 12 13)
%        2) each cahnnel's power

function [ out1, out2] = mySNR2( data,freq,signalFreq,resolution )
out1 = zeros(size(data,1),1);
out2 = zeros(size(data,1),size(data,2));
noiseIndex = freq(~ismember(freq,signalFreq))*resolution+1;
signalIndex = (signalFreq)*resolution+1;

%% applying CCA


%%
for i=1:size(data,1)%for each channel
    tempPower = abs(fft(data(i,:)));
    noisepower = 0;
    for j=1:length(noiseIndex)
        noisepower = noisepower+tempPower(1,floor(noiseIndex(j)));
    end
    noisepower = noisepower/length(noiseIndex);
    out1(i) = tempPower(1,floor(signalIndex))/ noisepower;
    out2(i,:) = tempPower;%(1,floor(signalIndex));
end

end

