diff --git a/Plots.m b/Plots.m index 7879ab8..5b9902b 100644 --- a/Plots.m +++ b/Plots.m @@ -31,21 +31,23 @@ function Plots(T) % stimulation parameters % first number is the mode of stimulation % 0 == none - % 1 == periodic - % 2 == phase dependend up state - % 3 == phase dependend down state + % 1 == semi-periodic + % 2 == phase dependend - var_stim = [ 0; % mode of stimulation - 60; % strength of the stimulus in Hz (spikes per second) - 200; % duration of the stimulus in ms - 5; % time between stimuli in s - 300]; % time until stimuli after negativ peak in ms + var_stim = [ 2; % mode of stimulation + 25; % strength of the stimulus in Hz (spikes per second) + 120; % duration of the stimulus in ms + 5; % time between stimulation events in s (ISI) + 0; % range of ISI in s [ISI-range,ISI+range] + 2; % Number of stimuli per event + 950; % time between stimuli within a event in ms + 500]; % time until stimuli after minimum in ms - T = 600; % duration of the simulation + T = 30; % duration of the simulation end -%[Ve, Vt, Marker_Stim] = TC(T, Param_Cortex_N2, Param_Thalamus_N2, Connectivity, var_stim); -[Ve, Vt, Marker_Stim] = TC(T, Param_Cortex_N3, Param_Thalamus_N3, Connectivity, var_stim); +[Ve, Vt, Marker_Stim] = TC(T, Param_Cortex_N2, Param_Thalamus_N2, Connectivity, var_stim); +%[Ve, Vt, Marker_Stim] = TC(T, Param_Cortex_N3, Param_Thalamus_N3, Connectivity, var_stim); L = max(size(Vt)); timeaxis = linspace(0,T,L); @@ -55,22 +57,26 @@ function Plots(T) title('Pyramidal membrane voltage'), xlabel('time in s'), ylabel('Ve in mV') ylim([-80, -40]) % vertical line for markers -hx1 = graph2d.constantline(Marker_Stim(2,:), 'color', 'black'); -hx2 = graph2d.constantline(Marker_Stim(1,:), 'color', 'red'); -changedependvar(hx1,'x'); +for i=1:var_stim(6) + hx = graph2d.constantline(Marker_Stim/1E2+(i-1)*var_stim(7)/1E3,'ydata', get(gca,'ylim'), 'color', 'black', 'LineStyle', ':'); + changedependvar(hx,'x'); +end +hx2 = graph2d.constantline((Marker_Stim/1E2 -var_stim(8)/1E3), 'color', 'red'); changedependvar(hx2,'x'); subplot(212), plot(timeaxis,Vt) title('Thalamic relay membrane voltage'), xlabel('time in s'), ylabel('Vt in mV') +ylim(get(gca,'ylim')); % vertical line for markers -hx = graph2d.constantline(Marker_Stim(2,:)); -changedependvar(hx,'x'); - -[Pxx,f] = pwelch(Ve-mean(Ve),hamming(L/30), 4*L/T, 2048, L/T); -n = find(f<=30, 1, 'last' ); - -figure(2) -plot(f(1:n),log(Pxx(1:n))) -title('Powerspectrum with pwelch'), xlabel('frequency in Hz'), ylabel('Power (log)') +for i=1:var_stim(6) + hx = graph2d.constantline(Marker_Stim/1E2+(i-1)*var_stim(7)/1E3,'ydata', get(gca,'ylim'), 'color', 'black', 'LineStyle', ':'); + changedependvar(hx,'x'); +end +% [Pxx,f] = pwelch(Ve-mean(Ve),hamming(L/30), 4*L/T, 2048, L/T); +% n = find(f<=30, 1, 'last' ); +% +% figure(2) +% plot(f(1:n),log(Pxx(1:n))) +% title('Powerspectrum with pwelch'), xlabel('frequency in Hz'), ylabel('Power (log)') %save('Timeseries', 'Ve', 'Vt'); end \ No newline at end of file diff --git a/Stimulation.h b/Stimulation.h index 662d75e..349fe7b 100644 --- a/Stimulation.h +++ b/Stimulation.h @@ -127,7 +127,6 @@ class Stim { Thalamic_Column* Thalamus; /* Data containers */ - vector marker_minimum; vector marker_stimulation; /* Random number generator in case of semi-periodic stimulation */ @@ -206,6 +205,11 @@ void Stim::check_stim (int time) { stimulation_started = true; Thalamus->set_input(strength); + /* Add marker for the first stimuli in the event */ + if(count_stimuli == 1) { + marker_stimulation.push_back(time - onset_correction); + } + /* Check if multiple stimuli should be applied */ if (count_stimuli < number_of_stimuli) { /* Update the timer with respect to time between stimuli */ @@ -217,14 +221,8 @@ void Stim::check_stim (int time) { time_to_stimuli += (ISI_range==0)? ISI : Uniform_Distribution(Generator); /* Reset the stimulus counter for next stimulation event */ - if (number_of_stimuli != 1) { - count_stimuli = 1; - } + count_stimuli = 1; } - - /* Add marker */ - marker_minimum.push_back(0); - marker_stimulation.push_back(time - onset_correction); } break; @@ -242,10 +240,6 @@ void Stim::check_stim (int time) { if(Cortex->Ve[0]>Ve_old) { threshold_crossed = false; minimum_found = true; - /* add one marker for every stimuli in the event */ - for(int i=0; iVe[0]; @@ -255,14 +249,18 @@ void Stim::check_stim (int time) { /* Wait until the stimulation should start */ if(minimum_found) { /* Start stimulation after time_to_stimuli has passed */ - if(count_to_start==time_to_stimuli) { + if(count_to_start==time_to_stimuli + (count_stimuli-1) * time_between_stimuli) { stimulation_started = true; Thalamus->set_input(strength); + /* Add marker for the first stimuli in the event */ + if(count_stimuli == 1) { + marker_stimulation.push_back(time - onset_correction); + } + /* Check if multiple stimuli should be applied */ if (count_stimuli < number_of_stimuli) { - /* Update the timer with respect to time between stimuli */ - time_to_stimuli += time_between_stimuli; + /* Update the number of stimuli */ count_stimuli++; } else { /* After last stimulus in event pause the stimulation */ @@ -271,15 +269,9 @@ void Stim::check_stim (int time) { count_to_start = 0; /* Reset the stimulus counter for next stimulation event */ - if (number_of_stimuli != 1) { - count_stimuli = 1; - } + count_stimuli = 1; } - - /* Add marker */ - marker_stimulation.push_back(time - onset_correction); } - count_to_start++; } break; @@ -308,14 +300,13 @@ void Stim::check_stim (int time) { mxArray* Stim::get_marker(void) { extern const int red; mxArray* Marker = mxCreateDoubleMatrix(0, 0, mxREAL); - mxSetM(Marker, 2); + mxSetM(Marker, 1); mxSetN(Marker, marker_stimulation.size()); - mxSetData(Marker, mxMalloc(sizeof(double)*2*marker_stimulation.size())); + mxSetData(Marker, mxMalloc(sizeof(double)*marker_stimulation.size())); double* Pr_Marker = mxGetPr(Marker); for(unsigned i=0; i