-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathq1_comparisonOfBroadbandMeasures_levels.m
144 lines (107 loc) · 5.58 KB
/
q1_comparisonOfBroadbandMeasures_levels.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
% q1_comparisonOfBroadbandMeasures
%
% Question 1: amplitude vs. power vs log power
% How does the quality of broadband estimate vary using amplitude, power or log power estimates?
% Prediction: Power best quality
% Approach: vary params.method
clear all;
%% Set parameters
params = [];
% SIMULATION parameters
% Set parameters for the noiseless, time-varying rate
params.simulation.resp = 'level'; % response profile: choose from {'boxcar' 'steps' 'step' 'pulse' 'bump' 'square' 'sine' 'noise' 'pred dn'} ([default = step];
params.simulation.t = (-1999.5:1999.5)'; % trial length: trials are -2 to 2 seconds, and later clipped to [0 1] to avoid edge artifacts
params.simulation.srate = 1000; % sample rate (Hz)
params.simulation.opt.f = 10; % temporal frequency of response profile, applicable to sine wave or square wave
params.simulation.opt.level = 1; % average level of response when using just one level
% Set parameters for noisy samples
params.simulation.nn = 100; % number of neurons
params.simulation.ntrials = 12; % number of repeated trials
params.simulation.seed = 0; % use same number to compare simulations for same random generator of samples; leave empty to use new generator every time
% Set parameters for leaky integration
params.simulation.alpha = 0.1; % time constant for dendritic leakage
params.simulation.tau = 0.0023; % time constant for post-synaptic current
% Set parameters for noise
params.simulation.addnoise = 0;%0.01; % additive noise (if 0, no noise is added)
% ANALYSIS parameters
params.analysis.bands = {[40 200], 20}; % {[lower bound, upper bound], window sz}
params.analysis.averagebandswhen = 'after hilbert'; % 'before hilbert'/'after hilbert'
params.analysis.whitenbands = 'no'; % yes/no
% PLOTTING parameters
params.plot.on = 'no'; % suppress plotting of simulations and each individual analysis
params.plot.fontsz = 18; % font size
params.plot.lnwdth = 3; % line width
%% compare different measures for different levels
% DEFINE levels to be tested
inputLevels = ((1:20)/20).^4; % range between 0 and 1
%inputLevels = ((1:20)/16).^4; % range between 0 and 2.44
%inputLevels = log((1:20/20)+2);
powerMeasures = {'amplitude', 'power', 'logpower'};
t = params.simulation.t/params.simulation.srate;
activityLevels = nan(length(t), params.simulation.ntrials, length(inputLevels));
responseLevels = nan(length(inputLevels), length(powerMeasures));
responseLevelsSD = nan(length(inputLevels), length(powerMeasures));
% SIMULATE
for ii = 1:length(inputLevels)
params.simulation.opt.level = inputLevels(ii);
[spikeRate(:,ii), params] = generateNoiselessTimeCourse(params);
[spikeArrivals, params] = generateNoisySampledTimeCourses(spikeRate(:,ii), params);
[simulatedSignal] = generateIntegratedTimeSeries(spikeArrivals, params);
activityLevels(:,:,ii) = simulatedSignal;
end
figure;plot(t,spikeRate, 'LineWidth', 2);
set(gca, 'FontSize', params.plot.fontsz)
xlabel('Time (s)');
ylabel('Spike rate');
title('Input levels');
figure;plot(t,squeeze(mean(activityLevels,2)), 'LineWidth', 2);
set(gca, 'FontSize', params.plot.fontsz)
xlabel('Time (s)');
ylabel('Integrated time series');
title('Simulated signal levels');
% ANALYZE
% Clip time series to avoid edge artifacts
tidx = t > 0 & t < 1;
for jj = 1:length(powerMeasures)
params.analysis.measure = powerMeasures{jj};
switch powerMeasures{jj}
case {'amplitude', 'power'}
params.analysis.averagebandshow = 'geomean';
case 'logpower'
params.analysis.averagebandshow = 'mean';
end
% Get 'calibrated' responses for this powerMeasure
[params] = calibrateResponseLevel(params);
for ii = 1:length(inputLevels)
simulatedSignal = activityLevels(:,:,ii);
% Compute broadband
[estimatedBroadband, params] = extractBroadband(simulatedSignal, params);
% Average extracted broadband across trials
meanBroadband = mean(estimatedBroadband,2);
% Scale broadband to calibrated response using calibrate function
meanBroadbandCalibrated(:,ii) = params.analysis.calibrate(meanBroadband);
responseLevels(ii,jj) = mean(meanBroadbandCalibrated(tidx,ii),1);
responseLevelsSD(ii,jj) = std(meanBroadbandCalibrated(tidx,ii),0,1);
end
figure;plot(t,squeeze(meanBroadbandCalibrated), 'LineWidth', 2);
set(gca, 'FontSize', params.plot.fontsz)
xlabel('Time (s)');
ylabel('Broadband time course (calibrated)');
title(powerMeasures{jj});
end
%% PLOT
fH = figure; set(fH, 'Color', 'w'); hold on;
colors = copper(length(powerMeasures));
colors(1,:) = [1 0 0];
for jj = 1:length(powerMeasures)
plot(inputLevels,responseLevels(:,jj), ...
'LineWidth', 2, 'Marker', '.', 'MarkerSize', 25, 'Color', colors(jj,:))
e = errorbar(inputLevels,responseLevels(:,jj), responseLevelsSD(:,jj), ...
'LineWidth', 2,'LineStyle', 'none', 'Color', colors(jj,:));
e.Annotation.LegendInformation.IconDisplayStyle = 'off';
end
l = legend(powerMeasures, 'Location', 'NorthWest');
set(gca, 'XLim', [-0.1 max(inputLevels)+0.1*max(inputLevels)], 'FontSize', params.plot.fontsz)
xlabel('Input level (spike rate)');
ylabel('Broadband response level');
title('comparison of broadband measures');