-
Notifications
You must be signed in to change notification settings - Fork 6
/
doFFT.m
executable file
·91 lines (64 loc) · 3.24 KB
/
doFFT.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
function FFT = doFFT(inputData,markers,flag)
% written as a shell by Olav Krigolson
% runs FFT analysis byu conditions on EEG data structure
numberOfConditions = size(markers,2);
numberOfEpochs = size(inputData.data,3);
if flag == 0
for conditionCounter = 1:numberOfConditions
tempData = [];
tempDataCounter = 1;
for epochCounter = 1:numberOfEpochs
if strcmp(markers(conditionCounter),inputData.epoch(epochCounter).eventtype)
tempData(:,:,tempDataCounter) = inputData.data(:,:,epochCounter);
tempDataCounter = tempDataCounter + 1;
end
end
if isempty(tempData)
ERP.data(:,:,conditionCounter) = NaN(size(inputData.data,1),size(inputData.data,2));
FFT.data(:,:,conditionCounter) = NaN(size(inputData.data,1),(size(inputData.data,2)/2)-1);
FFTFrequencies = 1:(size(inputData.data,2)/2)-1;
else
[FFTResults, trialPower, FFTPower, trialPhase, FFTFrequencies] = doFourier(tempData,inputData.srate);
FFT.data(:,:,conditionCounter) = FFTResults;
FFT.phase(:,:,conditionCounter) = FFTPower;
if numberOfConditions == 1
FFT.trialPower(:,:,:,conditionCounter) = trialPower;
FFT.trialPhase(:,:,:,conditionCounter) = trialPhase;
end
end
FFT.epochCount(conditionCounter) = tempDataCounter - 1;
end
end
if flag == 1
for conditionCounter = 1:numberOfConditions
tempData = [];
tempDataCounter = 1;
for epochCounter = 1:numberOfEpochs
tempData(:,:,tempDataCounter) = inputData.data(:,:,epochCounter);
tempDataCounter = tempDataCounter + 1;
end
if isempty(tempData)
ERP.data(:,:,conditionCounter) = NaN(size(inputData.data,1),size(inputData.data,2));
FFT.data(:,:,conditionCounter) = NaN(size(inputData.data,1),(size(inputData.data,2)/2)-1);
FFTFrequencies = 1:(size(inputData.data,2)/2)-1;
else
[FFTResults, trialPower, FFTPower, trialPhase, FFTFrequencies] = doFourier(tempData,inputData.srate);
FFT.data(:,:,conditionCounter) = FFTResults;
FFT.phase(:,:,conditionCounter) = FFTPower;
if numberOfConditions == 1
FFT.trialPower(:,:,:,conditionCounter) = trialPower;
FFT.trialPhase(:,:,:,conditionCounter) = trialPhase;
end
end
FFT.epochCount(conditionCounter) = tempDataCounter - 1;
end
end
FFT.frequencies = FFTFrequencies;
FFT.totalEpochs = numberOfEpochs;
FFT.chanlocs = inputData.chanlocs;
FFT.srate = inputData.srate;
FFT.epochTime(1) = inputData.xmin;
FFT.epochTime(2) = inputData.xmax;
FFT.times = inputData.times;
disp('FFTs have now been created...');
end