Permalink
Please sign in to comment.
Showing
with
0 additions
and 341 deletions.
- +0 −174 Test_Parameters.m
- +0 −167 Test_Stimulation.m
| @@ -1,174 +0,0 @@ | ||
| -% mex command is given by: | ||
| - | ||
| -function Test_Parameters(type) | ||
| -if nargin == 0 | ||
| - type = 2; | ||
| -end | ||
| - | ||
| - | ||
| -mex CXXFLAGS="\$CXXFLAGS -std=c++11 -O3" TC_mex.cpp Cortical_Column.cpp Thalamic_Column.cpp | ||
| - | ||
| -% Path to fieltrip preprocessing function | ||
| -if(isempty(strfind(path, '/nfshome/schellen/Documents/MATLAB/Tools/fieldtrip/preproc'))) | ||
| - addpath('~/Documents/MATLAB/Tools/fieldtrip/preproc'); | ||
| -end | ||
| - | ||
| -% Path to helper function | ||
| -if(isempty(strfind(path, '/nfshome/schellen/Documents/MATLAB/Tools/boundedline'))) | ||
| - addpath('~/Documents/MATLAB/Tools/boundedline'); | ||
| -end | ||
| - | ||
| -if type == 1 | ||
| - Param_Cortex = [4.7; % sigma_e | ||
| - 1.33; % g_KNa | ||
| - 120E-3]; % dphi | ||
| - | ||
| - Param_Thalamus = [0.051; % g_h | ||
| - 0.024]; % g_LK | ||
| - | ||
| - fn_data = '/nfshome/schellen/Documents/MATLAB/TC_model/Data/SO_Average_N3'; | ||
| - Model_Range_ERP = [-75, -45]; | ||
| - Model_Range_FSP = [-0.25, 1.25]; | ||
| - Data_Range_ERP = [-75, 35]; | ||
| - Data_Range_FSP = [2, 5]; | ||
| - xRange = -0.5:0.25:1.5; | ||
| -else | ||
| - Param_Cortex = [6; % sigma_e | ||
| - 2.0; % g_KNa | ||
| - 120E-3]; % dphi | ||
| - | ||
| - Param_Thalamus = [0.051; % g_h | ||
| - 0.0205]; % g_LK | ||
| - | ||
| - fn_data = '/nfshome/schellen/Documents/MATLAB/TC_model/Data/SO_Average_N3'; | ||
| - Model_Range_ERP = [-75, -45]; | ||
| - Model_Range_FSP = [-0.25, 1.25]; | ||
| - Data_Range_ERP = [-75, 35]; | ||
| - Data_Range_FSP = [2, 5]; | ||
| - xRange = -0.5:0.25:1.5; | ||
| -end | ||
| - | ||
| -Connectivity = [ 2.5; % N_et | ||
| - 2.5; % N_er | ||
| - 15; % N_te | ||
| - 15]; % N_ti | ||
| - | ||
| -load(fn_data); | ||
| - | ||
| -% stimulation parameters | ||
| -% first number is the mode of stimulation | ||
| -% 0 == none | ||
| -% 1 == semi-periodic | ||
| -% 2 == phase dependend | ||
| - | ||
| -var_stim = [ 0; % mode of stimulation | ||
| - 40; % strength of the stimulus in Hz (spikes per second) | ||
| - 100; % duration of the stimulus in ms | ||
| - 5; % time between stimulation events in s (ISI) | ||
| - 0; % range of ISI in s [ISI-range,ISI+range] | ||
| - 3; % Number of stimuli per event | ||
| - 1050; % time between stimuli within a event in ms | ||
| - 450]; % time until stimuli after minimum in ms | ||
| - | ||
| -T = 300; % duration of the simulation | ||
| - | ||
| -[Ve, Vi, Vt, Vr] = TC_mex(T, Param_Cortex, Param_Thalamus, Connectivity, var_stim); | ||
| -Fs = length(Ve)/T; | ||
| - | ||
| - | ||
| -Ve_low = ft_preproc_bandpassfilter(Ve, Fs, [0.25,4], 513, 'fir') + mean(Ve); | ||
| -Ve_FSP = ft_preproc_hilbert(ft_preproc_bandpassfilter(Ve, Fs, [12, 15], 513, 'fir'), 'abs').^2; | ||
| - | ||
| -% Search for peaks | ||
| -[~, x_SO] = findpeaks(-Ve_low, 'MINPEAKHEIGHT', 68, 'MINPEAKDISTANCE', 0.2*Fs); | ||
| - | ||
| -% Remove those events, that are too close to begin/end | ||
| -x_SO = x_SO(x_SO<(T-2)*Fs); | ||
| -x_SO = x_SO(x_SO> 2*Fs); | ||
| -x_SO = x_SO-3; % fix a different min position wrt data | ||
| - | ||
| -% Set the variables | ||
| -N_Stim = length(x_SO); | ||
| -Range_ERP = [-0.5, 1.5]; | ||
| -time_event = linspace(Range_ERP(1), Range_ERP(2), (Range_ERP(2)-Range_ERP(1))*Fs); | ||
| -Events = zeros(length(time_event), N_Stim); | ||
| -Events_FSP = zeros(length(time_event), N_Stim); | ||
| - | ||
| -% Segmentation | ||
| -for i=1:N_Stim | ||
| - Events(:,i) = Ve ((x_SO(i)+Range_ERP(1)*Fs)+1:(x_SO(i)+Range_ERP(2)*Fs)); | ||
| - Events_FSP(:,i) = Ve_FSP((x_SO(i)+Range_ERP(1)*Fs)+1:(x_SO(i)+Range_ERP(2)*Fs)); | ||
| -end | ||
| - | ||
| -mean_ERP_model= mean(Events, 2); %#ok<*NASGU> | ||
| -mean_FSP_model= mean(Events_FSP,2); | ||
| -sd_ERP_model = std (Events, 0, 2); | ||
| -sd_FSP_model = std (Events_FSP,0, 2); | ||
| - | ||
| -% Define handle for plotting | ||
| -BL_model =@(y,x) boundedline(y,x(:,1), x(:,2), 'alpha', 'transparency', 0.1, 'r'); | ||
| -BL_data =@(y,x) boundedline(y,x(:,1), x(:,2), 'alpha', 'transparency', 0.1, 'black'); | ||
| - | ||
| -% Option array for set | ||
| -Option_Name = { 'ylim'; | ||
| - 'ytick'; | ||
| - 'yticklabel'; | ||
| - 'ycolor'; | ||
| - 'xtick'}'; | ||
| - | ||
| -Option_Model_ERP = {Model_Range_ERP; | ||
| - linspace(Model_Range_ERP(1), Model_Range_ERP(2), 5); | ||
| - linspace(Model_Range_ERP(1), Model_Range_ERP(2), 5); | ||
| - 'black'; | ||
| - xRange}'; %#ok<*NBRAK> | ||
| - | ||
| -Option_Data_ERP = {Data_Range_ERP; | ||
| - linspace(Data_Range_ERP(1), Data_Range_ERP(2), 5); | ||
| - linspace(Data_Range_ERP(1), Data_Range_ERP(2), 5); | ||
| - 'black'; | ||
| - xRange}'; | ||
| - | ||
| -Option_Model_FSP = {Model_Range_FSP; | ||
| - linspace(Model_Range_FSP(1), Model_Range_FSP(2), 5); | ||
| - linspace(Model_Range_FSP(1), Model_Range_FSP(2), 5); | ||
| - 'black'; | ||
| - xRange}'; | ||
| - | ||
| -Option_Data_FSP = {Data_Range_FSP; | ||
| - linspace(Data_Range_FSP(1), Data_Range_FSP(2), 5); | ||
| - linspace(Data_Range_FSP(1), Data_Range_FSP(2), 5); | ||
| - 'black'; | ||
| - xRange}'; | ||
| - | ||
| -figure(1) | ||
| -subplot(411) | ||
| -plot(linspace(0,30,3000),Ve(101:3100)); | ||
| -title(['Ve with a mean of :',num2str(mean(Ve))]); | ||
| -subplot(412) | ||
| -plot(linspace(0,30,3000),Vi(101:3100)); | ||
| -title(['Vi with a mean of :',num2str(mean(Vi))]); | ||
| -subplot(413) | ||
| -plot(linspace(0,30,3000),Vt(101:3100)); | ||
| -title(['Vt with a mean of :',num2str(mean(Vt))]); | ||
| -subplot(414) | ||
| -plot(linspace(0,30,3000),Vr(101:3100)); | ||
| -title(['Vr with a mean of :',num2str(mean(Vr))]); | ||
| - | ||
| -% Create figure | ||
| -figure(2) | ||
| -clf | ||
| -subplot(211) | ||
| -[AX1, ~, ~] = plotyy(time_events,[mean_SO_data, sem_SO_data],time_events,[mean_ERP_model, sd_ERP_model], BL_data, BL_model); | ||
| -set(AX1(1), Option_Name, Option_Data_ERP); | ||
| -set(AX1(2), Option_Name, Option_Model_ERP); | ||
| -ylabel(AX1(1),'EEG [$\mu$V]'); | ||
| -ylabel(AX1(2),'$V_{e}$ [mV]'); | ||
| -title([num2str(N_Stim), ' Events']) | ||
| -subplot(212) | ||
| -[AX1, ~, ~] = plotyy(time_events,[mean_FSP_data, sem_FSP_data],time_events,[mean_FSP_model, sd_FSP_model], BL_data, BL_model); | ||
| -set(AX1(1), Option_Name, Option_Data_FSP); | ||
| -set(AX1(2), Option_Name, Option_Model_FSP); | ||
| -ylabel(AX1(1),'FSP data [a.u.]'); | ||
| -ylabel(AX1(2),'$FSP model$ [a.u.]'); | ||
| -title([num2str(N_Stim), ' Events']) | ||
| -end |
| @@ -1,167 +0,0 @@ | ||
| -% mex command is given by: | ||
| - | ||
| -function Test_Stimulation(type) | ||
| -if nargin == 0 | ||
| - type = 4; | ||
| -end | ||
| - | ||
| - | ||
| -mex CXXFLAGS="\$CXXFLAGS -std=c++11 -O3" TC_mex.cpp Cortical_Column.cpp Thalamic_Column.cpp | ||
| - | ||
| -% Path to fieltrip preprocessing function | ||
| -if(isempty(strfind(path, '/nfshome/schellen/Documents/MATLAB/Tools/fieldtrip/preproc'))) | ||
| - addpath('~/Documents/MATLAB/Tools/fieldtrip/preproc'); | ||
| -end | ||
| - | ||
| -% Path to helper function | ||
| -if(isempty(strfind(path, '/nfshome/schellen/Documents/MATLAB/Tools/boundedline'))) | ||
| - addpath('~/Documents/MATLAB/Tools/boundedline'); | ||
| -end | ||
| - | ||
| -Param_Cortex = [6; % sigma_e | ||
| - 2.05; % g_KNa | ||
| - 120E-3]; % dphi | ||
| - | ||
| -Param_Thalamus = [0.052; % g_h | ||
| - 0.02]; % g_LK | ||
| - | ||
| -Connectivity = [ 2.6; % N_et | ||
| - 2.6; % N_er | ||
| - 5; % N_te | ||
| - 10]; % N_ti | ||
| - | ||
| -% stimulation parameters | ||
| -% first number is the mode of stimulation | ||
| -% 0 == none | ||
| -% 1 == semi-periodic | ||
| -% 2 == phase dependend | ||
| - | ||
| -var_stim = [ 2; % mode of stimulation | ||
| - 70; % strength of the stimulus in Hz (spikes per second) | ||
| - 80; % 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 | ||
| - 1075; % time between stimuli within a event in ms | ||
| - 450]; % time until stimuli after minimum in ms | ||
| - | ||
| -T = 3600; % duration of the simulation | ||
| - | ||
| -load('/nfshome/schellen/Documents/MATLAB/TC_model/Data/ERP_Average_data'); | ||
| - | ||
| -Model_Range_ERP = [-75, -45]; | ||
| -Data_Range_ERP = [-80, 50]; | ||
| -Model_Range_FSP = [-0.25, 1.25]; | ||
| -Data_Range_FSP = [2, 8]; | ||
| -xRange = -1:0.5:3; | ||
| - | ||
| -% Option array for set | ||
| -Option_Name = { 'ylim'; | ||
| - 'ytick'; | ||
| - 'yticklabel'; | ||
| - 'ycolor'; | ||
| - 'xtick'; | ||
| - 'xlim'}'; | ||
| - | ||
| -Option_Model_ERP = {Model_Range_ERP; | ||
| - -75:10:-40; | ||
| - -75:10:-40; | ||
| - 'black'; | ||
| - xRange; | ||
| - [xRange(1),xRange(end)]}'; %#ok<*NBRAK> | ||
| - | ||
| -Option_Data_ERP = {Data_Range_ERP; | ||
| - -80:40:40; | ||
| - -80:40:40; | ||
| - 'black'; | ||
| - xRange; | ||
| - [xRange(1),xRange(end)]}'; | ||
| - | ||
| -Option_Model_FSP = {Model_Range_FSP; | ||
| - linspace(Model_Range_FSP(1), Model_Range_FSP(2), 4); | ||
| - linspace(Model_Range_FSP(1), Model_Range_FSP(2), 4); | ||
| - 'black'; | ||
| - xRange; | ||
| - [xRange(1),xRange(end)]}'; | ||
| - | ||
| -Option_Data_FSP = {Data_Range_FSP; | ||
| - linspace(Data_Range_FSP(1), Data_Range_FSP(2), 4); | ||
| - linspace(Data_Range_FSP(1), Data_Range_FSP(2), 4); | ||
| - 'black'; | ||
| - xRange; | ||
| - [xRange(1),xRange(end)]}'; | ||
| - | ||
| -[Ve, Vt, Ca, ah, Marker_Stim] = TC_mex(T, Param_Cortex, Param_Thalamus, Connectivity, var_stim); | ||
| -Fs = length(Ve)/T; | ||
| -Ve_FSP = ft_preproc_hilbert(ft_preproc_bandpassfilter(Ve, Fs, [12, 15], 513, 'fir'), 'abs').^2; | ||
| -xRange = [-1, 3]; | ||
| - | ||
| -% Search for peaks | ||
| -x_SO = Marker_Stim; | ||
| - | ||
| -% Remove those events, that are too close to begin/end | ||
| -x_SO = x_SO(x_SO<(T-xRange(end))*Fs); | ||
| -x_SO = x_SO(x_SO> -xRange(1)*Fs); | ||
| - | ||
| -% Set the variables | ||
| -N_Stim = length(x_SO); | ||
| -time_event = linspace(xRange(1), xRange(end), (xRange(end)-xRange(1))*Fs+1); | ||
| -Events = zeros(length(time_event), N_Stim); | ||
| -Events_FSP = zeros(length(time_event), N_Stim); | ||
| - | ||
| -% Segmentation | ||
| -for i=1:N_Stim | ||
| - Events(:,i) = Ve ((x_SO(i)+xRange(1)*Fs):(x_SO(i)+xRange(end)*Fs)); | ||
| - Events_FSP(:,i) = Ve_FSP((x_SO(i)+xRange(1)*Fs):(x_SO(i)+xRange(end)*Fs)); | ||
| -end | ||
| - | ||
| -mean_ERP_model= mean(Events, 2); %#ok<*NASGU> | ||
| -mean_FSP_model= mean(Events_FSP,2); | ||
| -sd_ERP_model = std (Events, 0, 2); | ||
| -sd_FSP_model = std (Events_FSP,0, 2); | ||
| - | ||
| -% Define handle for plotting | ||
| -BL_model =@(y,x) boundedline(y,x(:,1), x(:,2), 'alpha', 'transparency', 0.1, 'r'); | ||
| -BL_data =@(y,x) boundedline(y,x(:,1), x(:,2), 'alpha', 'transparency', 0.1, 'black'); | ||
| - | ||
| -figure(1) | ||
| -subplot(411) | ||
| -plot(linspace(0,30,3000),Ve(101:3100)); | ||
| -title(['Ve with a mean of :',num2str(mean(Ve))]); | ||
| -subplot(412) | ||
| -plot(linspace(0,30,3000),Vt(101:3100)); | ||
| -title(['Vt with a mean of :',num2str(mean(Vt))]); | ||
| -subplot(413) | ||
| -plot(linspace(0,30,3000),Ca(101:3100)); | ||
| -title(['Ca with a mean of :',num2str(mean(Ca))]); | ||
| -subplot(414) | ||
| -plot(linspace(0,30,3000),ah(101:3100)); | ||
| -title(['ah with a mean of :',num2str(mean(ah))]); | ||
| - | ||
| -% Create figure | ||
| -figure(2) | ||
| -clf | ||
| -subplot(211) | ||
| -[AX1, ~, ~] = plotyy(time_events,[mean_ERP, sem_FSP],time_events,[mean_ERP_model, sd_ERP_model], BL_data, BL_model); | ||
| -set(AX1(1),Option_Name, Option_Data_ERP, 'box', 'off'); | ||
| -set(AX1(2),Option_Name, Option_Model_ERP); | ||
| -ylabel(AX1(1),'EEG [$\mu$V]'); | ||
| -ylabel(AX1(2),'V$_{p}$ [mV]'); | ||
| - | ||
| -subplot(212) | ||
| -[AX2, ~, ~] = plotyy(time_events,[mean_FSP, sem_FSP],time_events,[mean_FSP_model, sd_FSP_model], BL_data, BL_model); | ||
| -set(AX2(1),Option_Name, Option_Data_FSP); | ||
| -set(AX2(2),Option_Name, Option_Model_FSP); | ||
| -ylabel(AX2(1),'Spindle Power [$\mu$V$^{2}$]'); | ||
| -ylabel(AX2(2),'Spindle Power [mV$^{2}$]'); | ||
| -title([num2str(N_Stim), ' Events']) | ||
| - | ||
| -% Marker for stimulation | ||
| -for i=1:2 | ||
| - hx1 = graph2d.constantline((i-1)*1.05+0.125*(i-1)*(i-2)/2,'ydata', get(AX1(1),'ylim'), 'parent', AX1(1), 'color', 'black', 'LineStyle', ':'); | ||
| - hx2 = graph2d.constantline((i-1)*1.05+0.125*(i-1)*(i-2)/2,'ydata', get(AX2(1),'ylim'), 'parent', AX2(1), 'color', 'black', 'LineStyle', ':'); | ||
| - changedependvar(hx1,'x'); | ||
| - changedependvar(hx2,'x'); | ||
| -end | ||
| - | ||
| -end |
0 comments on commit
d31e02d