-
Notifications
You must be signed in to change notification settings - Fork 1
/
warp_templates.m
57 lines (45 loc) · 1.74 KB
/
warp_templates.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
%
% stretches single trial spectra to a target frequency using a reference peak
% frenquency i.e. stretches a spectrum to the target frequency 10 using the
% subject specific mean frequency 11.5 calculated from the median template
% peak frequency
%
% [warpmat, TWseries] = warp_templates(tfdata, evLat, newLat, timevec);
%
% Author: Johanna Wagner, Swartz Center for Computational Neuroscience, UC San Diego, 2019
% adapted from a function written by Julie Onton
%
% Example
% >> [warpmat, Freqtw] = warp_templates(spectemplates, [11.2 11.2 11.2 11.2 11.2], 10, freqvec);
%
%
% INPUTS
%
% tfdata - [matrix] single trial spectra (trials x spectra)
% evLat - [real] are all the peak frequencies to warp in format (trials x peak)
% newLat - [real] are the new target peak frequencies to which to warp (row vector)
% timevector - [vector] frequency vector
%
% OUTPUTS:
% TWseries - the warped templates
% warpmat - the warping matrix with which the original spectra were
% multiplied to warp the data
function [warpmat, TWseries] = warp_templates(tfdata, evLat, newLat, timevec);
timevecabsS = (abs(timevec(1))+timevec);
clear indexAtMinL;
clear indexAtMinNew;
for k = 1: size(evLat,1);
for i = 1:size(evLat,2);
[minDifferenceValue, indexAtMinL(k,i)] = min(abs(timevecabsS - (abs(timevec(1))+evLat(k,i))));
end
end
for i = 1:size(evLat,2);
[minDifferenceValue, indexAtMinNew(i)] = min(abs(timevecabsS - (abs(timevec(1))+newLat(i))));
end
TWseries = zeros(size(tfdata));
for i = 1:size(evLat,1);
warpmat(i,:,:) = timewarp([1 indexAtMinL(i,:) size(timevec,2)], [1 indexAtMinNew size(timevec,2)]);
TWseries(i,:) = transpose(squeeze(warpmat(i,:,:))*squeeze(tfdata(i,:))');
display(['timewarping...trial...' num2str(i) ' of ' num2str(size(evLat,1))])
end
end