-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculateRMSEReconstrucionWhisker.m
53 lines (48 loc) · 2.21 KB
/
calculateRMSEReconstrucionWhisker.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
path = 'F:\Diego\Matlab\LeoBatch\Data\';
files = dir(sprintf('%s%s',path,'Experiment*'));
for anm=1:15
anm
clear data;
load (sprintf('%s%s',path,files(anm).name));
% Find the name of the variable
varNames = who;
aux = strfind(varNames,'Exper');
listFound = getFoundNames(aux);
% Should be one and only one
varData = varNames{listFound};
data = eval(varData);
clear Exper*;
NTrials = length(data.wl.trials);
NWhiskers = length(data.wl.trials{1}.theta);
for k=1:NWhiskers,
for i=1:NTrials,
auxtheta = data.wl.trials{i}.theta{k};
auxtimes = data.wl.trials{i}.time{k};
if (auxtimes(end)-auxtimes(1))/0.002+1 == length(auxtimes)
theta = auxtheta;
else
theta = (interp1q(auxtimes',auxtheta',[auxtimes(1):0.002:auxtimes(end)]'))';
end
if ~isnan(theta)
[hh amplitude lowPass filteredSignal setpoint amplitudeS amplitudeDS setpointS setpointDS phaseDS] = LeoWhiskerDecomposition(theta);
RMSE{anm}(k,i) = sqrt(nanmean((abs(hh).*cos(angle(hh))+setpointS'-theta).^2));
RMSE_norm{anm}(k,i) = RMSE{anm}(k,i)/sqrt(nanmean(theta.^2));
NFFT = 2^nextpow2(length(theta));
y=fft(theta,NFFT)/length(theta);
f=500/2*linspace(0,1,NFFT/2+1);
fftData.theta{anm}(k,i,:) = 2*abs(y(1:NFFT/2+1));
fftData.freqsReal{anm} = f;
NFFT = 2^nextpow2(length(amplitudeDS));
% y=fft(amplitudeDS.*cos(phaseDS)+setpointDS,NFFT)/length(amplitudeDS);
y=fft(amplitudeDS.*0.707+setpointDS,NFFT)/length(amplitudeDS);
f=16/2*linspace(0,1,NFFT/2+1);
fftData.recDownsample{anm}(k,i,:) = 2*abs(y(1:NFFT/2+1));
fftData.freqsDown{anm} = f;
end
end
summary.RMSE{anm}(k) = mean(RMSE{anm}(k,:));
summary.RMSE_norm{anm}(k) = mean(RMSE_norm{anm}(k,:));
end
summary.allW.RMSE(anm) = nanmean(RMSE{anm}(:));
summary.allW.RMSE_norm(anm) = nanmean(RMSE{anm}(:));
end