0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031 function [channels,overall_amplitude] = eeg_amplitudearea(EEG, channels, resrate, wstart, wend)
0032
0033 if wstart > wend
0034 error ('ERROR: wstart must be greater than wend')
0035 else
0036 [channels, overall_amplitude] = amplitudearea_msuV (EEG,channels, resrate, wstart, wend)
0037 overall_amplitude = overall_amplitude/(wend - wstart)
0038 end
0039
0040 return
0041
0042
0043 function [channels, overall_area] = amplitudearea_msuV (EEG, channels, resrate, wstart, wend)
0044
0045
0046
0047
0048 erp = mean(EEG.data,3);
0049
0050 [tmp ind1] =min( abs( EEG.times - wstart ) );
0051 [tmp ind2] =min( abs( EEG.times - wend ) );
0052 restep = 1000/resrate
0053
0054
0055 if EEG.times(ind1) > wstart
0056 ind1= ind1 -1;
0057 end
0058
0059 if EEG.times(ind2) < wend
0060 ind2= ind2 +1;
0061 end
0062
0063 for x= ind1:ind2
0064 t = (x -ind1)+1;
0065 tim(t) = EEG.times(x);
0066 end
0067
0068 tr = 1
0069 timr(tr) = wstart;
0070 while timr(tr) < wend
0071 tr = tr + 1;
0072 timr(tr) = timr(tr-1)+ restep;
0073 end
0074
0075 for x = 1:size(channels,2)
0076 channel = channels(x)
0077
0078 rerp(x, 1:tr) = spline(tim(:),erp(channel, ind1:ind2), timr(1:tr))
0079 for y = 1:(tr -1)
0080
0081
0082
0083 if (abs(rerp(x,y)) <= abs(rerp(x,y+1)))
0084 rhtsamp = y
0085 thtsamp = y + 1
0086 else
0087 rhtsamp = y + 1
0088 thtsamp = y
0089 end
0090 if y < (tr-1) | ((y == (tr-1)) & (wend - timr(tr - 1)) == restep)
0091 if ((rerp(x,y) > 0)& (rerp(x,y+1) < 0))|((rerp(x,y) < 0)& (rerp(x,y+1) > 0))
0092
0093
0094 opposite = abs(rerp(x,y))+abs(rerp(x,y+1))
0095 adjacent = restep
0096 tantheta = opposite/adjacent
0097 zerocross(x,y) = abs(rerp(x,y))/tantheta
0098 remainder(x,y) = adjacent - zerocross(x,y)
0099 area(x,y) = ((zerocross(x,y)/2)* (rerp(x,y)))+ ((remainder(x,y)/2)* (rerp(x,y+1)))
0100 else
0101 rectanglearea = rerp(x,(rhtsamp))*restep
0102 trianglearea = (rerp(x,(thtsamp))-rerp(x,(rhtsamp)))*restep/2
0103 area(x,y) = rectanglearea + trianglearea
0104 end
0105 elseif (y == (tr-1)) & ((wend - timr(tr - 1)) < restep)
0106 endstep = wend - timr(tr - 1)
0107 opposite = abs(rerp(x,y))+abs(rerp(x,y+1))
0108 adjacent = restep
0109 tantheta = opposite/adjacent
0110 zerocross = abs(rerp(x,y))/tantheta
0111 if (((rerp(x,y) > 0)& (rerp(x,y+1) < 0))|((rerp(x,y) < 0)& (rerp(x,y+1) > 0)))&(zerocross < endstep)
0112
0113
0114 remainder = endstep - zerocross
0115 opposite2 = tantheta * remainder * sign(rerp(x,y)) * -1
0116 area(x,y) = ((zerocross/2)* (rerp(x,y)))+ ((remainder/2)* opposite2)
0117 elseif thtsamp > rhtsamp
0118
0119
0120 opposite = abs(rerp(x,(thtsamp))) - abs(rerp(x,(rhtsamp)))
0121 adjacent = restep
0122 tantheta = opposite/adjacent
0123 triht = tantheta * endstep * sign(rerp(x,(thtsamp)))
0124 trianglearea = (endstep/2)*triht
0125 rectanglearea = rerp(x,(rhtsamp))*endstep
0126 area(x,y) = rectanglearea + trianglearea
0127 elseif rhtsamp > thtsamp
0128
0129
0130 opposite = abs(rerp(x,(thtsamp))) - abs(rerp(x,(rhtsamp)))
0131 adjacent = restep
0132 tantheta = opposite/adjacent
0133 excessstep = restep - endstep
0134 extrarectangleht = tantheta* excessstep * sign(rerp(x,(thtsamp)))
0135 extrarectanglearea = extrarectangleht * endstep *sign(rerp(x,(thtsamp)))
0136 triht = (opposite - extrarectangleht) * sign(rerp(x,(thtsamp)))
0137 trianglearea = (endstep/2)*triht *sign(rerp(x,(thtsamp)))
0138 rectanglearea = rerp(x,(rhtsamp))*endstep
0139 area(x,y) = rectanglearea + extrarectanglearea + trianglearea
0140 end
0141 end
0142 end
0143 end
0144
0145 for x = 1:(size(channels,2))
0146 overall_area(x) = sum(area(x,:))
0147 end
0148
0149 return