Subject | Hash | Author | Date (UTC) |
---|---|---|---|
Fix inconsistent code style in repo (only *.m-files) | 1a87b28a285ad84af1836154f80761430554700c | Jason Hoelscher-Obermaier | 2017-04-12 10:36:03 |
Set default code style using .editorconfig in root of repository | 83719dc571b5a4fce247907ea50fdb5841b5d5f6 | Jason Hoelscher-Obermaier | 2017-04-12 09:18:43 |
Refactor calculatePulsedQuadratures to prepare for increased efficiency... | 7247ee11d4e93ab24f5c38d49e135ac283855f1b | Jason Hoelscher-Obermaier | 2017-04-12 08:44:18 |
Decrease verbosity: suppress output from pdfcrop in meta_ev.m | f51caf728c9e727ea7036d1066ed5638d5f5adef | Jason Hoelscher-Obermaier | 2017-04-12 08:41:23 |
Try to suppress display of figures in meta_ev_test.m (unsuccessful) | c87cedfa3c1e53a8f25ad8c4119704c8bdfe9b2f | Jason Hoelscher-Obermaier | 2017-04-11 09:22:12 |
Add class dual_homo_simulation which emulates a dual_homo_measurement but with simulated traces | 41792061b163af8e7d57738c19382409e0321190 | Jason Hoelscher-Obermaier | 2017-04-10 11:07:24 |
Turn off warning regarding default_sample_no in PXItrace | 0c6322c334c051e08198ba79ca85170ebd5e8e12 | Jason Hoelscher-Obermaier | 2017-04-10 11:04:03 |
Fix num2eng.m: correct display of 0 (w. tolerance of +-eps) and +-inf. | 6345574b61460fec8dd19832056d6273a07f23e9 | Jason Hoelscher-Obermaier | 2017-04-10 10:44:17 |
Extend functionality of method 'plot_cuts' of class 'meta_ev' | af350f1084ba30f3f56f70367b8dd7ea3071f1a9 | Jason Hoelscher-Obermaier | 2017-04-08 16:30:56 |
Bug fix in num2eng.m: Input 0 (or +/- eps) will now yield '0' as expected | 7ab33199240f75e7013223cddf02e69cd83e3272 | Jason Hoelscher-Obermaier | 2017-04-08 16:27:52 |
Refactor meta_ev: move plotting methods to separate files. | 6e5df82a5739d8f1ef7a209822f7a448ced1721c | Jason Hoelscher-Obermaier | 2017-04-08 09:27:21 |
Additional options for method plot_cuts in meta_ev.m | eabae3d9b5b934c5b9d56396374cfdd6c9f5ed3f | Jason Hoelscher-Obermaier | 2017-04-08 08:53:29 |
Add class homotrace_simulated as wrapper around homotrace if simulation-data-streams are to be used... | b09e4d8431e7784d3021ae949edd557291c8d482 | Jason Hoelscher-Obermaier | 2017-04-06 14:56:34 |
Replace unnecessary switch-expression in assert_consistency_of_varargin by isequal-test | 0c946942de73edb17b0d1f7b62748b9c8f0a98d0 | Jason Hoelscher-Obermaier | 2017-04-06 14:27:26 |
Improve default color order for line plots | 336545a7441b6b575ab47ef655377514207cd69b | Jason Hoelscher-Obermaier | 2017-04-07 21:40:27 |
Add method "plot_cuts" to meta_ev... | d92ade078a2b85f08312fe9524d9dc2097c6aff6 | Jason Hoelscher-Obermaier | 2017-04-07 20:57:41 |
Add method filter_params to meta_ev.m | a9b063dc0c5858ba211dafe6c78cbe49bf5063d5 | Jason Hoelscher-Obermaier | 2017-04-07 18:03:54 |
Replace unnecessary switch-expression in assert_consistency_of_varargin by isequal-test | 6cb69108ba70daabd0a01aa61d4f5c9de25cb57a | Jason Hoelscher-Obermaier | 2017-04-06 14:27:26 |
Update submodule matlab-xunit to point to master (after updates to displayStack were merged). | 086e1d0869d17ea2dfffa706717bbbceb981ab72 | Jason Hoelscher-Obermaier | 2017-04-06 08:41:39 |
Bug fix in sentence_case: return empty string if input is empty string | 97a0aea577a1ce963e01957b16cc689d25f2a7a8 | Jason Hoelscher-Obermaier | 2017-04-05 16:22:00 |
File @dac/dac.m changed (mode: 100644) (index 5626ce4..a981b86) | |||
... | ... | classdef dac < Singleton | |
11 | 11 | % configuration | % configuration |
12 | 12 | quiet % no output | quiet % no output |
13 | 13 | prngseed % seed PRNG | prngseed % seed PRNG |
14 | |||
14 | |||
15 | 15 | Ntmax % maximum numer of points to load | Ntmax % maximum numer of points to load |
16 | 16 | Ntsim % maximum numer of points to simulate | Ntsim % maximum numer of points to simulate |
17 | |||
17 | |||
18 | 18 | psdnwin % pwelch window number | psdnwin % pwelch window number |
19 | 19 | psdwinfunc % pwelch window function | psdwinfunc % pwelch window function |
20 | 20 | psdoverlap % pwelch window overlap | psdoverlap % pwelch window overlap |
... | ... | classdef dac < Singleton | |
23 | 23 | refF % reference frequency | refF % reference frequency |
24 | 24 | expFs % sample frequency | expFs % sample frequency |
25 | 25 | Fs % Fs rescaled to refF | Fs % Fs rescaled to refF |
26 | |||
26 | |||
27 | 27 | postprocess % run postprocessing (true/false) | postprocess % run postprocessing (true/false) |
28 | 28 | postp % postprocessing (struct) | postp % postprocessing (struct) |
29 | |||
29 | |||
30 | 30 | user % userinterface | user % userinterface |
31 | 31 | end | end |
32 | 32 | ||
... | ... | classdef dac < Singleton | |
53 | 53 | newObj.refF = []; | newObj.refF = []; |
54 | 54 | newObj.expFs = []; | newObj.expFs = []; |
55 | 55 | newObj.Fs = []; | newObj.Fs = []; |
56 | |||
56 | |||
57 | 57 | % user interface | % user interface |
58 | newObj.user = []; | ||
58 | newObj.user = []; | ||
59 | 59 | end | end |
60 | 60 | end | end |
61 | 61 | ||
... | ... | classdef dac < Singleton | |
141 | 141 | Value = obj.Fs; | Value = obj.Fs; |
142 | 142 | end | end |
143 | 143 | end | end |
144 | |||
144 | |||
145 | 145 | end | end |
146 | 146 | end | end |
File @dadac/filter.m changed (mode: 100644) (index 4c7909c..f64a77e) | |||
... | ... | function dsout = filter(ds,varargin) | |
2 | 2 | % dsout = filter(ds) | % dsout = filter(ds) |
3 | 3 | % | % |
4 | 4 | % Filters time data (dadac object) with specified bandwidth and filter | % Filters time data (dadac object) with specified bandwidth and filter |
5 | % order. Uses internal function 'filter', but with different arguments. | ||
5 | % order. Uses internal function 'filter', but with different arguments. | ||
6 | 6 | % arguments: | % arguments: |
7 | 7 | % - ds: time data (dadac object) | % - ds: time data (dadac object) |
8 | 8 | % optional arguments: | % optional arguments: |
... | ... | forder=512; | |
22 | 22 | ||
23 | 23 | % parse varargs | % parse varargs |
24 | 24 | for ii=1:2:nargs | for ii=1:2:nargs |
25 | switch args{ii} | ||
26 | case 'fresponse', fresponse = args{ii+1}; | ||
27 | case 'frange', frange = args{ii+1}; | ||
28 | case 'forder', forder = args{ii+1}; | ||
25 | switch args{ii} | ||
26 | case 'fresponse', fresponse = args{ii+1}; | ||
27 | case 'frange', frange = args{ii+1}; | ||
28 | case 'forder', forder = args{ii+1}; | ||
29 | 29 | otherwise, warning(['unrecognized argument ' args{ii}]) | otherwise, warning(['unrecognized argument ' args{ii}]) |
30 | 30 | end | end |
31 | 31 | end | end |
... | ... | dsout = dadac(numel(ds),'type','fr'); | |
53 | 53 | ||
54 | 54 | % calculate spectrum for each entry in ds | % calculate spectrum for each entry in ds |
55 | 55 | for ii = 1:numel(ds) | for ii = 1:numel(ds) |
56 | |||
57 | % calculate filter for each row | ||
56 | |||
57 | % calculate filter for each row | ||
58 | 58 | for jj = 1:size(ds(ii).yData,2) | for jj = 1:size(ds(ii).yData,2) |
59 | 59 | tf = filter(b,1,ds(ii).yData(:,jj)); | tf = filter(b,1,ds(ii).yData(:,jj)); |
60 | 60 | dsout(ii).yData(:,jj) = tf(:); | dsout(ii).yData(:,jj) = tf(:); |
61 | 61 | end | end |
62 | |||
62 | |||
63 | 63 | % copy other properties | % copy other properties |
64 | 64 | dsout(ii).id = ds(ii).id; | dsout(ii).id = ds(ii).id; |
65 | 65 | dsout(ii).label = ds(ii).label; | dsout(ii).label = ds(ii).label; |
File @dadac/plot.m changed (mode: 100644) (index 133b59b..9710634) | |||
... | ... | function varargout = plot(ds,varargin) | |
6 | 6 | ||
7 | 7 | for ii = 1:numel(ds) | for ii = 1:numel(ds) |
8 | 8 | ph = figure(); | ph = figure(); |
9 | |||
9 | |||
10 | 10 | xvec = ds(ii).xData; | xvec = ds(ii).xData; |
11 | 11 | if isempty(xvec) | if isempty(xvec) |
12 | 12 | tempPh = plot(ds(ii).yData,varargin{:}); | tempPh = plot(ds(ii).yData,varargin{:}); |
File @dadac/postprocess.m changed (mode: 100644) (index 2da57f2..e24a144) | |||
... | ... | end | |
50 | 50 | % $$$ if ~strcmp(pps.method,'none') | % $$$ if ~strcmp(pps.method,'none') |
51 | 51 | if ~isempty(pps) | if ~isempty(pps) |
52 | 52 | Hd = design(pps.fdesign,pps.method); | Hd = design(pps.fdesign,pps.method); |
53 | %Hd = pps.hd; | ||
53 | %Hd = pps.hd; | ||
54 | 54 | for jj = part | for jj = part |
55 | if ~ds(jj).postpd | ||
55 | if ~ds(jj).postpd | ||
56 | 56 | for ii = 1:size(ds(jj).yData,2) | for ii = 1:size(ds(jj).yData,2) |
57 | 57 | ds(jj).yData(:,ii)=filter(Hd,ds(jj).yData(:,ii)); | ds(jj).yData(:,ii)=filter(Hd,ds(jj).yData(:,ii)); |
58 | 58 | ds(jj).postpd = true; | ds(jj).postpd = true; |
... | ... | else | |
75 | 75 | pps.fdesign.Fpass2=Fpass2Scaled; | pps.fdesign.Fpass2=Fpass2Scaled; |
76 | 76 | end | end |
77 | 77 | pps.fdesign.Fs=FsScaled; | pps.fdesign.Fs=FsScaled; |
78 |
File @dadac/pwelch.m changed (mode: 100644) (index d3cebfa..f463ff4) | |||
... | ... | for ii = 1:numel(ds) | |
42 | 42 | win = PWELCH_WIN_FUNCTION(winlen); | win = PWELCH_WIN_FUNCTION(winlen); |
43 | 43 | ||
44 | 44 | % calculate psd for each row | % calculate psd for each row |
45 | fr = []; | ||
45 | fr = []; | ||
46 | 46 | for jj = 1:size(ds(ii).yData,2) | for jj = 1:size(ds(ii).yData,2) |
47 | 47 | [power,fr] = pwelch(ds(ii).yData(:,jj),win,PWELCH_NOVERLAP,[],dao.expFs,PWELCH_RANGE); | [power,fr] = pwelch(ds(ii).yData(:,jj),win,PWELCH_NOVERLAP,[],dao.expFs,PWELCH_RANGE); |
48 | 48 | dsout(ii).yData(:,jj) = power(:); | dsout(ii).yData(:,jj) = power(:); |
File @dadac/pwelchplot.m changed (mode: 100644) (index 3b7ad41..325d96e) | |||
1 | 1 | function pwelchplot(frdata) | function pwelchplot(frdata) |
2 | 2 | % pwelchplot(frdata) | % pwelchplot(frdata) |
3 | % | ||
3 | % | ||
4 | 4 | % Plots PSD. This is a helper for ess/pwelch and dadac/pwelch and is | % Plots PSD. This is a helper for ess/pwelch and dadac/pwelch and is |
5 | 5 | % not supposed to be called directly! | % not supposed to be called directly! |
6 | 6 | % | % |
File @daddc/daddc.m changed (mode: 100644) (index debcb09..c4a0ac8) | |||
... | ... | classdef daddc | |
103 | 103 | obj.basedir = Value; | obj.basedir = Value; |
104 | 104 | end | end |
105 | 105 | end | end |
106 | |||
106 | |||
107 | 107 | function obj = set.config(obj,Value) | function obj = set.config(obj,Value) |
108 | 108 | if isempty(Value) | if isempty(Value) |
109 | 109 | obj.config = ''; | obj.config = ''; |
... | ... | classdef daddc | |
121 | 121 | % $$$ % create directory and add it to datadir | % $$$ % create directory and add it to datadir |
122 | 122 | % $$$ function obj = makeDatadir(obj,varargin) | % $$$ function obj = makeDatadir(obj,varargin) |
123 | 123 | % $$$ args = varargs2cell(varargin); | % $$$ args = varargs2cell(varargin); |
124 | % $$$ if | ||
125 | % $$$ | ||
124 | % $$$ if | ||
125 | % $$$ | ||
126 | 126 | % $$$ end | % $$$ end |
127 | 127 | % $$$ end | % $$$ end |
128 | 128 |
File @daddc/loadconfig.m changed (mode: 100644) (index 008f4b5..3694d55) | |||
... | ... | function varargout = loadconfig(ddir,varargin) | |
4 | 4 | % | % |
5 | 5 | % Call configuration function in ddir.basedir and pass arguments. If | % Call configuration function in ddir.basedir and pass arguments. If |
6 | 6 | % second argument is 'help' print help text of configuration function. | % second argument is 'help' print help text of configuration function. |
7 | % | ||
7 | % | ||
8 | 8 | % Note: Only use FULL filenames for this to work correctly! | % Note: Only use FULL filenames for this to work correctly! |
9 | 9 | ||
10 | 10 | varargout = cell(1,max(1,nargout)); % always return result | varargout = cell(1,max(1,nargout)); % always return result |
... | ... | end | |
30 | 30 | clear(funcString); | clear(funcString); |
31 | 31 | ||
32 | 32 | % to fix: | % to fix: |
33 | % problems with 'dirNotInPath' check: search order in variable 'path' | ||
33 | % problems with 'dirNotInPath' check: search order in variable 'path' | ||
34 | 34 | % yields problems for finding correct parameter file | % yields problems for finding correct parameter file |
35 | 35 | ||
36 | 36 | % add basedir to path if needed | % add basedir to path if needed |
... | ... | if ischar(varargin{1}) | |
49 | 49 | elseif isstruct(varargin{1}) || isempty(varargin{1}) | elseif isstruct(varargin{1}) || isempty(varargin{1}) |
50 | 50 | % load parameters | % load parameters |
51 | 51 | argsStruct = varargs2struct(varargin); | argsStruct = varargs2struct(varargin); |
52 | [varargout{:}] = confFunc(argsStruct); | ||
52 | [varargout{:}] = confFunc(argsStruct); | ||
53 | 53 | end | end |
54 | 54 | % comment see above | % comment see above |
55 | 55 | % only remove basedir from path if we added it before | % only remove basedir from path if we added it before |
File @ess/append.m changed (mode: 100644) (index d425f80..6b5cb14) | |||
... | ... | function ssa=append(varargin) | |
3 | 3 | % | % |
4 | 4 | % Concatenate models sys1,sys2,... to form one model, without | % Concatenate models sys1,sys2,... to form one model, without |
5 | 5 | % making a connection between the different models. | % making a connection between the different models. |
6 | |||
6 | |||
7 | 7 | sss = cell(1,length(nargin)); | sss = cell(1,length(nargin)); |
8 | 8 | ssl = {}; ssr = {}; ssq = {}; ssm = {}; | ssl = {}; ssr = {}; ssq = {}; ssm = {}; |
9 | 9 | nvar = 0; nnvar = 0; jj = 1; | nvar = 0; nnvar = 0; jj = 1; |
10 | |||
10 | |||
11 | 11 | for ii = 1:nargin | for ii = 1:nargin |
12 | 12 | % dynamics | % dynamics |
13 | 13 | sss{ii} = ss(varargin{ii}); | sss{ii} = ss(varargin{ii}); |
... | ... | function ssa=append(varargin) | |
43 | 43 | % incorrect. | % incorrect. |
44 | 44 | ssr{ii} = rnotempty(varargin{ii}); | ssr{ii} = rnotempty(varargin{ii}); |
45 | 45 | end | end |
46 | |||
46 | |||
47 | 47 | % append deterministic (ss) part | % append deterministic (ss) part |
48 | 48 | ssa = ess(append(sss{:})); | ssa = ess(append(sss{:})); |
49 | 49 |
File @ess/c2d.m changed (mode: 100644) (index e52350c..9a5d660) | |||
... | ... | if sys_c.Ts == 0 | |
37 | 37 | sys_d.c = H; sys_d.d = D; | sys_d.c = H; sys_d.d = D; |
38 | 38 | sys_d.q = Q; sys_d.r = R; sys_d.m = M; | sys_d.q = Q; sys_d.r = R; sys_d.m = M; |
39 | 39 | sys_d.Ts = Ts; | sys_d.Ts = Ts; |
40 | |||
40 | |||
41 | 41 | case {'zoh','foh','impulse','tustin'} % 'matched' is broken | case {'zoh','foh','impulse','tustin'} % 'matched' is broken |
42 | 42 | % convert ss part | % convert ss part |
43 | 43 | % prescaling might be applied by ss/c2d | % prescaling might be applied by ss/c2d |
File @ess/compactify.m changed (mode: 100644) (index e4c88ef..b8d2b32) | |||
... | ... | switch method | |
65 | 65 | % delete InputGroup and OutputGroup | % delete InputGroup and OutputGroup |
66 | 66 | sys.InputGroup = struct(); | sys.InputGroup = struct(); |
67 | 67 | sys.OutputGroup = struct(); | sys.OutputGroup = struct(); |
68 | |||
68 | |||
69 | 69 | % create new model and copy meta-properties | % create new model and copy meta-properties |
70 | 70 | if sys.isnoisy() | if sys.isnoisy() |
71 | 71 | nrm=intersect(intersect(hhor,dhor),nhor); | nrm=intersect(intersect(hhor,dhor),nhor); |
File @ess/display.m changed (mode: 100644) (index a0669fb..452a575) | |||
1 | 1 | function display(sys) | function display(sys) |
2 | 2 | %DISPLAY Pretty-print for ess models. | %DISPLAY Pretty-print for ess models. |
3 | 3 | ||
4 | |||
4 | |||
5 | 5 | %% Code adapted from @ss/display.m | %% Code adapted from @ss/display.m |
6 | 6 | ||
7 | 7 | % Extract state-space data and sampling/delay times | % Extract state-space data and sampling/delay times |
... | ... | end | |
101 | 101 | %% print l matrix | %% print l matrix |
102 | 102 | function displm(sys,LeftMargin) | function displm(sys,LeftMargin) |
103 | 103 | % this has to be changed if ss gets qlabel property | % this has to be changed if ss gets qlabel property |
104 | wlabels = ''; | ||
104 | wlabels = ''; | ||
105 | 105 | xlabels = sys.StateName; | xlabels = sys.StateName; |
106 | 106 | [nx,nq] = size(sys.l); | [nx,nq] = size(sys.l); |
107 | 107 | ||
... | ... | function displm(sys,LeftMargin) | |
114 | 114 | if isempty(xlabels{i}), xlabels{i} = '?'; end | if isempty(xlabels{i}), xlabels{i} = '?'; end |
115 | 115 | end | end |
116 | 116 | end | end |
117 | |||
117 | |||
118 | 118 | if isempty(wlabels) || isequal('',wlabels{:}), | if isempty(wlabels) || isequal('',wlabels{:}), |
119 | 119 | for i=1:nq, | for i=1:nq, |
120 | 120 | wlabels{i} = sprintf('w%d',i); | wlabels{i} = sprintf('w%d',i); |
121 | 121 | end | end |
122 | 122 | else | else |
123 | for i=1:nq, | ||
123 | for i=1:nq, | ||
124 | 124 | if isempty(wlabels{i}), wlabels{i} = '?'; end | if isempty(wlabels{i}), wlabels{i} = '?'; end |
125 | 125 | end | end |
126 | 126 | end | end |
File @ess/ess.m changed (mode: 100644) (index fc6df34..631f40a) | |||
... | ... | classdef ess < ss | |
12 | 12 | % | % |
13 | 13 | % This class extends ss. See 'help ss' for a list of additional | % This class extends ss. See 'help ss' for a list of additional |
14 | 14 | % arguments. | % arguments. |
15 | |||
15 | |||
16 | 16 | % adapt number of meta-properties in getMetaProperties if | % adapt number of meta-properties in getMetaProperties if |
17 | 17 | % datastructure is changed! | % datastructure is changed! |
18 | 18 | properties | properties |
... | ... | classdef ess < ss | |
26 | 26 | isnoisy % system has noisy input | isnoisy % system has noisy input |
27 | 27 | % (boolean) | % (boolean) |
28 | 28 | end | end |
29 | |||
29 | |||
30 | 30 | ||
31 | 31 | methods | methods |
32 | |||
32 | |||
33 | 33 | %%% constructor | %%% constructor |
34 | 34 | function obj = ess(varargin) | function obj = ess(varargin) |
35 | 35 | % parse arguments | % parse arguments |
... | ... | classdef ess < ss | |
37 | 37 | essvarlen = 8; | essvarlen = 8; |
38 | 38 | addvarlen = essvarlen-ssvarlen; | addvarlen = essvarlen-ssvarlen; |
39 | 39 | newArgs = cell(1,addvarlen); superArgs = {}; | newArgs = cell(1,addvarlen); superArgs = {}; |
40 | |||
40 | |||
41 | 41 | % copy from ss object | % copy from ss object |
42 | 42 | if nargin>0 && isa(varargin{1},'StateSpaceModel') || isa(varargin{1},'tf') | if nargin>0 && isa(varargin{1},'StateSpaceModel') || isa(varargin{1},'tf') |
43 | 43 | % create empty ss object and call copy constructor | % create empty ss object and call copy constructor |
... | ... | classdef ess < ss | |
52 | 52 | % already ess model | % already ess model |
53 | 53 | S = varargin{1}; | S = varargin{1}; |
54 | 54 | end | end |
55 | |||
55 | |||
56 | 56 | superArgs{1} = []; | superArgs{1} = []; |
57 | 57 | [copyNames,copyArgs] = getProperties(S); | [copyNames,copyArgs] = getProperties(S); |
58 | |||
58 | |||
59 | 59 | % fields not set in ss object | % fields not set in ss object |
60 | 60 | if nargin > 1 | if nargin > 1 |
61 | 61 | newArgs(1:nargin-1) = varargin(2:nargin); | newArgs(1:nargin-1) = varargin(2:nargin); |
... | ... | classdef ess < ss | |
86 | 86 | newArgs = varargin(ssvarlen+1:essvarlen); | newArgs = varargin(ssvarlen+1:essvarlen); |
87 | 87 | end | end |
88 | 88 | end | end |
89 | |||
89 | |||
90 | 90 | % call superclass constructor | % call superclass constructor |
91 | 91 | obj = obj@ss(superArgs{:}); | obj = obj@ss(superArgs{:}); |
92 | |||
92 | |||
93 | 93 | % copy properties | % copy properties |
94 | 94 | clen = length(copyArgs); | clen = length(copyArgs); |
95 | 95 | if clen > 0 | if clen > 0 |
... | ... | classdef ess < ss | |
97 | 97 | obj.(copyNames{ii}) = copyArgs{ii}; | obj.(copyNames{ii}) = copyArgs{ii}; |
98 | 98 | end | end |
99 | 99 | end | end |
100 | |||
100 | |||
101 | 101 | % set new fields | % set new fields |
102 | 102 | if length(newArgs) > 0 | if length(newArgs) > 0 |
103 | 103 | [obj.l,obj.q,obj.r,obj.m] = newArgs{:}; | [obj.l,obj.q,obj.r,obj.m] = newArgs{:}; |
... | ... | classdef ess < ss | |
111 | 111 | if ~h | if ~h |
112 | 112 | error('Model dimensions are not valid!') | error('Model dimensions are not valid!') |
113 | 113 | end | end |
114 | |||
114 | |||
115 | 115 | end | end |
116 | |||
116 | |||
117 | 117 | function nobj = cleanNoise(obj) | function nobj = cleanNoise(obj) |
118 | 118 | % empty all noise matrices if noiseTest fails | % empty all noise matrices if noiseTest fails |
119 | 119 | nobj = obj; | nobj = obj; |
... | ... | classdef ess < ss | |
121 | 121 | nobj.l = []; nobj.q = []; nobj.r = []; nobj.m = []; | nobj.l = []; nobj.q = []; nobj.r = []; nobj.m = []; |
122 | 122 | end | end |
123 | 123 | end | end |
124 | |||
125 | %% meta-properties | ||
124 | |||
125 | %% meta-properties | ||
126 | 126 | % extract object meta-properties = all except matrices | % extract object meta-properties = all except matrices |
127 | 127 | % adapt number of meta-properties if datastructure is changed! | % adapt number of meta-properties if datastructure is changed! |
128 | 128 | function props = getMetaProperties(ssObj) | function props = getMetaProperties(ssObj) |
... | ... | classdef ess < ss | |
142 | 142 | ssObjout.(names{ii}) = props.(names{ii}); | ssObjout.(names{ii}) = props.(names{ii}); |
143 | 143 | end | end |
144 | 144 | end | end |
145 | |||
146 | |||
145 | |||
146 | |||
147 | 147 | %% set: these toggle isnoisy if required | %% set: these toggle isnoisy if required |
148 | 148 | function obj = set.q(obj,Value) | function obj = set.q(obj,Value) |
149 | 149 | tmpq = obj.q; | tmpq = obj.q; |
... | ... | classdef ess < ss | |
183 | 183 | S.ess = localEssData(obj); % extra ess matrices (l,q,r,m) | S.ess = localEssData(obj); % extra ess matrices (l,q,r,m) |
184 | 184 | S.prop = getMetaProperties(obj); % meta properties | S.prop = getMetaProperties(obj); % meta properties |
185 | 185 | end | end |
186 | |||
186 | |||
187 | 187 | end | end |
188 | |||
188 | |||
189 | 189 | methods (Static) | methods (Static) |
190 | 190 | % extend ss saveobj | % extend ss saveobj |
191 | 191 | function obj = loadobj(S) | function obj = loadobj(S) |
... | ... | function c = extraEssProperties(obj) | |
251 | 251 | % takes ess obj as input | % takes ess obj as input |
252 | 252 | sp = properties('ss'); ep = properties(obj); | sp = properties('ss'); ep = properties(obj); |
253 | 253 | % note order of input: ep must be before!! | % note order of input: ep must be before!! |
254 | % 'stable' is needed such that original order | ||
254 | % 'stable' is needed such that original order | ||
255 | 255 | % of arguments is preserved for the ess constructor | % of arguments is preserved for the ess constructor |
256 | c = setdiff(ep,sp,'stable'); | ||
256 | c = setdiff(ep,sp,'stable'); | ||
257 | 257 | end | end |
258 | 258 | ||
259 | 259 | % local essdata | % local essdata |
File @ess/initial.m changed (mode: 100644) (index 6d3d125..9a72643) | |||
... | ... | if isempty(xinit) | |
31 | 31 | xinit = zeros(size(sys.a,1),1); | xinit = zeros(size(sys.a,1),1); |
32 | 32 | end | end |
33 | 33 | ||
34 | varargout = cell(1,nargout); | ||
34 | varargout = cell(1,nargout); | ||
35 | 35 | ||
36 | 36 | % create trajectory | % create trajectory |
37 | 37 | if sys.isnoisy() | if sys.isnoisy() |
File @ess/isphysmeas.m changed (mode: 100644) (index 0e18116..e44ff41) | |||
1 | 1 | function bool = isphysmeas(sys,varargin) | function bool = isphysmeas(sys,varargin) |
2 | 2 | % bool = isphysmeas(sys,...) | % bool = isphysmeas(sys,...) |
3 | % | ||
3 | % | ||
4 | 4 | % optional arguments: | % optional arguments: |
5 | 5 | % - 'eigs': show eigenvalues true/false | % - 'eigs': show eigenvalues true/false |
6 | 6 | % - 'statevars': select relevant state variables (integer range) | % - 'statevars': select relevant state variables (integer range) |
... | ... | mat = L*(Q-M*inv(R)*M')*L'-(symm*C'*inv(R)*C*symm')/4; | |
31 | 31 | bool = (num==0); | bool = (num==0); |
32 | 32 | ||
33 | 33 | if showeigs | if showeigs |
34 | fprintf('eigenvalues:\n') | ||
35 | eig(mat) | ||
34 | fprintf('eigenvalues:\n') | ||
35 | eig(mat) | ||
36 | 36 | end | end |
File @ess/kalman.m changed (mode: 100644) (index b5382d0..cb5bbc0) | |||
... | ... | Q = sys.q; R = sys.r; M = sys.m; | |
17 | 17 | % help ess/ss says: | % help ess/ss says: |
18 | 18 | % 'augmented' is equivalent to SS(A,[B,L,0],C,[D,0,1]) | % 'augmented' is equivalent to SS(A,[B,L,0],C,[D,0,1]) |
19 | 19 | asys = ss(sys,'augmented'); | asys = ss(sys,'augmented'); |
20 | |||
20 | |||
21 | 21 | [kest,L,P,varargout{:}] = kalman(asys(:,{'KnownInput','ProcessNoise'}),Q,R,M,varargin{:}); | [kest,L,P,varargout{:}] = kalman(asys(:,{'KnownInput','ProcessNoise'}),Q,R,M,varargin{:}); |
File @ess/kfss.m changed (mode: 100644) (index fe6cb05..3f43b73) | |||
... | ... | function [ksys,kss,pss,psu] = kfss(sys) | |
8 | 8 | % | % |
9 | 9 | % The discrete Kalman filter is given by | % The discrete Kalman filter is given by |
10 | 10 | % x[n|n] = (1-K)F x[n-1|n-1] + K z[n] + B u[n], | % x[n|n] = (1-K)F x[n-1|n-1] + K z[n] + B u[n], |
11 | % z[n|n] = C x[n|n] + D u[n], | ||
11 | % z[n|n] = C x[n|n] + D u[n], | ||
12 | 12 | % where x[n|n] is the a posterior state. | % where x[n|n] is the a posterior state. |
13 | 13 | % | % |
14 | 14 | % The prior and posterior estimation error covariance matrices are | % The prior and posterior estimation error covariance matrices are |
... | ... | else | |
55 | 55 | % ss gain equations see Simon p. 194, Heijden p.271 | % ss gain equations see Simon p. 194, Heijden p.271 |
56 | 56 | id = eye(sn); | id = eye(sn); |
57 | 57 | kss = (pss*H'+M)/(H*pss*H'+R+H*M+(H*M)');% kalman gain | kss = (pss*H'+M)/(H*pss*H'+R+H*M+(H*M)');% kalman gain |
58 | |||
58 | |||
59 | 59 | % a posteriori state x[n|n] | % a posteriori state x[n|n] |
60 | 60 | A = (F-kss*H*F); % filter dynamics | A = (F-kss*H*F); % filter dynamics |
61 | 61 |
File @ess/lsim.m changed (mode: 100644) (index b01d5ee..e97e27d) | |||
... | ... | function varargout = lsim(sys,varargin) | |
8 | 8 | % observation-noise used to simulate the response. Note that the input | % observation-noise used to simulate the response. Note that the input |
9 | 9 | % U now has modified dimensions! If this is not desired, use | % U now has modified dimensions! If this is not desired, use |
10 | 10 | % lsim(ss(sys),...) instead. | % lsim(ss(sys),...) instead. |
11 | % | ||
11 | % | ||
12 | 12 | % Wrapper function: See also SS/LSIM. | % Wrapper function: See also SS/LSIM. |
13 | 13 | ||
14 | 14 | % reference varargin in struct (no copies are created!) | % reference varargin in struct (no copies are created!) |
... | ... | else | |
29 | 29 | uaugmented = [argS.u,zeros(length(argS.t),sn+on)]; | uaugmented = [argS.u,zeros(length(argS.t),sn+on)]; |
30 | 30 | end | end |
31 | 31 | ||
32 | varargout = cell(1,nargout); | ||
32 | varargout = cell(1,nargout); | ||
33 | 33 | ||
34 | 34 | % check if system is noisy, if not call ss/lsim on unmodified system | % check if system is noisy, if not call ss/lsim on unmodified system |
35 | if sys.isnoisy() | ||
35 | if sys.isnoisy() | ||
36 | 36 | % generate and concatenate noise to deterministic input | % generate and concatenate noise to deterministic input |
37 | 37 | % [argS.u,statenoise,obsnoise] | % [argS.u,statenoise,obsnoise] |
38 | 38 | uaugmented(:,un+1:end) = gennoise(sys,argS.t,'combinednoise','true'); | uaugmented(:,un+1:end) = gennoise(sys,argS.t,'combinednoise','true'); |
File @ess/parallel.m changed (mode: 100644) (index 921f2b1..2903dd5) | |||
1 | 1 | function sys_cc = parallel(varargin) | function sys_cc = parallel(varargin) |
2 | 2 | % sys=parallel(sys1,sys2,...) | % sys=parallel(sys1,sys2,...) |
3 | 3 | % | % |
4 | % Connect sys1, sys2, ... in parallel, i.e. inputs of sys1 and sys2 | ||
4 | % Connect sys1, sys2, ... in parallel, i.e. inputs of sys1 and sys2 | ||
5 | 5 | % get the same determinsitic input u, outputs of sys1 and sys 2 are | % get the same determinsitic input u, outputs of sys1 and sys 2 are |
6 | 6 | % directly summed. | % directly summed. |
7 | 7 | % | % |
... | ... | function sys_cc = parallel(varargin) | |
24 | 24 | % connect systems | % connect systems |
25 | 25 | sys_cc=varargin{1}; | sys_cc=varargin{1}; |
26 | 26 | if nargin == 2 | if nargin == 2 |
27 | sys_cc=tparallel(sys_cc,varargin{2}); | ||
27 | sys_cc=tparallel(sys_cc,varargin{2}); | ||
28 | 28 | else | else |
29 | 29 | error('Parallel connection of more than two models is currently not supported') | error('Parallel connection of more than two models is currently not supported') |
30 | 30 | end | end |
... | ... | ec = @(x) cellfun(@(x)'',x,'UniformOutput',false); % return cell array {'',...} | |
53 | 53 | sys_c.q = blkdiag(sys1.q,sys2.q); | sys_c.q = blkdiag(sys1.q,sys2.q); |
54 | 54 | sys_c.r = sys1.r+sys2.r; | sys_c.r = sys1.r+sys2.r; |
55 | 55 | sys_c.m = [sys1.m;sys2.m]; | sys_c.m = [sys1.m;sys2.m]; |
56 | |||
56 | |||
57 | 57 | elseif sys1.isnoisy() | elseif sys1.isnoisy() |
58 | 58 | sys_c.l = blkdiag(sys1.l,zeros(size(sys2.a,1),1)); | sys_c.l = blkdiag(sys1.l,zeros(size(sys2.a,1),1)); |
59 | 59 | sys_c.q = blkdiag(sys1.q,zeros(1,1)); | sys_c.q = blkdiag(sys1.q,zeros(1,1)); |
60 | 60 | sys_c.r = sys1.r; | sys_c.r = sys1.r; |
61 | 61 | sys_c.m = [sys1.m;zeros(1,size(sys2.c,1))]; | sys_c.m = [sys1.m;zeros(1,size(sys2.c,1))]; |
62 | |||
62 | |||
63 | 63 | elseif sys2.isnoisy() | elseif sys2.isnoisy() |
64 | 64 | sys_c.l = blkdiag(zeros(size(sys1.a,1),1),sys2.l); | sys_c.l = blkdiag(zeros(size(sys1.a,1),1),sys2.l); |
65 | 65 | sys_c.q = blkdiag(zeros(1,1),sys2.q); | sys_c.q = blkdiag(zeros(1,1),sys2.q); |
File @ess/prescale.m changed (mode: 100644) (index a3a2b84..f09684c) | |||
1 | 1 | function varargout = prescale(sys,varargin) | function varargout = prescale(sys,varargin) |
2 | 2 | % Wrapper for prescale for ess objects. | % Wrapper for prescale for ess objects. |
3 | % | ||
3 | % | ||
4 | 4 | % Converts ss to ess objects before passing all arguments to | % Converts ss to ess objects before passing all arguments to |
5 | 5 | % ss/prescale. Specifically, the noise input (l) is appended to the | % ss/prescale. Specifically, the noise input (l) is appended to the |
6 | 6 | % deterministic input (b). If this is not desired, use | % deterministic input (b). If this is not desired, use |
File @ess/selectIO.m changed (mode: 100644) (index 16eeb02..ace13f3) | |||
1 | 1 | function [ssys,opos] = selectIO(sys,varargin) | function [ssys,opos] = selectIO(sys,varargin) |
2 | 2 | % ssys = selectIO(sys,...) | % ssys = selectIO(sys,...) |
3 | % | ||
3 | % | ||
4 | 4 | % Select input/output channels from sys. Syntax as for ss models. | % Select input/output channels from sys. Syntax as for ss models. |
5 | 5 | % See also: SS | % See also: SS |
6 | |||
6 | |||
7 | 7 | is = size(sys.b,2); % input number | is = size(sys.b,2); % input number |
8 | 8 | os = size(sys.c,1); % output number | os = size(sys.c,1); % output number |
9 | 9 | ||
... | ... | function [ssys,opos] = selectIO(sys,varargin) | |
19 | 19 | else | else |
20 | 20 | error('too many arguments') | error('too many arguments') |
21 | 21 | end | end |
22 | |||
22 | |||
23 | 23 | % if arguments are empty, use all channels | % if arguments are empty, use all channels |
24 | 24 | if isempty(partO), partO = 1:os; end | if isempty(partO), partO = 1:os; end |
25 | 25 | if isempty(partI), partI = 1:is; end | if isempty(partI), partI = 1:is; end |
... | ... | function [ssys,opos] = selectIO(sys,varargin) | |
29 | 29 | ssys = ss(sys); ssys = ssys(partO,partI); | ssys = ss(sys); ssys = ssys(partO,partI); |
30 | 30 | % modify R and M to match new output | % modify R and M to match new output |
31 | 31 | % input need not be modified | % input need not be modified |
32 | opos = findPosition('output',partO); | ||
32 | opos = findPosition('output',partO); | ||
33 | 33 | ssys = ess(ssys,sys.l,sys.q,sys.r(opos,opos),sys.m(:,opos)); | ssys = ess(ssys,sys.l,sys.q,sys.r(opos,opos),sys.m(:,opos)); |
34 | |||
34 | |||
35 | 35 | %% private | %% private |
36 | 36 | ||
37 | 37 | function pos = findPosition(searchWhere,searchExp) | function pos = findPosition(searchWhere,searchExp) |
File @ess/sscov.m changed (mode: 100644) (index 9ab4733..2fc9017) | |||
... | ... | end | |
12 | 12 | cov = lyap(sys.a,sys.l*sys.q*sys.l'); | cov = lyap(sys.a,sys.l*sys.q*sys.l'); |
13 | 13 | ||
14 | 14 | end | end |
15 |
File PXItraces/@PXItrace/PXI_running_variance.m changed (mode: 100644) (index c998b31..b5a5ac1) | |||
1 | 1 | %% PXI_running_variance: takes a PXI trace and calculates its variance | %% PXI_running_variance: takes a PXI trace and calculates its variance |
2 | 2 | function [vvar, mmean] = PXI_running_variance(PXItrace) | function [vvar, mmean] = PXI_running_variance(PXItrace) |
3 | sample_no = PXItrace.sample_no; | ||
4 | samples_per_run = 1E7; | ||
5 | runs = floor(sample_no/samples_per_run); | ||
3 | sample_no = PXItrace.sample_no; | ||
4 | samples_per_run = 1E7; | ||
5 | runs = floor(sample_no/samples_per_run); | ||
6 | 6 | ||
7 | PXItrace.fopen() | ||
8 | c = onCleanup(@()PXItrace.fclose()); | ||
9 | tic; | ||
10 | for k=1:runs | ||
11 | dat = PXItrace.fread(samples_per_run); | ||
12 | if k==1 | ||
13 | vvar = var(dat); | ||
14 | mmean = mean(dat); | ||
15 | else | ||
16 | mmean2 = mean(dat); | ||
17 | vvar2 = var(dat); | ||
7 | PXItrace.fopen() | ||
8 | c = onCleanup(@()PXItrace.fclose()); | ||
9 | tic; | ||
10 | for k=1:runs | ||
11 | dat = PXItrace.fread(samples_per_run); | ||
12 | if k==1 | ||
13 | vvar = var(dat); | ||
14 | mmean = mean(dat); | ||
15 | else | ||
16 | mmean2 = mean(dat); | ||
17 | vvar2 = var(dat); | ||
18 | 18 | ||
19 | vvar = varupdate(... | ||
20 | mmean,vvar,k*samples_per_run,... | ||
21 | mmean2,vvar2,samples_per_run); | ||
22 | mmean = meanupdate(... | ||
23 | mmean,k*samples_per_run,... | ||
24 | mmean2,samples_per_run); | ||
25 | end | ||
26 | if k==5 | ||
27 | t = toc; | ||
28 | exp_dur = t*runs/5; | ||
29 | disp(['Expected duration: ', num2str(round(exp_dur)), ' seconds']) | ||
30 | disp(['Expected duration: ', num2str(round(exp_dur/60)), ' minutes']) | ||
31 | end | ||
32 | end | ||
19 | vvar = varupdate(... | ||
20 | mmean,vvar,k*samples_per_run,... | ||
21 | mmean2,vvar2,samples_per_run); | ||
22 | mmean = meanupdate(... | ||
23 | mmean,k*samples_per_run,... | ||
24 | mmean2,samples_per_run); | ||
25 | end | ||
26 | if k==5 | ||
27 | t = toc; | ||
28 | exp_dur = t*runs/5; | ||
29 | disp(['Expected duration: ', num2str(round(exp_dur)), ' seconds']) | ||
30 | disp(['Expected duration: ', num2str(round(exp_dur/60)), ' minutes']) | ||
31 | end | ||
32 | end | ||
33 | 33 | end | end |
File PXItraces/@PXItrace/PXItrace.m changed (mode: 100644) (index 3fb2f14..eae64e3) | |||
... | ... | classdef PXItrace < class_conveniences | |
32 | 32 | pseudohash % quick pseudohash computed with pseudo_hash | pseudohash % quick pseudohash computed with pseudo_hash |
33 | 33 | chunk_index % for long measurements where traces are split into several chunks | chunk_index % for long measurements where traces are split into several chunks |
34 | 34 | dummy = false; % dummy = true creates a short dummy file with random numbers to play around with | dummy = false; % dummy = true creates a short dummy file with random numbers to play around with |
35 | stream = false % stream = true <==> PXItrace does not rely on existing file but on a stream | ||
35 | stream = false % stream = true <==> PXItrace does not rely on existing file but on a stream | ||
36 | 36 | % as created e.g. by simulation_data_stream.m | % as created e.g. by simulation_data_stream.m |
37 | 37 | end | end |
38 | 38 | properties(Dependent) | properties(Dependent) |
... | ... | classdef PXItrace < class_conveniences | |
42 | 42 | bytes_per_sample | bytes_per_sample |
43 | 43 | sample_no | sample_no |
44 | 44 | end | end |
45 | properties(Hidden) | ||
45 | properties(Hidden) | ||
46 | 46 | fileID % needed for fopen, fclose, fseek and fread | fileID % needed for fopen, fclose, fseek and fread |
47 | 47 | NI_voltage_gain | NI_voltage_gain |
48 | 48 | NI_voltage_offset | NI_voltage_offset |
... | ... | classdef PXItrace < class_conveniences | |
73 | 73 | obj.pseudohash = pseudo_hash(filepath); | obj.pseudohash = pseudo_hash(filepath); |
74 | 74 | end | end |
75 | 75 | end | end |
76 | |||
76 | |||
77 | 77 | %destructor | %destructor |
78 | 78 | function delete(obj) | function delete(obj) |
79 | 79 | %disp('destructor called'); | %disp('destructor called'); |
... | ... | classdef PXItrace < class_conveniences | |
84 | 84 | %disp(['deleted the dummy file ', obj.filename]); | %disp(['deleted the dummy file ', obj.filename]); |
85 | 85 | delete(obj.filepath); | delete(obj.filepath); |
86 | 86 | end | end |
87 | end | ||
87 | end | ||
88 | 88 | ||
89 | 89 | function dir = get.directory(obj) | function dir = get.directory(obj) |
90 | 90 | dir = fileparts(obj.filepath); | dir = fileparts(obj.filepath); |
File PXItraces/@PXItrace/blocked_cross_correlation.m changed (mode: 100644) (index 93da534..f340548) | |||
... | ... | function [cf, cf_a, cf_b] = blocked_cross_correlation(tr_a, tr_b, block_size, va | |
8 | 8 | elseif length(varargin)==1 | elseif length(varargin)==1 |
9 | 9 | scaleopt = varargin{1}; | scaleopt = varargin{1}; |
10 | 10 | assert(any(ismember(scaleopt, {'none', 'biased', 'unbiased', 'coeff'})),... | assert(any(ismember(scaleopt, {'none', 'biased', 'unbiased', 'coeff'})),... |
11 | 'scaleopt must be one of: "none", "biased", "unbiased", "coeff"!') | ||
11 | 'scaleopt must be one of: "none", "biased", "unbiased", "coeff"!') | ||
12 | 12 | end | end |
13 | 13 | disp(['calculating crosscorrelation between ',... | disp(['calculating crosscorrelation between ',... |
14 | 14 | tr_a.filename,' and ',tr_b.filename,'.']); | tr_a.filename,' and ',tr_b.filename,'.']); |
15 | |||
15 | |||
16 | 16 | tr_a.fopen; read_a = @()tr_a.fread(block_size); | tr_a.fopen; read_a = @()tr_a.fread(block_size); |
17 | 17 | tr_b.fopen; read_b = @()tr_b.fread(block_size); | tr_b.fopen; read_b = @()tr_b.fread(block_size); |
18 | |||
18 | |||
19 | 19 | sample_no = min(tr_a.sample_no, tr_b.sample_no); | sample_no = min(tr_a.sample_no, tr_b.sample_no); |
20 | 20 | block_no = floor(sample_no/block_size); | block_no = floor(sample_no/block_size); |
21 | 21 | ||
... | ... | function [cf, cf_a, cf_b] = blocked_cross_correlation(tr_a, tr_b, block_size, va | |
42 | 42 | a3 = zeropad; | a3 = zeropad; |
43 | 43 | b3 = zeropad; | b3 = zeropad; |
44 | 44 | elseif k==10 | elseif k==10 |
45 | print_eta(k, block_no) | ||
45 | print_eta(k, block_no) | ||
46 | 46 | a3 = read_a(); | a3 = read_a(); |
47 | 47 | b3 = read_b(); | b3 = read_b(); |
48 | 48 | else | else |
49 | 49 | a3 = read_a(); | a3 = read_a(); |
50 | 50 | b3 = read_b(); | b3 = read_b(); |
51 | 51 | end | end |
52 | |||
52 | |||
53 | 53 | cf = cf + myxcorr(a1,a2,a3, b1,b2,b3,k); | cf = cf + myxcorr(a1,a2,a3, b1,b2,b3,k); |
54 | 54 | cf_a = cf_a + myxcorr(a1,a2,a3, a1,a2,a3,k); | cf_a = cf_a + myxcorr(a1,a2,a3, a1,a2,a3,k); |
55 | 55 | cf_b = cf_b + myxcorr(b1,b2,b3, b1,b2,b3,k); | cf_b = cf_b + myxcorr(b1,b2,b3, b1,b2,b3,k); |
File PXItraces/@timetrace/show_snapshot.m changed (mode: 100644) (index c86a246..b9387fd) | |||
1 | 1 | function fig = show_snapshot(obj) | function fig = show_snapshot(obj) |
2 | sample_no = 1000; | ||
3 | obj.fopen; | ||
4 | data_vec = obj.fread(sample_no); | ||
5 | obj.fclose; | ||
2 | sample_no = 1000; | ||
3 | obj.fopen; | ||
4 | data_vec = obj.fread(sample_no); | ||
5 | obj.fclose; | ||
6 | 6 | time_vec = obj.timevec_from_t1_to_t2(0,sample_no/obj.samplingrate); | time_vec = obj.timevec_from_t1_to_t2(0,sample_no/obj.samplingrate); |
7 | 7 | fig = gcf; | fig = gcf; |
8 | 8 | plt = plot(time_vec, data_vec,'.-',... | plt = plot(time_vec, data_vec,'.-',... |
File PXItraces/Felix/READhomotrace.m changed (mode: 100644) (index bd6d517..64c7442) | |||
1 | 1 | function data = READhomotrace(path,samplingrate) | function data = READhomotrace(path,samplingrate) |
2 | 2 | temp_data = homotrace(path); | temp_data = homotrace(path); |
3 | 3 | ttpath = char(path); | ttpath = char(path); |
4 | |||
4 | |||
5 | 5 | %READhomotrace('F:\Experiment\2016\20160707 - LT SiN Norcada 500mum glued\P20muW\P20muW_1_amp_Range0200mV_Amplification30dB.dat',8e+7) | %READhomotrace('F:\Experiment\2016\20160707 - LT SiN Norcada 500mum glued\P20muW\P20muW_1_amp_Range0200mV_Amplification30dB.dat',8e+7) |
6 | |||
6 | |||
7 | 7 | j = 1; | j = 1; |
8 | 8 | k = 1; | k = 1; |
9 | 9 | n = 1; | n = 1; |
10 | 10 | u = 1; | u = 1; |
11 | 11 | prev = 0; | prev = 0; |
12 | |||
12 | |||
13 | 13 | for i = 1:length(ttpath) | for i = 1:length(ttpath) |
14 | 14 | if ttpath(i) == '\' | if ttpath(i) == '\' |
15 | 15 | prev = i + 1; | prev = i + 1; |
16 | 16 | end | end |
17 | 17 | end | end |
18 | |||
18 | |||
19 | 19 | newpath = []; | newpath = []; |
20 | |||
20 | |||
21 | 21 | for i = prev:length(ttpath) | for i = prev:length(ttpath) |
22 | 22 | if ttpath(i) == '_' || ttpath(i) == '.' | if ttpath(i) == '_' || ttpath(i) == '.' |
23 | 23 | if ttpath(i) == '.' | if ttpath(i) == '.' |
... | ... | function data = READhomotrace(path,samplingrate) | |
27 | 27 | n = 1; | n = 1; |
28 | 28 | k = 1; | k = 1; |
29 | 29 | u = 1; | u = 1; |
30 | |||
30 | |||
31 | 31 | else | else |
32 | 32 | switch j | switch j |
33 | 33 | case 1 | case 1 |
... | ... | function data = READhomotrace(path,samplingrate) | |
72 | 72 | k = k + 1; | k = k + 1; |
73 | 73 | end | end |
74 | 74 | end | end |
75 | |||
75 | |||
76 | 76 | if voltsU == 'mV' | if voltsU == 'mV' |
77 | 77 | volts = str2num(volts)/1000; | volts = str2num(volts)/1000; |
78 | 78 | voltsU = 'V'; | voltsU = 'V'; |
79 | 79 | end | end |
80 | |||
80 | |||
81 | 81 | if wattsU == 'muW' | if wattsU == 'muW' |
82 | 82 | temp_data.signal_power_muW = str2num(watts); | temp_data.signal_power_muW = str2num(watts); |
83 | 83 | end | end |
84 | |||
84 | |||
85 | 85 | if ampU == 'dB' | if ampU == 'dB' |
86 | 86 | amp = 10^(str2num(amp)/10); | amp = 10^(str2num(amp)/10); |
87 | 87 | ampU = 'linear'; | ampU = 'linear'; |
88 | 88 | end | end |
89 | |||
89 | |||
90 | 90 | if voltsU == 'V' | if voltsU == 'V' |
91 | 91 | temp_data.DAQrange = volts; | temp_data.DAQrange = volts; |
92 | 92 | else | else |
93 | 93 | temp_data.DAQrange = DAQrange; | temp_data.DAQrange = DAQrange; |
94 | 94 | end | end |
95 | |||
95 | |||
96 | 96 | if ampU == 'linear' | if ampU == 'linear' |
97 | 97 | temp_data.amplification = amp; | temp_data.amplification = amp; |
98 | 98 | else | else |
99 | 99 | temp_data.amplification = amplification; | temp_data.amplification = amplification; |
100 | 100 | end | end |
101 | |||
101 | |||
102 | 102 | if strcmp(ampORphase,'amp') | if strcmp(ampORphase,'amp') |
103 | 103 | ampORphase = 'Amplitude'; | ampORphase = 'Amplitude'; |
104 | 104 | temp_data.quadrature = ampORphase; | temp_data.quadrature = ampORphase; |
... | ... | function data = READhomotrace(path,samplingrate) | |
106 | 106 | ampORphase = 'Phase'; | ampORphase = 'Phase'; |
107 | 107 | temp_data.quadrature = ampORphase; | temp_data.quadrature = ampORphase; |
108 | 108 | end | end |
109 | |||
109 | |||
110 | 110 | temp_data.samplingrate = samplingrate; | temp_data.samplingrate = samplingrate; |
111 | 111 | data = temp_data; | data = temp_data; |
112 | 112 | end | end |
File PXItraces/Felix/check_range.m changed (mode: 100644) (index c4971bd..7945305) | |||
... | ... | function [data, chunk_number, error_chunks] = check_range(obj,inv_scalar) | |
4 | 4 | chunk_size = 1e+6; | chunk_size = 1e+6; |
5 | 5 | chunk_number = floor(obj.sample_no/(chunk_size*inv_scalar)); | chunk_number = floor(obj.sample_no/(chunk_size*inv_scalar)); |
6 | 6 | %chunk_number = 1e+3; | %chunk_number = 1e+3; |
7 | |||
8 | |||
7 | |||
8 | |||
9 | 9 | precision = obj.precision; | precision = obj.precision; |
10 | |||
10 | |||
11 | 11 | minrange = intmin(precision); | minrange = intmin(precision); |
12 | 12 | maxrange = intmax(precision); | maxrange = intmax(precision); |
13 | |||
14 | |||
13 | |||
14 | |||
15 | 15 | temp_valids = zeros(chunk_number,1); | temp_valids = zeros(chunk_number,1); |
16 | 16 | %temp_data = zeros(chunk_size,chunk_number); | %temp_data = zeros(chunk_size,chunk_number); |
17 | 17 | %avgmax = zeros(1,chunk_number); | %avgmax = zeros(1,chunk_number); |
18 | 18 | %avgmin = zeros(1,chunk_number); | %avgmin = zeros(1,chunk_number); |
19 | |||
19 | |||
20 | 20 | k = 1; | k = 1; |
21 | 21 | for i = 1:chunk_number | for i = 1:chunk_number |
22 | 22 | s1 = (i-1) * chunk_size + 1; | s1 = (i-1) * chunk_size + 1; |
23 | |||
23 | |||
24 | 24 | obj.fopen; | obj.fopen; |
25 | 25 | obj.fseek(s1); | obj.fseek(s1); |
26 | 26 | tmp = fread_raw(obj,chunk_size); | tmp = fread_raw(obj,chunk_size); |
27 | 27 | obj.fclose; | obj.fclose; |
28 | |||
28 | |||
29 | 29 | %do calculations with tmp | %do calculations with tmp |
30 | |||
30 | |||
31 | 31 | ||
32 | 32 | valid = true; | valid = true; |
33 | |||
33 | |||
34 | 34 | if max(tmp) > maxrange || min(tmp) < minrange | if max(tmp) > maxrange || min(tmp) < minrange |
35 | 35 | valid = false; | valid = false; |
36 | 36 | end | end |
37 | |||
38 | |||
37 | |||
38 | |||
39 | 39 | temp_valids(i) = valid; | temp_valids(i) = valid; |
40 | |||
40 | |||
41 | 41 | if not(valid) | if not(valid) |
42 | 42 | disp(['chunk number ' num2str(i) ' out of range']); | disp(['chunk number ' num2str(i) ' out of range']); |
43 | 43 | error_chunks(k) = tmp; | error_chunks(k) = tmp; |
44 | 44 | k = k+1; | k = k+1; |
45 | 45 | end | end |
46 | |||
47 | |||
48 | |||
49 | |||
46 | |||
47 | |||
48 | |||
49 | |||
50 | 50 | %temp_data(:,i) = tmp; | %temp_data(:,i) = tmp; |
51 | 51 | end | end |
52 | |||
53 | |||
54 | |||
52 | |||
53 | |||
54 | |||
55 | 55 | data = temp_valids; | data = temp_valids; |
56 | 56 | end | end |
File PXItraces/Felix/fread_raw.m changed (mode: 100644) (index d239c7e..a7b0713) | |||
... | ... | function data = fread_raw(obj, size, varargin) | |
6 | 6 | %to fread after the precision-argument, ie varargin{1}=SKIP, | %to fread after the precision-argument, ie varargin{1}=SKIP, |
7 | 7 | %varargin{2}=MACHINEFORMAT etc | %varargin{2}=MACHINEFORMAT etc |
8 | 8 | rawdata = fread(obj.fileID, size, obj.precision,varargin{:}); | rawdata = fread(obj.fileID, size, obj.precision,varargin{:}); |
9 | |||
9 | |||
10 | 10 | ||
11 | 11 | data = rawdata; | data = rawdata; |
12 | 12 | end | end |
File PXItraces/Felix/new_fft.m changed (mode: 100644) (index a059a4f..d569812) | |||
... | ... | function fig = new_fft(obj,time) | |
23 | 23 | plot(f,mx); | plot(f,mx); |
24 | 24 | title('Power Spectrum of the Vector'); | title('Power Spectrum of the Vector'); |
25 | 25 | xlabel('Frequency (Hz)'); | xlabel('Frequency (Hz)'); |
26 | ylabel('Power'); | ||
26 | ylabel('Power'); | ||
27 | 27 | end | end |
File PXItraces/Felix/sanity_check_short.m changed (mode: 100644) (index e112cdf..6b90577) | |||
... | ... | function data = sanity_check_short(obj,inv_scalar) | |
4 | 4 | ||
5 | 5 | %inv_scalar details how much of the file should be read | %inv_scalar details how much of the file should be read |
6 | 6 | %1 is everything, 2 is half of the file, 100 is 1 percent etc... | %1 is everything, 2 is half of the file, 100 is 1 percent etc... |
7 | |||
7 | |||
8 | 8 | [out, chunk_number] = check_range(obj,inv_scalar); | [out, chunk_number] = check_range(obj,inv_scalar); |
9 | |||
9 | |||
10 | 10 | %add function to check for lock problems | %add function to check for lock problems |
11 | |||
11 | |||
12 | 12 | if out == ones(chunk_number,1) | if out == ones(chunk_number,1) |
13 | 13 | disp('no range errors detected'); | disp('no range errors detected'); |
14 | 14 | data = true; | data = true; |
15 | 15 | else | else |
16 | data = false; | ||
16 | data = false; | ||
17 | 17 | end | end |
18 | |||
19 | |||
20 | end | ||
21 | 18 | ||
19 | |||
20 | end |
File PXItraces/Felix/show_fourier_transform.m changed (mode: 100644) (index 92fe781..261f0b8) | |||
1 | 1 | function fig = show_fourier_transform(obj) | function fig = show_fourier_transform(obj) |
2 | |||
2 | |||
3 | 3 | Fs = obj.samplingrate; | Fs = obj.samplingrate; |
4 | 4 | T = 1/Fs; | T = 1/Fs; |
5 | |||
5 | |||
6 | 6 | ||
7 | 7 | obj.fopen; | obj.fopen; |
8 | 8 | X = obj.fread(Fs); | X = obj.fread(Fs); |
9 | 9 | obj.fclose; | obj.fclose; |
10 | |||
10 | |||
11 | 11 | L = length(X); | L = length(X); |
12 | n = pow2(nextpow2(L)); | ||
13 | |||
12 | n = pow2(nextpow2(L)); | ||
13 | |||
14 | 14 | Y = fft(X(1:L),n); | Y = fft(X(1:L),n); |
15 | 15 | t = (0:T:(L-1)*T); | t = (0:T:(L-1)*T); |
16 | 16 | f = (0:n-1)*(Fs/n); | f = (0:n-1)*(Fs/n); |
17 | 17 | power = Y.*conj(Y)/n; | power = Y.*conj(Y)/n; |
18 | |||
19 | |||
20 | |||
18 | |||
19 | |||
20 | |||
21 | 21 | fig = gcf; | fig = gcf; |
22 | 22 | %plot(t,X(1:L)); | %plot(t,X(1:L)); |
23 | 23 | plot(f,power); | plot(f,power); |
24 | |||
25 | |||
26 | |||
24 | |||
25 | |||
26 | |||
27 | 27 | end | end |
File PXItraces/Felix/show_integral.m changed (mode: 100644) (index f74c7c5..1198335) | |||
1 | 1 | function fig = show_integral(obj) | function fig = show_integral(obj) |
2 | |||
2 | |||
3 | 3 | obj.fopen; | obj.fopen; |
4 | 4 | temp_data = obj.fread(1e+4); | temp_data = obj.fread(1e+4); |
5 | 5 | obj.fclose; | obj.fclose; |
6 | |||
6 | |||
7 | 7 | Fs = obj.samplingrate; | Fs = obj.samplingrate; |
8 | 8 | T = 1/Fs; | T = 1/Fs; |
9 | 9 | L = length(temp_data); | L = length(temp_data); |
10 | |||
10 | |||
11 | 11 | temp_data_size = temp_data(1); | temp_data_size = temp_data(1); |
12 | |||
12 | |||
13 | 13 | for i = 1:L-1 | for i = 1:L-1 |
14 | 14 | data(i) = int(temp_data(i:i+1)); | data(i) = int(temp_data(i:i+1)); |
15 | 15 | end | end |
16 | |||
16 | |||
17 | 17 | t = (0:T:(L-2)*T); | t = (0:T:(L-2)*T); |
18 | 18 | fig = gcf; | fig = gcf; |
19 | 19 | plot(t,data); | plot(t,data); |
20 | |||
20 | |||
21 | 21 | end | end |
File PXItraces/Felix/show_pwelch.m changed (mode: 100644) (index 7f9cdc9..53598f8) | |||
1 | 1 | function fig = show_pwelch(obj,time) | function fig = show_pwelch(obj,time) |
2 | 2 | Fs = obj.samplingrate; % Sampling frequency | Fs = obj.samplingrate; % Sampling frequency |
3 | |||
3 | |||
4 | 4 | obj.fopen; | obj.fopen; |
5 | 5 | x = obj.fread(Fs*time); | x = obj.fread(Fs*time); |
6 | 6 | obj.fclose; | obj.fclose; |
7 | |||
7 | |||
8 | 8 | [pxx,f] = pwelch(x,[],[],[],Fs); | [pxx,f] = pwelch(x,[],[],[],Fs); |
9 | 9 | %pmax = pwelch(x,[],[],[],Fs,'maxhold'); | %pmax = pwelch(x,[],[],[],Fs,'maxhold'); |
10 | 10 | %pmin = pwelch(x,[],[],[],Fs,'minhold'); | %pmin = pwelch(x,[],[],[],Fs,'minhold'); |
11 | |||
11 | |||
12 | 12 | fig = gcf; | fig = gcf; |
13 | 13 | plot(f,pow2db(pxx)) | plot(f,pow2db(pxx)) |
14 | |||
14 | |||
15 | 15 | end | end |
File PXItraces/PXIcalibration.m changed (mode: 100644) (index 3fc88b9..f2f0d65) | |||
... | ... | for k=1:2 | |
57 | 57 | %mytrace.fseek(randi(mytrace.sample_no)); | %mytrace.fseek(randi(mytrace.sample_no)); |
58 | 58 | data = mytrace.fread(sample_no)'; | data = mytrace.fread(sample_no)'; |
59 | 59 | mytrace.fclose(); | mytrace.fclose(); |
60 | |||
60 | |||
61 | 61 | ||
62 | 62 | % fit with fixed frequency cosine | % fit with fixed frequency cosine |
63 | 63 | % x(1) = amp, x(2) = offset, x(3) = shift | % x(1) = amp, x(2) = offset, x(3) = shift |
... | ... | for k=1:2 | |
69 | 69 | ||
70 | 70 | ||
71 | 71 | fit_values = lsqcurvefit(cosfit,guess,timevec,data,lbound,ubound); | fit_values = lsqcurvefit(cosfit,guess,timevec,data,lbound,ubound); |
72 | |||
72 | |||
73 | 73 | figure(fig_orig); | figure(fig_orig); |
74 | 74 | plot(timevec, data); | plot(timevec, data); |
75 | 75 | plot(timevec, cosfit(fit_values, timevec)); | plot(timevec, cosfit(fit_values, timevec)); |
76 | |||
76 | |||
77 | 77 | gain = fit_values(1); | gain = fit_values(1); |
78 | 78 | offset = fit_values(2); | offset = fit_values(2); |
79 | |||
79 | |||
80 | 80 | figure(fig_cali); | figure(fig_cali); |
81 | 81 | plot(timevec, (data-offset)/gain) | plot(timevec, (data-offset)/gain) |
82 | 82 | end | end |
83 | |||
84 | |||
85 | |||
83 | |||
84 | |||
85 | |||
86 | 86 | %% define meas and fit traces | %% define meas and fit traces |
87 | 87 | sample_no = 1e4; | sample_no = 1e4; |
88 | 88 |
File PXItraces/SanityChecks/sanity_check_header_v2.m changed (mode: 100644) (index d8bea7e..7187a63) | |||
... | ... | fprintf('\nOptomechanics:\n'); | |
71 | 71 | if isempty(del_OM) | if isempty(del_OM) |
72 | 72 | fprintf('All data is usable!!!\n'); | fprintf('All data is usable!!!\n'); |
73 | 73 | else | else |
74 | fprintf('%.2f%% of data not usable!!!\n',100*length(del_OM)*read_nr/testobj.sample_no); | ||
74 | fprintf('%.2f%% of data not usable!!!\n',100*length(del_OM)*read_nr/testobj.sample_no); | ||
75 | 75 | end | end |
76 | 76 | ||
77 | 77 | %% Output textfile | %% Output textfile |
File PXItraces/Tobias/sanity_check_header.m changed (mode: 100644) (index 722d3b3..425e9a2) | |||
... | ... | toc; | |
73 | 73 | % 'samplingrate', 80E6,... | % 'samplingrate', 80E6,... |
74 | 74 | % 'DAQrange', 0.2,... | % 'DAQrange', 0.2,... |
75 | 75 | % 'amplification', sqrt(1E3)); | % 'amplification', sqrt(1E3)); |
76 | % | ||
76 | % | ||
77 | 77 | % % cyc_end = 1+floor((testobj.sample_no)/(read_nr)); | % % cyc_end = 1+floor((testobj.sample_no)/(read_nr)); |
78 | 78 | % fprintf('\nOptomechanics:\n'); | % fprintf('\nOptomechanics:\n'); |
79 | 79 | % tic; | % tic; |
... | ... | fprintf('\nOptomechanics:\n'); | |
100 | 100 | if isempty(del_OM) | if isempty(del_OM) |
101 | 101 | fprintf('All data is usable!!!\n'); | fprintf('All data is usable!!!\n'); |
102 | 102 | else | else |
103 | fprintf('%.2f%% data not usable!!!\n',100*length(del_OM)*read_nr/testobj.sample_no); | ||
103 | fprintf('%.2f%% data not usable!!!\n',100*length(del_OM)*read_nr/testobj.sample_no); | ||
104 | 104 | end | end |
105 | 105 | ||
106 | 106 | %% Output textfile | %% Output textfile |
... | ... | plot(x,upper_bound_sigma_OM,'color',[1,0,0]); | |
153 | 153 | hold on; | hold on; |
154 | 154 | plot(x,lower_bound_sigma_OM,'color',[1,0,0]); | plot(x,lower_bound_sigma_OM,'color',[1,0,0]); |
155 | 155 | ||
156 | %% Sample length variance test | ||
156 | %% Sample length variance test | ||
157 | 157 | % figure(); | % figure(); |
158 | 158 | % for j=1:30 | % for j=1:30 |
159 | 159 | % clear x && vd; | % clear x && vd; |
... | ... | plot(x,lower_bound_sigma_OM,'color',[1,0,0]); | |
208 | 208 | % filepath = fullfile(basedir, 'testdata_mod_100mV_offset_+100mV_CH0_Range0200mV_Amplification0dB.dat'); | % filepath = fullfile(basedir, 'testdata_mod_100mV_offset_+100mV_CH0_Range0200mV_Amplification0dB.dat'); |
209 | 209 | % testobj = timetrace(filepath, 'samplingrate', 80E6,... | % testobj = timetrace(filepath, 'samplingrate', 80E6,... |
210 | 210 | % 'DAQrange', 0.2, 'amplification', sqrt(1E0)); | % 'DAQrange', 0.2, 'amplification', sqrt(1E0)); |
211 | % | ||
211 | % | ||
212 | 212 | % [del_DN,median_variance_DN,upper_bound_sigma_DN,lower_bound_sigma_DN,variance_data_DN] = sanity_check_darknoise(testobj,cyc_end,read_nr); | % [del_DN,median_variance_DN,upper_bound_sigma_DN,lower_bound_sigma_DN,variance_data_DN] = sanity_check_darknoise(testobj,cyc_end,read_nr); |
213 | 213 | % [del_SN,median_variance_SN,upper_bound_sigma_SN,lower_bound_sigma_SN,variance_data_SN] = sanity_check_shotnoise(testobj,upper_bound_sigma_DN,cyc_end,read_nr); | % [del_SN,median_variance_SN,upper_bound_sigma_SN,lower_bound_sigma_SN,variance_data_SN] = sanity_check_shotnoise(testobj,upper_bound_sigma_DN,cyc_end,read_nr); |
214 | 214 | % sanity_check_mechanical(testobj,upper_bound_sigma_DN,upper_bound_sigma_SN,cyc_end,read_nr); | % sanity_check_mechanical(testobj,upper_bound_sigma_DN,upper_bound_sigma_SN,cyc_end,read_nr); |
File PXItraces/Tobias/sanity_check_header_v2.m changed (mode: 100644) (index f4790b8..5224ead) | |||
... | ... | fprintf('\nOptomechanics:\n'); | |
71 | 71 | if isempty(del_OM) | if isempty(del_OM) |
72 | 72 | fprintf('All data is usable!!!\n'); | fprintf('All data is usable!!!\n'); |
73 | 73 | else | else |
74 | fprintf('%.2f%% of data not usable!!!\n',100*length(del_OM)*read_nr/testobj.sample_no); | ||
74 | fprintf('%.2f%% of data not usable!!!\n',100*length(del_OM)*read_nr/testobj.sample_no); | ||
75 | 75 | end | end |
76 | 76 | ||
77 | 77 | %% Output textfile | %% Output textfile |
78 | 78 | % if ~isempty(del_DN) | % if ~isempty(del_DN) |
79 | 79 | % dlmwrite('C:\Users\aspel\Desktop\Test\DN.txt',del_DN); | % dlmwrite('C:\Users\aspel\Desktop\Test\DN.txt',del_DN); |
80 | 80 | % end | % end |
81 | % | ||
81 | % | ||
82 | 82 | % if ~isempty(del_SN) | % if ~isempty(del_SN) |
83 | 83 | % dlmwrite('C:\Users\aspel\Desktop\Test\SN.txt',del_SN); | % dlmwrite('C:\Users\aspel\Desktop\Test\SN.txt',del_SN); |
84 | 84 | % end | % end |
85 | % | ||
85 | % | ||
86 | 86 | % if ~isempty(del_OM) | % if ~isempty(del_OM) |
87 | 87 | % dlmwrite('C:\Users\aspel\Desktop\Test\OM.txt',del_OM); | % dlmwrite('C:\Users\aspel\Desktop\Test\OM.txt',del_OM); |
88 | 88 | % end | % end |
File data_analysis/@entanglement_evaluation/calculateModeVectors.m changed (mode: 100644) (index 5c2e565..4492231) | |||
... | ... | function obj = calculateModeVectors(obj, varargin) | |
18 | 18 | ||
19 | 19 | if ~dummy_mode | if ~dummy_mode |
20 | 20 | assert(obj.samplingrate > 0,... | assert(obj.samplingrate > 0,... |
21 | 'Sampling rate must be positive.') | ||
21 | 'Sampling rate must be positive.') | ||
22 | 22 | assert(~isempty(obj.opt_pulse_widths),... | assert(~isempty(obj.opt_pulse_widths),... |
23 | 23 | 'opt_pulse_widths must be provided or calculated using getOptPulseWidths'); | 'opt_pulse_widths must be provided or calculated using getOptPulseWidths'); |
24 | 24 | end | end |
25 | |||
25 | |||
26 | 26 | obj.readout_modes = []; | obj.readout_modes = []; |
27 | 27 | obj.entangling_modes = []; | obj.entangling_modes = []; |
28 | 28 | ||
... | ... | function obj = calculateModeVectors(obj, varargin) | |
59 | 59 | [readout_mode_ON, R] = qr(readout_mode,0); | [readout_mode_ON, R] = qr(readout_mode,0); |
60 | 60 | readout_mode_ON=readout_mode_ON(:,1:obj.mech_frequencies_no); | readout_mode_ON=readout_mode_ON(:,1:obj.mech_frequencies_no); |
61 | 61 | entangling_mode_ON = flipud(readout_mode_ON); | entangling_mode_ON = flipud(readout_mode_ON); |
62 | |||
62 | |||
63 | 63 | % test orthonormalization | % test orthonormalization |
64 | % (the following tolerances were found to yield reasonable constraints | ||
64 | % (the following tolerances were found to yield reasonable constraints | ||
65 | 65 | % in a 47-mode evaluation of experimental data) | % in a 47-mode evaluation of experimental data) |
66 | 66 | norm_tol = 1E-12; | norm_tol = 1E-12; |
67 | 67 | orthog_tol = 1E-8; | orthog_tol = 1E-8; |
68 | |||
68 | |||
69 | 69 | [orthonorm, orthog, normal, info] = orthonormality(readout_mode_ON',... | [orthonorm, orthog, normal, info] = orthonormality(readout_mode_ON',... |
70 | 70 | norm_tol, orthog_tol); | norm_tol, orthog_tol); |
71 | |||
71 | |||
72 | 72 | if ~orthonorm | if ~orthonorm |
73 | 73 | message=sprintf('\nlight qr failed: launching hard qr...\n'); | message=sprintf('\nlight qr failed: launching hard qr...\n'); |
74 | 74 | disp(message) | disp(message) |
... | ... | function obj = calculateModeVectors(obj, varargin) | |
80 | 80 | entangling_mode_ON = flipud(readout_mode_ON); | entangling_mode_ON = flipud(readout_mode_ON); |
81 | 81 | toc | toc |
82 | 82 | end | end |
83 | |||
83 | |||
84 | 84 | assert_orthonormality(readout_mode_ON', norm_tol, orthog_tol); | assert_orthonormality(readout_mode_ON', norm_tol, orthog_tol); |
85 | |||
85 | |||
86 | 86 | obj.readout_modes = [obj.readout_modes;... | obj.readout_modes = [obj.readout_modes;... |
87 | 87 | transpose(readout_mode_ON)]; | transpose(readout_mode_ON)]; |
88 | 88 | obj.entangling_modes = [obj.entangling_modes;... | obj.entangling_modes = [obj.entangling_modes;... |
File data_analysis/@entanglement_evaluation/calculatePulsedCMs.m changed (mode: 100644) (index a112a62..a0a0fe0) | |||
... | ... | function obj = calculatePulsedCMs(obj, varargin) | |
4 | 4 | for pow_ind=1:obj.tracepairs_no | for pow_ind=1:obj.tracepairs_no |
5 | 5 | obj = calculatePulsedCMsSingle(obj, pow_ind); | obj = calculatePulsedCMsSingle(obj, pow_ind); |
6 | 6 | end | end |
7 | case 2 | ||
7 | case 2 | ||
8 | 8 | pow_ind = varargin{1}; | pow_ind = varargin{1}; |
9 | 9 | obj = calculatePulsedCMsSingle(obj, pow_ind); | obj = calculatePulsedCMsSingle(obj, pow_ind); |
10 | 10 | otherwise | otherwise |
11 | 11 | error('Too many varargin-arguments.') | error('Too many varargin-arguments.') |
12 | end | ||
12 | end | ||
13 | 13 | end | end |
14 | 14 | ||
15 | 15 | function obj = calculatePulsedCMsSingle(obj, pow_ind) | function obj = calculatePulsedCMsSingle(obj, pow_ind) |
File data_analysis/@entanglement_evaluation/calculatePulsedQuadratures.m changed (mode: 100644) (index 8b1cf78..5d56627) | |||
... | ... | function obj = calculatePulsedQuadratures(obj, tracepair_ind, varargin) | |
22 | 22 | P = zeros(pulsepairs_no, modes_no); | P = zeros(pulsepairs_no, modes_no); |
23 | 23 | X = zeros(pulsepairs_no, modes_no); | X = zeros(pulsepairs_no, modes_no); |
24 | 24 | Y = zeros(pulsepairs_no, modes_no); | Y = zeros(pulsepairs_no, modes_no); |
25 | |||
25 | |||
26 | 26 | [raw_data, close_raw_data] = get_raw_data_fct(obj, tracepair_ind); | [raw_data, close_raw_data] = get_raw_data_fct(obj, tracepair_ind); |
27 | 27 | ||
28 | 28 | print_eta = estimated_time_of_arrival; | print_eta = estimated_time_of_arrival; |
29 | 29 | percent_done=0; | percent_done=0; |
30 | |||
30 | |||
31 | 31 | for pp=1:pulsepairs_no | for pp=1:pulsepairs_no |
32 | 32 | [q,p,x,y] = getQuadsForNextPulse(obj, raw_data); | [q,p,x,y] = getQuadsForNextPulse(obj, raw_data); |
33 | 33 | Q(pp,:) = q; P(pp,:) = p; X(pp,:) = x; Y(pp,:) = y; | Q(pp,:) = q; P(pp,:) = p; X(pp,:) = x; Y(pp,:) = y; |
34 | |||
34 | |||
35 | 35 | if pp==20, print_eta(pp, pulsepairs_no); | if pp==20, print_eta(pp, pulsepairs_no); |
36 | 36 | elseif floor(pp/pulsepairs_no*100)>(percent_done+5) | elseif floor(pp/pulsepairs_no*100)>(percent_done+5) |
37 | 37 | percent_done = percent_done + 5 | percent_done = percent_done + 5 |
... | ... | function obj = calculatePulsedQuadratures(obj, tracepair_ind, varargin) | |
40 | 40 | ||
41 | 41 | close_raw_data(); | close_raw_data(); |
42 | 42 | ||
43 | |||
43 | |||
44 | 44 | % reorder into pulse_trace{tracepair_ind}{gam_ind} | % reorder into pulse_trace{tracepair_ind}{gam_ind} |
45 | 45 | for g=1:obj.pulse_gammas_no | for g=1:obj.pulse_gammas_no |
46 | 46 | %reorder into Q1, Q2,.., P1, P2,.., X1, X2,.., Y1, Y2,... | %reorder into Q1, Q2,.., P1, P2,.., X1, X2,.., Y1, Y2,... |
47 | 47 | % for each pulse_gamma | % for each pulse_gamma |
48 | 48 | first_mode_ind = (g-1)*obj.mech_frequencies_no + 1; | first_mode_ind = (g-1)*obj.mech_frequencies_no + 1; |
49 | 49 | last_mode_ind = g*obj.mech_frequencies_no; | last_mode_ind = g*obj.mech_frequencies_no; |
50 | |||
50 | |||
51 | 51 | q = Q(:, first_mode_ind:last_mode_ind); | q = Q(:, first_mode_ind:last_mode_ind); |
52 | 52 | p = P(:, first_mode_ind:last_mode_ind); | p = P(:, first_mode_ind:last_mode_ind); |
53 | 53 | x = X(:, first_mode_ind:last_mode_ind); | x = X(:, first_mode_ind:last_mode_ind); |
54 | 54 | y = Y(:, first_mode_ind:last_mode_ind); | y = Y(:, first_mode_ind:last_mode_ind); |
55 | |||
55 | |||
56 | 56 | % reorder into Q1, P1, Q2, P2,..., X1, Y1, X2, Y2,... | % reorder into Q1, P1, Q2, P2,..., X1, Y1, X2, Y2,... |
57 | 57 | pulse_trace = permute_data([q, p, x, y]); | pulse_trace = permute_data([q, p, x, y]); |
58 | 58 | obj.pulse_trace{tracepair_ind}{g} = pulse_trace; | obj.pulse_trace{tracepair_ind}{g} = pulse_trace; |
... | ... | end | |
63 | 63 | function [q,p,x,y] = getQuadsForNextPulse(obj, raw_data_fct) | function [q,p,x,y] = getQuadsForNextPulse(obj, raw_data_fct) |
64 | 64 | entangling_data = raw_data_fct(); | entangling_data = raw_data_fct(); |
65 | 65 | readout_data = raw_data_fct(); | readout_data = raw_data_fct(); |
66 | |||
66 | |||
67 | 67 | if obj.inverted_evaluation | if obj.inverted_evaluation |
68 | 68 | entangling_data = conj(entangling_data); | entangling_data = conj(entangling_data); |
69 | 69 | readout_data = conj(readout_data); | readout_data = conj(readout_data); |
70 | 70 | end | end |
71 | |||
71 | |||
72 | 72 | entangling = obj.entangling_modes*entangling_data; | entangling = obj.entangling_modes*entangling_data; |
73 | 73 | readout = obj.readout_modes*readout_data; | readout = obj.readout_modes*readout_data; |
74 | |||
74 | |||
75 | 75 | q = real(entangling); p = imag(entangling); | q = real(entangling); p = imag(entangling); |
76 | 76 | x = real(readout); y = imag(readout); | x = real(readout); y = imag(readout); |
77 | 77 | end | end |
... | ... | function [get_raw_data, close_raw_data] = get_raw_data_fct(obj, tracepair_ind) | |
99 | 99 | end | end |
100 | 100 | end | end |
101 | 101 | get_raw_data = @fcthandle_get; | get_raw_data = @fcthandle_get; |
102 | |||
102 | |||
103 | 103 | function fcthandle_close() | function fcthandle_close() |
104 | 104 | ampli_tr.fclose; | ampli_tr.fclose; |
105 | 105 | phase_tr.fclose; | phase_tr.fclose; |
File data_analysis/@entanglement_evaluation/calculate_log_neg.m changed (mode: 100644) (index 8d8da18..44a32f8) | |||
... | ... | function calculate_log_neg(obj, shotnoise_ind) | |
14 | 14 | end | end |
15 | 15 | ||
16 | 16 | % after (re)calculation of log.neg. | % after (re)calculation of log.neg. |
17 | % wipe clean any potential previous calculation of optimal log.neg. or pulse width | ||
17 | % wipe clean any potential previous calculation of optimal log.neg. or pulse width | ||
18 | 18 | opt_logneg_corrected_private = []; | opt_logneg_corrected_private = []; |
19 | 19 | opt_pulse_gammas_private = []; | opt_pulse_gammas_private = []; |
File data_analysis/@entanglement_evaluation/calculate_mode_vectors_gammalist.m changed (mode: 100644) (index 8db3411..8478e7b) | |||
... | ... | function ev = calculate_mode_vectors_gammalist(ev) | |
41 | 41 | [readout_mode_ON, R] = qr(readout_mode,0); | [readout_mode_ON, R] = qr(readout_mode,0); |
42 | 42 | readout_mode_ON=readout_mode_ON(:,1:ev.mech_frequencies_no); | readout_mode_ON=readout_mode_ON(:,1:ev.mech_frequencies_no); |
43 | 43 | entangling_mode_ON = flipud(readout_mode_ON); | entangling_mode_ON = flipud(readout_mode_ON); |
44 | |||
44 | |||
45 | 45 | % test orthonormalization | % test orthonormalization |
46 | % (the following tolerances were found to yield reasonable constraints | ||
46 | % (the following tolerances were found to yield reasonable constraints | ||
47 | 47 | % in a 47-mode evaluation of experimental data) | % in a 47-mode evaluation of experimental data) |
48 | 48 | norm_tol = 1E-12; | norm_tol = 1E-12; |
49 | 49 | orthog_tol = 1E-8; | orthog_tol = 1E-8; |
50 | |||
50 | |||
51 | 51 | [orthonorm, orthog, normal, info] = orthonormality(readout_mode_ON',... | [orthonorm, orthog, normal, info] = orthonormality(readout_mode_ON',... |
52 | 52 | norm_tol, orthog_tol); | norm_tol, orthog_tol); |
53 | |||
53 | |||
54 | 54 | if ~orthonorm | if ~orthonorm |
55 | 55 | message=sprintf('\nlight qr failed: launching hard qr...\n'); | message=sprintf('\nlight qr failed: launching hard qr...\n'); |
56 | 56 | disp(message) | disp(message) |
... | ... | function ev = calculate_mode_vectors_gammalist(ev) | |
58 | 58 | readout_mode_ON=readout_mode_ON(:,1:ev.mech_frequencies_no); | readout_mode_ON=readout_mode_ON(:,1:ev.mech_frequencies_no); |
59 | 59 | entangling_mode_ON = flipud(readout_mode_ON); | entangling_mode_ON = flipud(readout_mode_ON); |
60 | 60 | end | end |
61 | |||
61 | |||
62 | 62 | assert_orthonormality(readout_mode_ON', norm_tol, orthog_tol); | assert_orthonormality(readout_mode_ON', norm_tol, orthog_tol); |
63 | 63 | ||
64 | 64 | ev.readout_modes = [ev.readout_modes;... | ev.readout_modes = [ev.readout_modes;... |
File data_analysis/@entanglement_evaluation/calibratePulsedCMs.m changed (mode: 100644) (index b71e416..46c8c79) | |||
1 | 1 | function obj = calibratePulsedCMs(obj, varargin) | function obj = calibratePulsedCMs(obj, varargin) |
2 | 2 | shotnoise_ind = get_shotnoise_ind(obj, varargin{:}); | shotnoise_ind = get_shotnoise_ind(obj, varargin{:}); |
3 | |||
3 | |||
4 | 4 | if obj.homodyne_visibility==1 && obj.detection_efficiency==1 | if obj.homodyne_visibility==1 && obj.detection_efficiency==1 |
5 | 5 | pulse_CM_corrected = obj.pulse_CM; | pulse_CM_corrected = obj.pulse_CM; |
6 | 6 | else | else |
7 | 7 | pulse_CM_corrected = correct_for_detection_imperfections(obj, shotnoise_ind); | pulse_CM_corrected = correct_for_detection_imperfections(obj, shotnoise_ind); |
8 | 8 | end | end |
9 | 9 | calibrate_to_shotnoise(obj, pulse_CM_corrected, shotnoise_ind); | calibrate_to_shotnoise(obj, pulse_CM_corrected, shotnoise_ind); |
10 | |||
10 | |||
11 | 11 | calculate_log_neg(obj, shotnoise_ind); | calculate_log_neg(obj, shotnoise_ind); |
12 | 12 | calculate_physicality(obj); | calculate_physicality(obj); |
13 | 13 | ||
... | ... | function pulse_CM_corr = correct_for_detection_imperfections(obj, shotnoise_ind) | |
19 | 19 | cm_shot_measured = obj.pulse_CM{shotnoise_ind}{g}; | cm_shot_measured = obj.pulse_CM{shotnoise_ind}{g}; |
20 | 20 | pulse_CM_corr{shotnoise_ind}{g} = cm_shot_measured/eta; | pulse_CM_corr{shotnoise_ind}{g} = cm_shot_measured/eta; |
21 | 21 | for signal_ind=1:obj.tracepairs_no | for signal_ind=1:obj.tracepairs_no |
22 | if signal_ind==shotnoise_ind, continue | ||
22 | if signal_ind==shotnoise_ind, continue | ||
23 | 23 | else | else |
24 | 24 | cm_signal_measured = obj.pulse_CM{signal_ind}{g}; | cm_signal_measured = obj.pulse_CM{signal_ind}{g}; |
25 | 25 | pulse_CM_corr{signal_ind}{g} = (cm_signal_measured - (1 - (eta*(nu^2)))*cm_shot_measured)/((eta*nu)^2); | pulse_CM_corr{signal_ind}{g} = (cm_signal_measured - (1 - (eta*(nu^2)))*cm_shot_measured)/((eta*nu)^2); |
File data_analysis/@entanglement_evaluation/calulate_optimal_entanglement.m changed (mode: 100644) (index 80da6a6..5bd0899) | |||
1 | 1 | function ev = calulate_optimal_entanglement(ev) | function ev = calulate_optimal_entanglement(ev) |
2 | % resample pulse_gammas to yield better resolution in pulse-width-space | ||
3 | resampling_factor = 100; | ||
4 | pulse_gammas_refined = interp(ev.pulse_gammas, resampling_factor); | ||
5 | pulse_gammas_refined = pulse_gammas_refined(... | ||
6 | pulse_gammas_refined<max(ev.pulse_gammas)); | ||
7 | pulse_gammas_refined = [pulse_gammas_refined, max(ev.pulse_gammas)]; | ||
2 | % resample pulse_gammas to yield better resolution in pulse-width-space | ||
3 | resampling_factor = 100; | ||
4 | pulse_gammas_refined = interp(ev.pulse_gammas, resampling_factor); | ||
5 | pulse_gammas_refined = pulse_gammas_refined(... | ||
6 | pulse_gammas_refined<max(ev.pulse_gammas)); | ||
7 | pulse_gammas_refined = [pulse_gammas_refined, max(ev.pulse_gammas)]; | ||
8 | 8 | ||
9 | K = length(ev.logneg_corrected); | ||
10 | opt_logneg_corrected_private = zeros(K,1); | ||
11 | opt_pulse_gammas_private = zeros(K,1); | ||
12 | for k=1:K | ||
13 | log_neg = [ev.logneg_corrected{k}{:}]; | ||
14 | |||
15 | % interpolate evaluated pulse widths and log.neg.values | ||
16 | logneg_corrected_refined = interp1(ev.pulse_gammas, log_neg,... | ||
17 | pulse_gammas_refined, 'splines'); | ||
18 | |||
19 | % optimize over interpolated values | ||
20 | [lnopt, optind] = max(logneg_corrected_refined); | ||
21 | opt_logneg_corrected_private(k) = lnopt; | ||
22 | opt_pulse_gammas_private(k) = pulse_gammas_refined(optind); | ||
9 | K = length(ev.logneg_corrected); | ||
10 | opt_logneg_corrected_private = zeros(K,1); | ||
11 | opt_pulse_gammas_private = zeros(K,1); | ||
12 | for k=1:K | ||
13 | log_neg = [ev.logneg_corrected{k}{:}]; | ||
23 | 14 | ||
24 | % save interpolated arrays for inspection | ||
25 | ev.pulse_gammas_interpolated{k} = pulse_gammas_refined; | ||
26 | ev.logneg_corrected_interpolated{k} = logneg_corrected_refined; | ||
27 | end | ||
15 | % interpolate evaluated pulse widths and log.neg.values | ||
16 | logneg_corrected_refined = interp1(ev.pulse_gammas, log_neg,... | ||
17 | pulse_gammas_refined, 'splines'); | ||
28 | 18 | ||
29 | ev.opt_logneg_corrected_private = opt_logneg_corrected_private; | ||
30 | ev.opt_pulse_gammas_private = opt_pulse_gammas_private; | ||
19 | % optimize over interpolated values | ||
20 | [lnopt, optind] = max(logneg_corrected_refined); | ||
21 | opt_logneg_corrected_private(k) = lnopt; | ||
22 | opt_pulse_gammas_private(k) = pulse_gammas_refined(optind); | ||
23 | |||
24 | % save interpolated arrays for inspection | ||
25 | ev.pulse_gammas_interpolated{k} = pulse_gammas_refined; | ||
26 | ev.logneg_corrected_interpolated{k} = logneg_corrected_refined; | ||
27 | end | ||
28 | |||
29 | ev.opt_logneg_corrected_private = opt_logneg_corrected_private; | ||
30 | ev.opt_pulse_gammas_private = opt_pulse_gammas_private; |
File data_analysis/@entanglement_evaluation/darknoisesubtractPulsedCMs.m changed (mode: 100644) (index e171620..66cbd74) | |||
... | ... | function obj = darknoisesubtractPulsedCMs(obj, varargin) | |
2 | 2 | darknoise_ind = get_darknoise_ind(obj, varargin{:}) | darknoise_ind = get_darknoise_ind(obj, varargin{:}) |
3 | 3 | for g=1:obj.pulse_gammas_no | for g=1:obj.pulse_gammas_no |
4 | 4 | cm_dark = obj.pulse_CM{darknoise_ind}{g}; | cm_dark = obj.pulse_CM{darknoise_ind}{g}; |
5 | |||
5 | |||
6 | 6 | for p=1:obj.tracepairs_no | for p=1:obj.tracepairs_no |
7 | 7 | cm = obj.pulse_CM{p}{g}; | cm = obj.pulse_CM{p}{g}; |
8 | 8 | obj.pulse_CM{p}{g} = cm - cm_dark; | obj.pulse_CM{p}{g} = cm - cm_dark; |
... | ... | function darknoise_ind = get_darknoise_ind(obj, varargin) | |
19 | 19 | error(['Unrecognized varargin-argument ', varargin{k}]); | error(['Unrecognized varargin-argument ', varargin{k}]); |
20 | 20 | end | end |
21 | 21 | end | end |
22 | |||
22 | |||
23 | 23 | assert(length(darknoise_ind)==1,... | assert(length(darknoise_ind)==1,... |
24 | 24 | 'No unique index for the darknoise traces was provided') | 'No unique index for the darknoise traces was provided') |
File data_analysis/@entanglement_evaluation/entanglement_evaluation.m changed (mode: 100644) (index 4fac9bf..15b2f73) | |||
... | ... | classdef entanglement_evaluation < class_conveniences & entanglement_evaluation_ | |
53 | 53 | ||
54 | 54 | ||
55 | 55 | %%% DEPENDENT PROPERTIES AND THEIR GETTERS %%% | %%% DEPENDENT PROPERTIES AND THEIR GETTERS %%% |
56 | properties(Dependent) | ||
56 | properties(Dependent) | ||
57 | 57 | %% FROM PROPERTIES OF THE EVALUATION | %% FROM PROPERTIES OF THE EVALUATION |
58 | 58 | mech_frequencies_no@double scalar | mech_frequencies_no@double scalar |
59 | 59 | pulse_gammas_no@double scalar | pulse_gammas_no@double scalar |
File data_analysis/@entanglement_evaluation/example_entanglement_evaluation.m changed (mode: 100644) (index 426bbed..867ab5e) | |||
... | ... | meas.add_trace_pair(... | |
14 | 14 | 'ts_07142015-185030_200muW_xQ_int16_sf368.000_Nts1.0e+06_MCr1.dat',... | 'ts_07142015-185030_200muW_xQ_int16_sf368.000_Nts1.0e+06_MCr1.dat',... |
15 | 15 | 'ts_07142015-185030_200muW_yQ_int16_sf368.000_Nts1.0e+06_MCr1.dat',... | 'ts_07142015-185030_200muW_yQ_int16_sf368.000_Nts1.0e+06_MCr1.dat',... |
16 | 16 | 'samplingrate', 70, 'amplification', 368, 'signal_power_muW', 200); | 'samplingrate', 70, 'amplification', 368, 'signal_power_muW', 200); |
17 | |||
18 | |||
17 | |||
18 | |||
19 | 19 | %% create entanglement_evaluation object | %% create entanglement_evaluation object |
20 | 20 | clear('ev') | clear('ev') |
21 | 21 | ev = entanglement_evaluation(); | ev = entanglement_evaluation(); |
File data_analysis/@entanglement_evaluation/exportResults.m changed (mode: 100644) (index 7eeadc3..2b94c44) | |||
... | ... | function export_data_and_CM(obj) | |
25 | 25 | filename = ['.short_', filename]; | filename = ['.short_', filename]; |
26 | 26 | dlmwrite(fullfile(obj.evaluation_folder,filename),... | dlmwrite(fullfile(obj.evaluation_folder,filename),... |
27 | 27 | data, 'delimiter', '\t','precision',6); | data, 'delimiter', '\t','precision',6); |
28 | |||
29 | |||
28 | |||
29 | |||
30 | 30 | pulsed_CMs_calibrated = obj.pulse_CM_calibrated; | pulsed_CMs_calibrated = obj.pulse_CM_calibrated; |
31 | 31 | if ~isempty(pulsed_CMs_calibrated) | if ~isempty(pulsed_CMs_calibrated) |
32 | 32 | filename = 'pulsed_CMs_calibrated.mat'; | filename = 'pulsed_CMs_calibrated.mat'; |
33 | 33 | save(fullfile(obj.evaluation_folder, filename), 'pulsed_CMs_calibrated'); | save(fullfile(obj.evaluation_folder, filename), 'pulsed_CMs_calibrated'); |
34 | 34 | end | end |
35 | |||
35 | |||
36 | 36 | lognegs = obj.logneg_corrected; | lognegs = obj.logneg_corrected; |
37 | 37 | if ~isempty(lognegs) | if ~isempty(lognegs) |
38 | 38 | filename = 'lognegs.mat'; | filename = 'lognegs.mat'; |
39 | 39 | save(fullfile(obj.evaluation_folder, filename), 'lognegs'); | save(fullfile(obj.evaluation_folder, filename), 'lognegs'); |
40 | 40 | end | end |
41 | |||
41 | |||
42 | 42 | physicality = obj.pulse_CM_is_physical; | physicality = obj.pulse_CM_is_physical; |
43 | 43 | if ~isempty(physicality) | if ~isempty(physicality) |
44 | 44 | filename = 'physicality.mat'; | filename = 'physicality.mat'; |
File data_analysis/@entanglement_evaluation/plotLogneg.m changed (mode: 100644) (index aba17ac..14abdf7) | |||
... | ... | function fig = plotLogneg(obj, varargin) | |
48 | 48 | error(['Unrecognized varargin-argument ', varargin{k},'.']); | error(['Unrecognized varargin-argument ', varargin{k},'.']); |
49 | 49 | end | end |
50 | 50 | end | end |
51 | |||
51 | |||
52 | 52 | if new_fig | if new_fig |
53 | 53 | fig = figure; hold all; | fig = figure; hold all; |
54 | 54 | else | else |
... | ... | function fig = plotLogneg(obj, varargin) | |
85 | 85 | labels('Pulse width $$\Gamma \, [\mathrm{Hz}]$$',... | labels('Pulse width $$\Gamma \, [\mathrm{Hz}]$$',... |
86 | 86 | 'Logarithmic negativity $$E_\mathcal{N}$$'); | 'Logarithmic negativity $$E_\mathcal{N}$$'); |
87 | 87 | title(tex_escape(titlestr)); | title(tex_escape(titlestr)); |
88 | |||
88 | |||
89 | 89 | ||
90 | 90 | % add info regarding physicality to plot | % add info regarding physicality to plot |
91 | 91 | if show_physicality | if show_physicality |
File data_analysis/@entanglement_evaluation/plot_logneg_gammalist.m changed (mode: 100644) (index f6698e3..37913fc) | |||
1 | 1 | function plot_logneg_gammalist(ev, power_ind, varargin) | function plot_logneg_gammalist(ev, power_ind, varargin) |
2 | symmetric = false; | ||
3 | divergent = false; | ||
4 | invert = false; | ||
5 | export = true; | ||
6 | minvalue = -inf; | ||
7 | maxvalue = +inf; | ||
8 | titlestr = []; | ||
9 | export_suffix =''; | ||
10 | for k=1:2:length(varargin) | ||
11 | switch varargin{k} | ||
12 | case {'symmetric', 'Symmetric'} | ||
13 | symmetric = varargin{k+1}; | ||
14 | case {'invert', 'Invert'} | ||
15 | invert = varargin{k+1}; | ||
16 | case {'divergent', 'Divergent'} | ||
17 | divergent = varargin{k+1}; | ||
18 | case {'minvalue', 'min'} | ||
19 | minvalue = varargin{k+1}; | ||
20 | case {'maxvalue', 'max'} | ||
21 | maxvalue = varargin{k+1}; | ||
22 | case {'title', 'Title'} | ||
23 | titlestr = varargin{k+1}; | ||
24 | case {'export', 'Export', 'save', 'Save'} | ||
25 | export = varargin{k+1}; | ||
26 | case {'export_suffix', 'exportsuffix', 'suffix', 'Suffix'} | ||
27 | export_suffix = ['.',varargin{k+1}]; | ||
28 | otherwise | ||
29 | error(['Unrecognized varargin-argument ', varargin{k}]) | ||
30 | end | ||
31 | end | ||
2 | symmetric = false; | ||
3 | divergent = false; | ||
4 | invert = false; | ||
5 | export = true; | ||
6 | minvalue = -inf; | ||
7 | maxvalue = +inf; | ||
8 | titlestr = []; | ||
9 | export_suffix =''; | ||
10 | for k=1:2:length(varargin) | ||
11 | switch varargin{k} | ||
12 | case {'symmetric', 'Symmetric'} | ||
13 | symmetric = varargin{k+1}; | ||
14 | case {'invert', 'Invert'} | ||
15 | invert = varargin{k+1}; | ||
16 | case {'divergent', 'Divergent'} | ||
17 | divergent = varargin{k+1}; | ||
18 | case {'minvalue', 'min'} | ||
19 | minvalue = varargin{k+1}; | ||
20 | case {'maxvalue', 'max'} | ||
21 | maxvalue = varargin{k+1}; | ||
22 | case {'title', 'Title'} | ||
23 | titlestr = varargin{k+1}; | ||
24 | case {'export', 'Export', 'save', 'Save'} | ||
25 | export = varargin{k+1}; | ||
26 | case {'export_suffix', 'exportsuffix', 'suffix', 'Suffix'} | ||
27 | export_suffix = ['.',varargin{k+1}]; | ||
28 | otherwise | ||
29 | error(['Unrecognized varargin-argument ', varargin{k}]) | ||
30 | end | ||
31 | end | ||
32 | |||
33 | pulse_widths_factorized = allcomb_invert(ev.pulse_widths); | ||
34 | |||
35 | % right now, we only support plotting mode 1 on x and mode 2 on y | ||
36 | x_mode_no = 1; | ||
37 | y_mode_no = 2; | ||
38 | |||
39 | % get axis labels | ||
40 | x_labels = pulse_widths_factorized{x_mode_no}; | ||
41 | x_labels = cellfun(@num2eng, num2cell(x_labels(:)), 'UniformOutput', false); | ||
32 | 42 | ||
33 | pulse_widths_factorized = allcomb_invert(ev.pulse_widths); | ||
43 | y_labels = pulse_widths_factorized{y_mode_no}; | ||
44 | y_labels = flipud(y_labels); | ||
45 | y_labels = cellfun(@num2eng, num2cell(y_labels(:)), 'UniformOutput', false); | ||
34 | 46 | ||
35 | % right now, we only support plotting mode 1 on x and mode 2 on y | ||
36 | x_mode_no = 1; | ||
37 | y_mode_no = 2; | ||
47 | % reshape data to be consistent with axis labelling | ||
48 | data = reshape(cell2mat(ev.logneg_corrected{power_ind})',... | ||
49 | length(x_labels), length(y_labels)); | ||
50 | data = flipud(data); | ||
38 | 51 | ||
39 | % get axis labels | ||
40 | x_labels = pulse_widths_factorized{x_mode_no}; | ||
41 | x_labels = cellfun(@num2eng, num2cell(x_labels(:)), 'UniformOutput', false); | ||
42 | |||
43 | y_labels = pulse_widths_factorized{y_mode_no}; | ||
44 | y_labels = flipud(y_labels); | ||
45 | y_labels = cellfun(@num2eng, num2cell(y_labels(:)), 'UniformOutput', false); | ||
46 | |||
47 | % reshape data to be consistent with axis labelling | ||
48 | data = reshape(cell2mat(ev.logneg_corrected{power_ind})',... | ||
49 | length(x_labels), length(y_labels)); | ||
50 | data = flipud(data); | ||
52 | % calculate parameters | ||
53 | ncolors = 1024; | ||
54 | data_max = max(max(data)); | ||
55 | data_min = min(min(data)); | ||
51 | 56 | ||
52 | % calculate parameters | ||
53 | ncolors = 1024; | ||
54 | data_max = max(max(data)); | ||
55 | data_min = min(min(data)); | ||
56 | |||
57 | if symmetric | ||
58 | cmap = cbrewer('div', 'RdBu', ncolors); %Divergent tables:'BrBG', 'PiYG', 'PRGn', 'PuOr', 'RdBu', 'RdGy', 'RdYlBu', 'RdYlGn' | ||
57 | if symmetric | ||
58 | cmap = cbrewer('div', 'RdBu', ncolors); %Divergent tables:'BrBG', 'PiYG', 'PRGn', 'PuOr', 'RdBu', 'RdGy', 'RdYlBu', 'RdYlGn' | ||
59 | |||
60 | extremum = max([abs(data_min), data_max]); | ||
61 | if minvalue==-inf | ||
62 | minvalue = -extremum; | ||
63 | end | ||
64 | maxvalue = -minvalue; | ||
65 | else | ||
66 | if minvalue==-inf | ||
67 | minvalue = data_min; | ||
68 | end | ||
69 | if maxvalue==+inf | ||
70 | maxvalue = data_max; | ||
71 | end | ||
72 | cmap = cbrewer('seq', 'Blues', ncolors); % Sequential tables:'Blues','BuGn','BuPu','GnBu','Greens','Greys','Oranges','OrRd','PuBu','PuBuGn','PuRd','Purples','RdPu','Reds','YlGn','YlGnBu','YlOrBr','YlOrRd','Spectral' | ||
73 | end | ||
74 | if divergent | ||
75 | datarange = maxvalue-minvalue; | ||
76 | maxcolno = round(ncolors*abs(maxvalue)/datarange); | ||
77 | mincolno = round(ncolors*abs(minvalue)/datarange); | ||
78 | maxmap = cbrewer('seq', 'Reds', maxcolno); | ||
79 | minmap = flipud(cbrewer('seq', 'Blues', mincolno)); | ||
80 | cmap = [minmap; maxmap]; | ||
81 | end | ||
59 | 82 | ||
60 | extremum = max([abs(data_min), data_max]); | ||
61 | if minvalue==-inf | ||
62 | minvalue = -extremum; | ||
63 | end | ||
64 | maxvalue = -minvalue; | ||
65 | else | ||
66 | if minvalue==-inf | ||
67 | minvalue = data_min; | ||
68 | end | ||
69 | if maxvalue==+inf | ||
70 | maxvalue = data_max; | ||
71 | end | ||
72 | cmap = cbrewer('seq', 'Blues', ncolors); % Sequential tables:'Blues','BuGn','BuPu','GnBu','Greens','Greys','Oranges','OrRd','PuBu','PuBuGn','PuRd','Purples','RdPu','Reds','YlGn','YlGnBu','YlOrBr','YlOrRd','Spectral' | ||
73 | end | ||
74 | if divergent | ||
75 | datarange = maxvalue-minvalue; | ||
76 | maxcolno = round(ncolors*abs(maxvalue)/datarange); | ||
77 | mincolno = round(ncolors*abs(minvalue)/datarange); | ||
78 | maxmap = cbrewer('seq', 'Reds', maxcolno); | ||
79 | minmap = flipud(cbrewer('seq', 'Blues', mincolno)); | ||
80 | cmap = [minmap; maxmap]; | ||
81 | end | ||
83 | if invert | ||
84 | cmap = flipud(cmap); | ||
85 | end | ||
82 | 86 | ||
83 | if invert | ||
84 | cmap = flipud(cmap); | ||
85 | end | ||
87 | % plot | ||
88 | heatmap(data, x_labels, y_labels, '%0.3f',... | ||
89 | 'Colormap', cmap, 'Colorbar', true,... | ||
90 | 'MinColorValue', minvalue, 'MaxColorValue', maxvalue,... | ||
91 | 'GridLines', ':', 'TextColor', 'k',... | ||
92 | 'ColorLevels', ncolors); | ||
93 | xlabel(['Width [Hz] for mode with central frequency ', num2eng(ev.mech_frequencies(x_mode_no)),'Hz']); | ||
94 | ylabel(['Width [Hz] for mode with central frequency ', num2eng(ev.mech_frequencies(y_mode_no)),'Hz']); | ||
95 | title(titlestr); | ||
86 | 96 | ||
87 | % plot | ||
88 | heatmap(data, x_labels, y_labels, '%0.3f',... | ||
89 | 'Colormap', cmap, 'Colorbar', true,... | ||
90 | 'MinColorValue', minvalue, 'MaxColorValue', maxvalue,... | ||
91 | 'GridLines', ':', 'TextColor', 'k',... | ||
92 | 'ColorLevels', ncolors); | ||
93 | xlabel(['Width [Hz] for mode with central frequency ', num2eng(ev.mech_frequencies(x_mode_no)),'Hz']); | ||
94 | ylabel(['Width [Hz] for mode with central frequency ', num2eng(ev.mech_frequencies(y_mode_no)),'Hz']); | ||
95 | title(titlestr); | ||
96 | |||
97 | % export to ev.evaluation_folder | ||
98 | eval_folder_exists = isequal(exist(ev.evaluation_folder),7); | ||
99 | if export | ||
100 | if eval_folder_exists | ||
101 | wherewasi = cd; | ||
102 | cd(ev.evaluation_folder); | ||
103 | export_fig(['logneg_corrected_', num2str(power_ind), export_suffix],... | ||
104 | '-pdf', '-transparent') | ||
105 | cd(wherewasi); | ||
106 | else | ||
97 | % export to ev.evaluation_folder | ||
98 | eval_folder_exists = isequal(exist(ev.evaluation_folder),7); | ||
99 | if export | ||
100 | if eval_folder_exists | ||
101 | wherewasi = cd; | ||
102 | cd(ev.evaluation_folder); | ||
103 | export_fig(['logneg_corrected_', num2str(power_ind), export_suffix],... | ||
104 | '-pdf', '-transparent') | ||
105 | cd(wherewasi); | ||
106 | else | ||
107 | 107 | warning(['Cannot find the evaluation folder ',... | warning(['Cannot find the evaluation folder ',... |
108 | 108 | ev.evaluation_folder]) | ev.evaluation_folder]) |
109 | 109 | end | end |
110 | end | ||
110 | end |
File data_analysis/@entanglement_evaluation/plot_logneg_gammalist_split.m changed (mode: 100644) (index 031b925..f3acacf) | |||
1 | 1 | function fig = plot_logneg_gammalist_split(ev, power_ind, varargin) | function fig = plot_logneg_gammalist_split(ev, power_ind, varargin) |
2 | invert = false; | ||
3 | export = true; | ||
4 | titlestr = []; | ||
5 | ylabel_str = ''; | ||
6 | export_suffix =''; | ||
7 | minvalue = []; | ||
8 | maxvalue = []; | ||
9 | for k=1:2:length(varargin) | ||
10 | switch varargin{k} | ||
11 | case {'invert', 'Invert'} | ||
12 | invert = varargin{k+1}; | ||
13 | case {'title', 'Title'} | ||
14 | titlestr = varargin{k+1}; | ||
15 | case {'export', 'Export', 'save', 'Save'} | ||
16 | export = varargin{k+1}; | ||
17 | case {'ylabel', 'Ylabel', 'YLabel'} | ||
18 | ylabel_str = varargin{k+1}; | ||
19 | case {'minvalue', 'min'} | ||
20 | minvalue = varargin{k+1}; | ||
21 | case {'maxvalue', 'max'} | ||
22 | maxvalue = varargin{k+1}; | ||
23 | case {'export_suffix', 'exportsuffix', 'suffix', 'Suffix'} | ||
24 | export_suffix = ['.',varargin{k+1}]; | ||
25 | otherwise | ||
26 | error(['Unrecognized varargin-argument ', varargin{k}]) | ||
27 | end | ||
28 | end | ||
2 | invert = false; | ||
3 | export = true; | ||
4 | titlestr = []; | ||
5 | ylabel_str = ''; | ||
6 | export_suffix =''; | ||
7 | minvalue = []; | ||
8 | maxvalue = []; | ||
9 | for k=1:2:length(varargin) | ||
10 | switch varargin{k} | ||
11 | case {'invert', 'Invert'} | ||
12 | invert = varargin{k+1}; | ||
13 | case {'title', 'Title'} | ||
14 | titlestr = varargin{k+1}; | ||
15 | case {'export', 'Export', 'save', 'Save'} | ||
16 | export = varargin{k+1}; | ||
17 | case {'ylabel', 'Ylabel', 'YLabel'} | ||
18 | ylabel_str = varargin{k+1}; | ||
19 | case {'minvalue', 'min'} | ||
20 | minvalue = varargin{k+1}; | ||
21 | case {'maxvalue', 'max'} | ||
22 | maxvalue = varargin{k+1}; | ||
23 | case {'export_suffix', 'exportsuffix', 'suffix', 'Suffix'} | ||
24 | export_suffix = ['.',varargin{k+1}]; | ||
25 | otherwise | ||
26 | error(['Unrecognized varargin-argument ', varargin{k}]) | ||
27 | end | ||
28 | end | ||
29 | 29 | ||
30 | lognegs = [ev.logneg_corrected{power_ind}{:}]'; | ||
31 | fig = figure; hold all; | ||
32 | |||
33 | function mysubplot(subplotind, xind, lind, cmap) | ||
34 | cmap = flipud(cbrewer('seq', cmap, 9)); | ||
35 | if invert | ||
36 | cmap = flipud(cmap); | ||
37 | end | ||
38 | pwx = ev.pulse_widths(:,xind); | ||
39 | pwl = ev.pulse_widths(:,lind); | ||
30 | lognegs = [ev.logneg_corrected{power_ind}{:}]'; | ||
31 | fig = figure; hold all; | ||
40 | 32 | ||
41 | colind=0; | ||
42 | for w=unique(pwl)' | ||
43 | ax = subplot(subplotind); hold all | ||
44 | colind = colind+1; | ||
45 | indices = find(pwl==w); | ||
46 | x_data = pwx(indices); | ||
47 | y_data = lognegs(indices); | ||
48 | plot(x_data, y_data, 'o-',... | ||
49 | 'Color', cmap(colind,:),... | ||
50 | 'LineWidth',2,... | ||
51 | 'MarkerFaceColor', cmap(colind,:),... | ||
52 | 'DisplayName', num2eng(w)) | ||
53 | xlim([0.9*min(x_data), 1.1*max(x_data)]) | ||
54 | if (~isempty(minvalue))&&(~isempty(maxvalue)) | ||
55 | ylim([minvalue, maxvalue]) | ||
56 | end | ||
57 | end | ||
58 | title(['Log. negativity vs pulse width [Hz] of mode ', num2str(xind)]) | ||
59 | postprocess_fig(xind, lind); | ||
60 | set(ax, 'box', 'on', 'Visible', 'on') | ||
61 | end | ||
33 | function mysubplot(subplotind, xind, lind, cmap) | ||
34 | cmap = flipud(cbrewer('seq', cmap, 9)); | ||
35 | if invert | ||
36 | cmap = flipud(cmap); | ||
37 | end | ||
38 | pwx = ev.pulse_widths(:,xind); | ||
39 | pwl = ev.pulse_widths(:,lind); | ||
62 | 40 | ||
63 | function postprocess_fig(xind, lind) | ||
64 | set(gca, 'xscale', 'log'); | ||
65 | %xlabel(['Pulse Width ', num2str(xind), ' [Hz]']); | ||
66 | ylabel(ylabel_str); | ||
41 | colind=0; | ||
42 | for w=unique(pwl)' | ||
43 | ax = subplot(subplotind); hold all | ||
44 | colind = colind+1; | ||
45 | indices = find(pwl==w); | ||
46 | x_data = pwx(indices); | ||
47 | y_data = lognegs(indices); | ||
48 | plot(x_data, y_data, 'o-',... | ||
49 | 'Color', cmap(colind,:),... | ||
50 | 'LineWidth',2,... | ||
51 | 'MarkerFaceColor', cmap(colind,:),... | ||
52 | 'DisplayName', num2eng(w)) | ||
53 | xlim([0.9*min(x_data), 1.1*max(x_data)]) | ||
54 | if (~isempty(minvalue))&&(~isempty(maxvalue)) | ||
55 | ylim([minvalue, maxvalue]) | ||
56 | end | ||
57 | end | ||
58 | title(['Log. negativity vs pulse width [Hz] of mode ', num2str(xind)]) | ||
59 | postprocess_fig(xind, lind); | ||
60 | set(ax, 'box', 'on', 'Visible', 'on') | ||
61 | end | ||
67 | 62 | ||
68 | mylegend = legend('Location','EastOutside'); | ||
69 | mytitle = get(mylegend,'title'); | ||
70 | set(mytitle,'string',['Pulse Width ', num2str(lind), ' [Hz]']); | ||
71 | |||
72 | hline=refline(0,0); set(hline, 'Color', 'k'); | ||
73 | grid on | ||
74 | end | ||
63 | function postprocess_fig(xind, lind) | ||
64 | set(gca, 'xscale', 'log'); | ||
65 | %xlabel(['Pulse Width ', num2str(xind), ' [Hz]']); | ||
66 | ylabel(ylabel_str); | ||
75 | 67 | ||
76 | mysubplot(211,1,2, 'GnBu'); | ||
77 | mysubplot(212,2,1, 'OrRd'); | ||
78 | suptitle(titlestr); | ||
68 | mylegend = legend('Location','EastOutside'); | ||
69 | mytitle = get(mylegend,'title'); | ||
70 | set(mytitle,'string',['Pulse Width ', num2str(lind), ' [Hz]']); | ||
79 | 71 | ||
80 | % export to ev.evaluation_folder | ||
81 | eval_folder_exists = isequal(exist(ev.evaluation_folder),7); | ||
82 | if export | ||
83 | if eval_folder_exists | ||
84 | wherewasi = cd; | ||
85 | cd(ev.evaluation_folder); | ||
86 | export_fig(['logneg_corrected_', num2str(power_ind), '.split',export_suffix],... | ||
87 | '-pdf', '-nocrop', '-transparent') | ||
88 | cd(wherewasi); | ||
89 | else | ||
90 | warning(['Cannot find the evaluation folder ',... | ||
91 | ev.evaluation_folder]) | ||
92 | end | ||
93 | end | ||
72 | hline=refline(0,0); set(hline, 'Color', 'k'); | ||
73 | grid on | ||
74 | end | ||
75 | |||
76 | mysubplot(211,1,2, 'GnBu'); | ||
77 | mysubplot(212,2,1, 'OrRd'); | ||
78 | suptitle(titlestr); | ||
79 | |||
80 | % export to ev.evaluation_folder | ||
81 | eval_folder_exists = isequal(exist(ev.evaluation_folder),7); | ||
82 | if export | ||
83 | if eval_folder_exists | ||
84 | wherewasi = cd; | ||
85 | cd(ev.evaluation_folder); | ||
86 | export_fig(['logneg_corrected_', num2str(power_ind), '.split',export_suffix],... | ||
87 | '-pdf', '-nocrop', '-transparent') | ||
88 | cd(wherewasi); | ||
89 | else | ||
90 | warning(['Cannot find the evaluation folder ',... | ||
91 | ev.evaluation_folder]) | ||
92 | end | ||
93 | end |
File data_analysis/@entanglement_evaluation/recalibrate.m changed (mode: 100644) (index 57096ff..4ed1de8) | |||
1 | 1 | function obj = recalibrate(obj, varargin) | function obj = recalibrate(obj, varargin) |
2 | 2 | [shotnoise_ind, eta, nu] = get_opt_args(obj, varargin{:}); | [shotnoise_ind, eta, nu] = get_opt_args(obj, varargin{:}); |
3 | obj.detection_efficiency = eta; | ||
3 | obj.detection_efficiency = eta; | ||
4 | 4 | obj.homodyne_visibility = nu; | obj.homodyne_visibility = nu; |
5 | obj.calibratePulsedCMs('shotnoise_ind', shotnoise_ind); | ||
5 | obj.calibratePulsedCMs('shotnoise_ind', shotnoise_ind); | ||
6 | 6 | ||
7 | 7 | function [shotnoise_ind, eta, nu] = get_opt_args(obj, varargin) | function [shotnoise_ind, eta, nu] = get_opt_args(obj, varargin) |
8 | 8 | shotnoise_ind = []; | shotnoise_ind = []; |
... | ... | function [shotnoise_ind, eta, nu] = get_opt_args(obj, varargin) | |
12 | 12 | switch varargin{k} | switch varargin{k} |
13 | 13 | case 'shotnoise_ind' | case 'shotnoise_ind' |
14 | 14 | shotnoise_ind = varargin{k+1}; | shotnoise_ind = varargin{k+1}; |
15 | case 'eta' | ||
15 | case 'eta' | ||
16 | 16 | eta = varargin{k+1}; | eta = varargin{k+1}; |
17 | case 'nu' | ||
17 | case 'nu' | ||
18 | 18 | nu = varargin{k+1}; | nu = varargin{k+1}; |
19 | 19 | otherwise | otherwise |
20 | 20 | error(['Unrecognized varargin-argument ', varargin{k}]); | error(['Unrecognized varargin-argument ', varargin{k}]); |
File data_analysis/@entanglement_evaluation/trace_out.m changed (mode: 100644) (index 7f1d004..7affa72) | |||
1 | 1 | function ev_traced = trace_out(ev, modes_to_trace, varargin) | function ev_traced = trace_out(ev, modes_to_trace, varargin) |
2 | % return a version of ev in which all light modes | ||
3 | % which correspond to the mechanical modes specified in modes_to_trace | ||
4 | % have been traced out. That is for which the interesting quantities | ||
5 | % logneg, physicality, covariance matrices have been recalculated appropriately | ||
6 | ev_traced = ev.copy(); | ||
2 | % return a version of ev in which all light modes | ||
3 | % which correspond to the mechanical modes specified in modes_to_trace | ||
4 | % have been traced out. That is for which the interesting quantities | ||
5 | % logneg, physicality, covariance matrices have been recalculated appropriately | ||
6 | ev_traced = ev.copy(); | ||
7 | 7 | ||
8 | % throw away stuff which isn't strictly needed | ||
9 | ev_traced.entangling_modes = []; | ||
10 | ev_traced.readout_modes = []; | ||
8 | % throw away stuff which isn't strictly needed | ||
9 | ev_traced.entangling_modes = []; | ||
10 | ev_traced.readout_modes = []; | ||
11 | 11 | ||
12 | 12 | % throw away stuff which needs to be recomputed after tracing out | % throw away stuff which needs to be recomputed after tracing out |
13 | 13 | ev_traced.opt_logneg_corrected_private = []; | ev_traced.opt_logneg_corrected_private = []; |
14 | 14 | ev_traced.opt_pulse_gammas_private = []; | ev_traced.opt_pulse_gammas_private = []; |
15 | 15 | ||
16 | 16 | % | % |
17 | mech_frequencies_old = ev.mech_frequencies; | ||
18 | mode_indices_old = 1:ev.mech_frequencies_no; | ||
17 | mech_frequencies_old = ev.mech_frequencies; | ||
18 | mode_indices_old = 1:ev.mech_frequencies_no; | ||
19 | 19 | ||
20 | assert(all(ismember(modes_to_trace, mode_indices_old)),... | ||
21 | 'entanglement_evaluation:trace_out:modes_illegit',... | ||
22 | 'The modes you specified for tracing out do not seem to be legit.'); | ||
20 | assert(all(ismember(modes_to_trace, mode_indices_old)),... | ||
21 | 'entanglement_evaluation:trace_out:modes_illegit',... | ||
22 | 'The modes you specified for tracing out do not seem to be legit.'); | ||
23 | 23 | ||
24 | mode_indices_new = setdiff(mode_indices_old, modes_to_trace); | ||
25 | mech_frequencies_new = mech_frequencies_old(mode_indices_new); | ||
24 | mode_indices_new = setdiff(mode_indices_old, modes_to_trace); | ||
25 | mech_frequencies_new = mech_frequencies_old(mode_indices_new); | ||
26 | 26 | ||
27 | ev_traced.mech_frequencies = mech_frequencies_new; | ||
27 | ev_traced.mech_frequencies = mech_frequencies_new; | ||
28 | 28 | ||
29 | 29 | light_mode_inds_new = [mode_indices_new, ev.mech_frequencies_no + mode_indices_new]; | light_mode_inds_new = [mode_indices_new, ev.mech_frequencies_no + mode_indices_new]; |
30 | 30 | light_quad_inds_new = quadIndicesFromModeIndices(light_mode_inds_new); | light_quad_inds_new = quadIndicesFromModeIndices(light_mode_inds_new); |
31 | 31 | ||
32 | %% trace out the pulsed traces if possible | ||
32 | %% trace out the pulsed traces if possible | ||
33 | 33 | if ~isempty(ev.pulse_trace) | if ~isempty(ev.pulse_trace) |
34 | trace_out_traces = @(mat)mat(:,light_quad_inds_new); | ||
35 | for k=1:ev.tracepairs_no | ||
36 | ev_traced.pulse_trace{k} = cellfun(trace_out_traces,... | ||
37 | ev.pulse_trace{k}, 'UniformOutput', false); | ||
38 | end | ||
34 | trace_out_traces = @(mat)mat(:,light_quad_inds_new); | ||
35 | for k=1:ev.tracepairs_no | ||
36 | ev_traced.pulse_trace{k} = cellfun(trace_out_traces,... | ||
37 | ev.pulse_trace{k}, 'UniformOutput', false); | ||
38 | end | ||
39 | 39 | end | end |
40 | 40 | ||
41 | 41 | ||
42 | %% trace out pulsed CMs | ||
43 | trace_out_CMs = @(mat) mat(light_quad_inds_new,light_quad_inds_new); | ||
44 | for k=1:ev.tracepairs_no | ||
45 | ev_traced.pulse_CM{k} = cellfun(trace_out_CMs,... | ||
46 | ev.pulse_CM{k}, 'UniformOutput', false); | ||
47 | ev_traced.pulse_CM_calibrated{k} = cellfun(trace_out_CMs,... | ||
48 | ev.pulse_CM_calibrated{k}, 'UniformOutput', false); | ||
49 | end | ||
42 | %% trace out pulsed CMs | ||
43 | trace_out_CMs = @(mat) mat(light_quad_inds_new,light_quad_inds_new); | ||
44 | for k=1:ev.tracepairs_no | ||
45 | ev_traced.pulse_CM{k} = cellfun(trace_out_CMs,... | ||
46 | ev.pulse_CM{k}, 'UniformOutput', false); | ||
47 | ev_traced.pulse_CM_calibrated{k} = cellfun(trace_out_CMs,... | ||
48 | ev.pulse_CM_calibrated{k}, 'UniformOutput', false); | ||
49 | end | ||
50 | 50 | ||
51 | %% recalculate shotnoise and physicality | ||
52 | shotnoise_ind = get_shotnoise_ind(ev_traced, varargin{:}); | ||
53 | calculate_log_neg(ev_traced, shotnoise_ind); | ||
51 | %% recalculate shotnoise and physicality | ||
52 | shotnoise_ind = get_shotnoise_ind(ev_traced, varargin{:}); | ||
53 | calculate_log_neg(ev_traced, shotnoise_ind); | ||
54 | 54 | calculate_physicality(ev_traced); | calculate_physicality(ev_traced); |
File data_analysis/@meta_ev/contour_plot.m changed (mode: 100644) (index f4abace..cf1d9f8) | |||
1 | 1 | function contour_plot(meta, plot_type, tracepairs_ind, varargin) | function contour_plot(meta, plot_type, tracepairs_ind, varargin) |
2 | assertEqual(meta.gridtype,'matrix',... | ||
3 | 'only implemented for gridtype "matrix"') | ||
2 | assertEqual(meta.gridtype,'matrix',... | ||
3 | 'only implemented for gridtype "matrix"') | ||
4 | 4 | ||
5 | switch lower(plot_type) | ||
6 | case {'logneg', 'opt_log_neg', 'entanglement'} | ||
7 | display_name = 'Max. log. negativity'; | ||
8 | fig_handle = 'ln_cont_fig'; | ||
9 | z_data = meta.opt_logneg_corrected_interp{tracepairs_ind}; | ||
10 | abs_max = ceil(10*max(max(abs(z_data))))/10; | ||
11 | c_axis_lims = [-abs_max,abs_max]; | ||
12 | if abs_max > 5 | ||
13 | c_levels = [[-abs_max:0.5:0],[0.1:0.1:abs_max]]; | ||
14 | elseif abs_max > 1 | ||
15 | c_levels = [[-abs_max:0.1:0],[0.1:0.1:abs_max]]; | ||
16 | elseif abs_max > 0.5 | ||
17 | c_levels = [-abs_max:0.1:abs_max]; | ||
18 | else | ||
19 | c_levels = [-abs_max:0.05:abs_max]; | ||
20 | end | ||
21 | cmap = flipud(cbrewer('div','RdBu',512)); | ||
22 | case {'pulsewidth', 'opt_pulse_gamma', 'opt_pulsewidth'} | ||
23 | display_name = 'Optimal pulse width [kHz]'; | ||
24 | fig_handle = 'pw_cont_fig'; | ||
25 | z_data = meta.opt_pulse_gammas_interp{tracepairs_ind}/1E3; | ||
26 | abs_max = ceil(10*max(max(abs(z_data))))/10; | ||
27 | abs_min = floor(10*min(min(abs(z_data))))/10; | ||
28 | c_axis_lims = [abs_min,abs_max]; | ||
29 | c_levels = logspace(log10(abs_min), log10(abs_max), 10); | ||
30 | cmap = cbrewer('seq','Blues',512); | ||
31 | otherwise | ||
32 | error(['Unsupported plottype: ', plot_type]); | ||
33 | end | ||
5 | switch lower(plot_type) | ||
6 | case {'logneg', 'opt_log_neg', 'entanglement'} | ||
7 | display_name = 'Max. log. negativity'; | ||
8 | fig_handle = 'ln_cont_fig'; | ||
9 | z_data = meta.opt_logneg_corrected_interp{tracepairs_ind}; | ||
10 | abs_max = ceil(10*max(max(abs(z_data))))/10; | ||
11 | c_axis_lims = [-abs_max,abs_max]; | ||
12 | if abs_max > 5 | ||
13 | c_levels = [[-abs_max:0.5:0],[0.1:0.1:abs_max]]; | ||
14 | elseif abs_max > 1 | ||
15 | c_levels = [[-abs_max:0.1:0],[0.1:0.1:abs_max]]; | ||
16 | elseif abs_max > 0.5 | ||
17 | c_levels = [-abs_max:0.1:abs_max]; | ||
18 | else | ||
19 | c_levels = [-abs_max:0.05:abs_max]; | ||
20 | end | ||
21 | cmap = flipud(cbrewer('div','RdBu',512)); | ||
22 | case {'pulsewidth', 'opt_pulse_gamma', 'opt_pulsewidth'} | ||
23 | display_name = 'Optimal pulse width [kHz]'; | ||
24 | fig_handle = 'pw_cont_fig'; | ||
25 | z_data = meta.opt_pulse_gammas_interp{tracepairs_ind}/1E3; | ||
26 | abs_max = ceil(10*max(max(abs(z_data))))/10; | ||
27 | abs_min = floor(10*min(min(abs(z_data))))/10; | ||
28 | c_axis_lims = [abs_min,abs_max]; | ||
29 | c_levels = logspace(log10(abs_min), log10(abs_max), 10); | ||
30 | cmap = cbrewer('seq','Blues',512); | ||
31 | otherwise | ||
32 | error(['Unsupported plottype: ', plot_type]); | ||
33 | end | ||
34 | 34 | ||
35 | x_scale = 'lin'; y_scale = 'lin'; | ||
36 | x_lims = []; y_lims = []; | ||
37 | fig = []; | ||
38 | for k=1:2:length(varargin) | ||
39 | switch lower(varargin{k}) | ||
40 | case {'x_scale','xscale'} | ||
41 | x_scale = varargin{k+1}; | ||
42 | case {'x_lims','xlims','x_lim','xlim'} | ||
43 | x_lims = varargin{k+1}; | ||
44 | case {'y_scale','yscale'} | ||
45 | y_scale = varargin{k+1}; | ||
46 | case {'y_lims','ylims','y_lim','ylim'} | ||
47 | y_lims = varargin{k+1}; | ||
48 | case {'caxis','coloraxis','c_axis_lims','color_axis_lims', 'coloraxis_lims'} | ||
49 | c_axis_lims = varargin{k+1}; | ||
50 | case {'label','fig_label','figlabel'} | ||
51 | meta.fig_label = varargin{k+1}; | ||
52 | case {'fig', 'figure'} | ||
53 | fig = varargin{k+1}; | ||
54 | otherwise | ||
55 | error(['unrecognized varargin-argument: ', varargin{k}]); | ||
56 | end | ||
57 | end | ||
35 | x_scale = 'lin'; y_scale = 'lin'; | ||
36 | x_lims = []; y_lims = []; | ||
37 | fig = []; | ||
38 | for k=1:2:length(varargin) | ||
39 | switch lower(varargin{k}) | ||
40 | case {'x_scale','xscale'} | ||
41 | x_scale = varargin{k+1}; | ||
42 | case {'x_lims','xlims','x_lim','xlim'} | ||
43 | x_lims = varargin{k+1}; | ||
44 | case {'y_scale','yscale'} | ||
45 | y_scale = varargin{k+1}; | ||
46 | case {'y_lims','ylims','y_lim','ylim'} | ||
47 | y_lims = varargin{k+1}; | ||
48 | case {'caxis','coloraxis','c_axis_lims','color_axis_lims', 'coloraxis_lims'} | ||
49 | c_axis_lims = varargin{k+1}; | ||
50 | case {'label','fig_label','figlabel'} | ||
51 | meta.fig_label = varargin{k+1}; | ||
52 | case {'fig', 'figure'} | ||
53 | fig = varargin{k+1}; | ||
54 | otherwise | ||
55 | error(['unrecognized varargin-argument: ', varargin{k}]); | ||
56 | end | ||
57 | end | ||
58 | 58 | ||
59 | if isempty(fig) | ||
60 | fig = figure; hold all; | ||
61 | else | ||
59 | if isempty(fig) | ||
60 | fig = figure; hold all; | ||
61 | else | ||
62 | 62 | visibility = get(fig,'visible'); | visibility = get(fig,'visible'); |
63 | 63 | figure(fig); hold all; set(fig, 'visible', visibility); | figure(fig); hold all; set(fig, 'visible', visibility); |
64 | 64 | end | end |
65 | 65 | ||
66 | meta.(fig_handle) = my_contour_plot(meta, fig, z_data,... | ||
67 | c_levels, display_name, cmap, c_axis_lims,... | ||
68 | x_scale, x_lims, y_scale, y_lims); | ||
66 | meta.(fig_handle) = my_contour_plot(meta, fig, z_data,... | ||
67 | c_levels, display_name, cmap, c_axis_lims,... | ||
68 | x_scale, x_lims, y_scale, y_lims); | ||
69 | 69 | ||
70 | 70 | ||
71 | 71 | function fig = my_contour_plot(meta, fig, z_data, c_levels, display_name, cmap, c_axis_lims, x_scale, x_lims, y_scale, y_lims) | function fig = my_contour_plot(meta, fig, z_data, c_levels, display_name, cmap, c_axis_lims, x_scale, x_lims, y_scale, y_lims) |
72 | %%% contour plot | ||
73 | [x_data, y_data] = meta.params_interp{:}; | ||
74 | [x_data, y_data, z_data] = meta_ev.limit_x_and_y(x_data, y_data, z_data, x_lims, y_lims); | ||
75 | [c_data, c_handles] = contourf(x_data, y_data, z_data,... | ||
76 | c_levels, 'DisplayName', display_name); | ||
77 | colormap(cmap); caxis(c_axis_lims); | ||
78 | set(gca, 'xscale', x_scale, 'yscale', y_scale) | ||
79 | labels(meta.param_names{:}); | ||
72 | %%% contour plot | ||
73 | [x_data, y_data] = meta.params_interp{:}; | ||
74 | [x_data, y_data, z_data] = meta_ev.limit_x_and_y(x_data, y_data, z_data, x_lims, y_lims); | ||
75 | [c_data, c_handles] = contourf(x_data, y_data, z_data,... | ||
76 | c_levels, 'DisplayName', display_name); | ||
77 | colormap(cmap); caxis(c_axis_lims); | ||
78 | set(gca, 'xscale', x_scale, 'yscale', y_scale) | ||
79 | labels(meta.param_names{:}); | ||
80 | |||
81 | %%% scatter plot of simulated data points | ||
82 | set(gca, 'layer', 'top') | ||
83 | scatter(meta.params{1}(:), meta.params{2}(:), 'xk',... | ||
84 | 'MarkerFaceColor','none',... | ||
85 | 'LineWidth',1,... | ||
86 | 'DisplayName', 'Simulated data points') | ||
87 | leg = legend('Location', 'Best'); | ||
88 | set(leg, 'Color', 'w', 'FontWeight', 'normal', 'LineWidth', 1, 'Interpreter', 'latex') | ||
80 | 89 | ||
81 | %%% scatter plot of simulated data points | ||
82 | set(gca, 'layer', 'top') | ||
83 | scatter(meta.params{1}(:), meta.params{2}(:), 'xk',... | ||
84 | 'MarkerFaceColor','none',... | ||
85 | 'LineWidth',1,... | ||
86 | 'DisplayName', 'Simulated data points') | ||
87 | leg = legend('Location', 'Best'); | ||
88 | set(leg, 'Color', 'w', 'FontWeight', 'normal', 'LineWidth', 1, 'Interpreter', 'latex') | ||
90 | %%% contour labels | ||
91 | text_handle = clabel(c_data, 'FontSize', 13); | ||
92 | for k=1:length(text_handle)/2 | ||
93 | z_value = get(text_handle(2*k), 'UserData'); | ||
94 | if z_value == 0 | ||
95 | c_color = [1,0,0]; | ||
96 | elseif z_value < 0 | ||
97 | c_color = cmap(1,:); | ||
98 | elseif z_value > 0 | ||
99 | c_color = cmap(end,:); | ||
100 | end | ||
89 | 101 | ||
90 | %%% contour labels | ||
91 | text_handle = clabel(c_data, 'FontSize', 13); | ||
92 | for k=1:length(text_handle)/2 | ||
93 | z_value = get(text_handle(2*k), 'UserData'); | ||
94 | if z_value == 0 | ||
95 | c_color = [1,0,0]; | ||
96 | elseif z_value < 0 | ||
97 | c_color = cmap(1,:); | ||
98 | elseif z_value > 0 | ||
99 | c_color = cmap(end,:); | ||
100 | end | ||
101 | |||
102 | set(text_handle(2*k), 'BackgroundColor','none', 'EdgeColor', 'none',...%c_colors(k,:),... | ||
103 | 'Color', c_color, 'FontWeight', 'normal', 'LineWidth', 0.7);% text | ||
104 | set(text_handle(2*k-1),'Marker','o', 'MarkerFaceColor', c_color,... | ||
105 | 'MarkerSize', 6, 'MarkerEdgeColor','none');% marker | ||
106 | |||
107 | if z_value < -0.1 && ismember(z_value, c_levels(1:2:end)) || z_value <-1 | ||
108 | set(text_handle(2*k),'String','') | ||
109 | set(text_handle(2*k-1),'Marker','none') | ||
110 | end | ||
111 | end | ||
112 | meta.my_postprocess_plot(fig); | ||
102 | set(text_handle(2*k), 'BackgroundColor','none', 'EdgeColor', 'none',...%c_colors(k,:),... | ||
103 | 'Color', c_color, 'FontWeight', 'normal', 'LineWidth', 0.7);% text | ||
104 | set(text_handle(2*k-1),'Marker','o', 'MarkerFaceColor', c_color,... | ||
105 | 'MarkerSize', 6, 'MarkerEdgeColor','none');% marker | ||
106 | |||
107 | if z_value < -0.1 && ismember(z_value, c_levels(1:2:end)) || z_value <-1 | ||
108 | set(text_handle(2*k),'String','') | ||
109 | set(text_handle(2*k-1),'Marker','none') | ||
110 | end | ||
111 | end | ||
112 | meta.my_postprocess_plot(fig); |
File data_analysis/@meta_ev/get_meta_data.m changed (mode: 100644) (index f0d5725..9b8f1f1) | |||
... | ... | function get_meta_data(meta, meta_data_file) | |
3 | 3 | % | % |
4 | 4 | % meta.get_meta_data(meta_data_file) adds to the meta_ev-object meta | % meta.get_meta_data(meta_data_file) adds to the meta_ev-object meta |
5 | 5 | % all information contained in the textfile meta_data_file. | % all information contained in the textfile meta_data_file. |
6 | % | ||
6 | % | ||
7 | 7 | % The metadata-file should be tab-separated. There should be one header line. | % The metadata-file should be tab-separated. There should be one header line. |
8 | 8 | % The header should look as follows: ev_file \t name_of_param1 \t name_of_param2 \t name_of_param3 ... | % The header should look as follows: ev_file \t name_of_param1 \t name_of_param2 \t name_of_param3 ... |
9 | 9 | headerlines = 1; | headerlines = 1; |
10 | |||
10 | |||
11 | 11 | % clear any old postprocessing results | % clear any old postprocessing results |
12 | 12 | meta.reset; | meta.reset; |
13 | 13 |
File data_analysis/@meta_ev/meta_ev.m changed (mode: 100644) (index 076695f..d26d142) | |||
1 | 1 | classdef meta_ev < class_conveniences | classdef meta_ev < class_conveniences |
2 | % convenience class for postprocessing entanglement_evaluations | ||
3 | % collects many ev-objects in a 2D-grid and | ||
4 | % - provides methods for batch loading and saving them | ||
5 | % - organizes them suitably | ||
6 | % - provides methods for plotting from those | ||
7 | |||
8 | properties | ||
9 | evaluations@cell % cell array of entanglment_evaluation-objects | ||
10 | ev_files@cell % cell array with paths to the ev.mat-files for individual evaluations | ||
11 | param_names@cell % cell array of parameter names (read from meta_data_file) | ||
12 | params@cell % cell array of parameter arrays (params{1} corresponds to param_names{1}) | ||
13 | meta_label = '' % string describing the evaluation (could be 'traced_out_2' e.g.) | ||
14 | meta_title = '' % optional: string used as title string for plots | ||
15 | models@cell | ||
16 | end | ||
17 | properties(Dependent) | ||
18 | dimensions@double vector % dimensions of evaluations-vector or -matrix | ||
19 | gridtype % string: 'vector' or 'matrix' describing type of grid | ||
20 | evaluations_no@double % number of evaluations | ||
21 | opt_logneg_corrected@cell % cell array (index corresponding to tracepair) of optimal entanglement | ||
22 | opt_pulse_gammas@cell % cell array (index corresponding to tracepair) of optimal pulse gammas | ||
23 | tracepairs_no@double % number of tracepairs used for each evaluation (enforced to be the same) | ||
24 | common@struct % struct which contains all those evaluation_properties which are shared by all evaluations | ||
25 | common_path % longest path which is a parentdir to all ev_files | ||
26 | end | ||
27 | properties(Dependent, Hidden) | ||
28 | opt_logneg_corrected_interp@cell % cell array of interpolated optimal entanglement | ||
29 | opt_pulse_gammas_interp@cell % cell array of interpolated optimal pulse gammas | ||
30 | ev_dirs@cell = {} % cell array with directories containing the ev.mat-files for individual evaluations | ||
31 | end | ||
32 | properties(Hidden) | ||
33 | params_interp@cell % cell array of interpolated parameter values | ||
34 | opt_logneg_corrected_interp_private@cell = {} % ... to avoid unnecessary recomputation ... | ||
35 | opt_pulse_gammas_interp_private@cell = {} % ... to avoid unnecessary recomputation ... | ||
36 | common_private@struct = struct() % ... to avoid unnecessary recomputation ... | ||
37 | ln_fig = [] % figure handle for internally generated plot logneg vs gamma | ||
38 | ln_cont_fig = [] % figure handle for internally generated contour plot of opt. logneg | ||
39 | ln_cut_fig = [] % figure handle for internally generated cut plot of opt. logneg | ||
40 | pw_cont_fig = [] % figure handle for internally generated contour plot of opt. pulse width | ||
41 | pw_cut_fig = [] % figure handle for internally generated cut plot of opt. pulse width | ||
42 | fig_label = '' % additional label to distinguish plots when saving | ||
43 | end | ||
44 | methods | ||
45 | %%% CONSTRUCTOR %%% | ||
2 | % convenience class for postprocessing entanglement_evaluations | ||
3 | % collects many ev-objects in a 2D-grid and | ||
4 | % - provides methods for batch loading and saving them | ||
5 | % - organizes them suitably | ||
6 | % - provides methods for plotting from those | ||
7 | |||
8 | properties | ||
9 | evaluations@cell % cell array of entanglment_evaluation-objects | ||
10 | ev_files@cell % cell array with paths to the ev.mat-files for individual evaluations | ||
11 | param_names@cell % cell array of parameter names (read from meta_data_file) | ||
12 | params@cell % cell array of parameter arrays (params{1} corresponds to param_names{1}) | ||
13 | meta_label = '' % string describing the evaluation (could be 'traced_out_2' e.g.) | ||
14 | meta_title = '' % optional: string used as title string for plots | ||
15 | models@cell | ||
16 | end | ||
17 | properties(Dependent) | ||
18 | dimensions@double vector % dimensions of evaluations-vector or -matrix | ||
19 | gridtype % string: 'vector' or 'matrix' describing type of grid | ||
20 | evaluations_no@double % number of evaluations | ||
21 | opt_logneg_corrected@cell % cell array (index corresponding to tracepair) of optimal entanglement | ||
22 | opt_pulse_gammas@cell % cell array (index corresponding to tracepair) of optimal pulse gammas | ||
23 | tracepairs_no@double % number of tracepairs used for each evaluation (enforced to be the same) | ||
24 | common@struct % struct which contains all those evaluation_properties which are shared by all evaluations | ||
25 | common_path % longest path which is a parentdir to all ev_files | ||
26 | end | ||
27 | properties(Dependent, Hidden) | ||
28 | opt_logneg_corrected_interp@cell % cell array of interpolated optimal entanglement | ||
29 | opt_pulse_gammas_interp@cell % cell array of interpolated optimal pulse gammas | ||
30 | ev_dirs@cell = {} % cell array with directories containing the ev.mat-files for individual evaluations | ||
31 | end | ||
32 | properties(Hidden) | ||
33 | params_interp@cell % cell array of interpolated parameter values | ||
34 | opt_logneg_corrected_interp_private@cell = {} % ... to avoid unnecessary recomputation ... | ||
35 | opt_pulse_gammas_interp_private@cell = {} % ... to avoid unnecessary recomputation ... | ||
36 | common_private@struct = struct() % ... to avoid unnecessary recomputation ... | ||
37 | ln_fig = [] % figure handle for internally generated plot logneg vs gamma | ||
38 | ln_cont_fig = [] % figure handle for internally generated contour plot of opt. logneg | ||
39 | ln_cut_fig = [] % figure handle for internally generated cut plot of opt. logneg | ||
40 | pw_cont_fig = [] % figure handle for internally generated contour plot of opt. pulse width | ||
41 | pw_cut_fig = [] % figure handle for internally generated cut plot of opt. pulse width | ||
42 | fig_label = '' % additional label to distinguish plots when saving | ||
43 | end | ||
44 | methods | ||
45 | %%% CONSTRUCTOR %%% | ||
46 | 46 | function meta = meta_ev(varargin) | function meta = meta_ev(varargin) |
47 | if length(varargin)==1 | ||
48 | meta_data_file = varargin{1}; | ||
49 | meta.get_meta_data(meta_data_file); | ||
50 | meta.load_evaluations; | ||
51 | elseif length(varargin)>1 | ||
52 | error('Expect at most one varargin-argument in constructor of meta-ev-class.') | ||
53 | end | ||
47 | if length(varargin)==1 | ||
48 | meta_data_file = varargin{1}; | ||
49 | meta.get_meta_data(meta_data_file); | ||
50 | meta.load_evaluations; | ||
51 | elseif length(varargin)>1 | ||
52 | error('Expect at most one varargin-argument in constructor of meta-ev-class.') | ||
53 | end | ||
54 | 54 | end | end |
55 | 55 | %%% | %%% |
56 | 56 | ||
57 | function load_evaluations(meta) | ||
58 | meta.gridtype; | ||
59 | % call meta.gridtype to guarantee error is thrown if gridtype is unsupported | ||
60 | |||
61 | meta.reset; % clear previous postprocessing results | ||
62 | evaluations = cell(meta.dimensions); | ||
63 | for k=1:meta.evaluations_no | ||
64 | ev = load(meta.ev_files{k}); ev = ev.ev; | ||
65 | evaluations{k} = ev; | ||
66 | end | ||
67 | meta.evaluations = evaluations; | ||
57 | function load_evaluations(meta) | ||
58 | meta.gridtype; | ||
59 | % call meta.gridtype to guarantee error is thrown if gridtype is unsupported | ||
60 | |||
61 | meta.reset; % clear previous postprocessing results | ||
62 | evaluations = cell(meta.dimensions); | ||
63 | for k=1:meta.evaluations_no | ||
64 | ev = load(meta.ev_files{k}); ev = ev.ev; | ||
65 | evaluations{k} = ev; | ||
66 | end | ||
67 | meta.evaluations = evaluations; | ||
68 | end | ||
69 | function load_models(meta) | ||
70 | meta.models = cell(meta.dimensions); | ||
71 | for k=1:meta.evaluations_no | ||
72 | try | ||
73 | model = load(fullfile(meta.ev_dirs{k}, 'model.mat')); model = model.model; | ||
74 | meta.models{k} = model; | ||
75 | end | ||
76 | end | ||
68 | 77 | end | end |
69 | function load_models(meta) | ||
70 | meta.models = cell(meta.dimensions); | ||
71 | for k=1:meta.evaluations_no | ||
72 | try | ||
73 | model = load(fullfile(meta.ev_dirs{k}, 'model.mat')); model = model.model; | ||
74 | meta.models{k} = model; | ||
75 | end | ||
76 | end | ||
77 | end | ||
78 | 78 | function meta_traced = trace_out(meta, mode_indices) | function meta_traced = trace_out(meta, mode_indices) |
79 | % return a version of meta-ev in which all light modes | ||
80 | % which correspond to the mechanical modes specified in modes_to_trace | ||
81 | % have been traced out. That is for which the interesting quantities | ||
82 | % logneg, physicality, covariance matrices have been recalculated appropriately | ||
83 | meta_traced = meta.copy; | ||
84 | meta_traced.reset; | ||
85 | for k=1:meta.evaluations_no | ||
86 | meta_traced.evaluations{k} = meta.evaluations{k}.trace_out(mode_indices); | ||
87 | end | ||
79 | % return a version of meta-ev in which all light modes | ||
80 | % which correspond to the mechanical modes specified in modes_to_trace | ||
81 | % have been traced out. That is for which the interesting quantities | ||
82 | % logneg, physicality, covariance matrices have been recalculated appropriately | ||
83 | meta_traced = meta.copy; | ||
84 | meta_traced.reset; | ||
85 | for k=1:meta.evaluations_no | ||
86 | meta_traced.evaluations{k} = meta.evaluations{k}.trace_out(mode_indices); | ||
87 | end | ||
88 | 88 | end | end |
89 | 89 | function restrict_pulse_gammas(meta,gamma_min, gamma_max) | function restrict_pulse_gammas(meta,gamma_min, gamma_max) |
90 | for k=1:meta.evaluations_no | ||
91 | ev = meta.evaluations{k}; | ||
92 | pulse_gammas = ev.pulse_gammas; | ||
93 | allowed_indices = intersect(find(pulse_gammas >= gamma_min),... | ||
94 | find(pulse_gammas <= gamma_max)); | ||
95 | ev.pulse_gammas = pulse_gammas(allowed_indices); | ||
96 | for l=1:numel(ev.logneg_corrected) | ||
97 | ln = ev.logneg_corrected{l}; | ||
98 | ev.logneg_corrected{l} = {ln{allowed_indices}}; | ||
99 | end | ||
100 | ev.calulate_optimal_entanglement; | ||
101 | end | ||
102 | meta.reset; | ||
90 | for k=1:meta.evaluations_no | ||
91 | ev = meta.evaluations{k}; | ||
92 | pulse_gammas = ev.pulse_gammas; | ||
93 | allowed_indices = intersect(find(pulse_gammas >= gamma_min),... | ||
94 | find(pulse_gammas <= gamma_max)); | ||
95 | ev.pulse_gammas = pulse_gammas(allowed_indices); | ||
96 | for l=1:numel(ev.logneg_corrected) | ||
97 | ln = ev.logneg_corrected{l}; | ||
98 | ev.logneg_corrected{l} = {ln{allowed_indices}}; | ||
99 | end | ||
100 | ev.calulate_optimal_entanglement; | ||
101 | end | ||
102 | meta.reset; | ||
103 | 103 | end | end |
104 | 104 | function reset(meta) | function reset(meta) |
105 | meta.reset_hidden_props; | ||
105 | meta.reset_hidden_props; | ||
106 | 106 | end | end |
107 | 107 | function meta_filtered = filter_params(meta, param_ind, param_values) | function meta_filtered = filter_params(meta, param_ind, param_values) |
108 | % param_ind determines the parameter to keep fixed | ||
109 | params_uniqe = unique(meta.params{param_ind}); | ||
110 | indices = []; | ||
111 | for val = param_values(:)' | ||
112 | [~,ind] = min(abs(params_uniqe - val)); | ||
113 | params_uniqe(ind) = NaN; | ||
114 | indices = [indices, ind]; | ||
115 | end | ||
116 | if param_ind==1 | ||
117 | myfilter = @(array) array(:,indices); | ||
118 | elseif param_ind==2 | ||
119 | myfilter = @(array) array(indices,:); | ||
120 | end | ||
108 | % param_ind determines the parameter to keep fixed | ||
109 | params_uniqe = unique(meta.params{param_ind}); | ||
110 | indices = []; | ||
111 | for val = param_values(:)' | ||
112 | [~,ind] = min(abs(params_uniqe - val)); | ||
113 | params_uniqe(ind) = NaN; | ||
114 | indices = [indices, ind]; | ||
115 | end | ||
116 | if param_ind==1 | ||
117 | myfilter = @(array) array(:,indices); | ||
118 | elseif param_ind==2 | ||
119 | myfilter = @(array) array(indices,:); | ||
120 | end | ||
121 | 121 | ||
122 | meta_filtered = meta.copy; | ||
123 | meta_filtered.reset; | ||
124 | for field={'evaluations', 'ev_files', 'models'}; | ||
125 | if ~isempty(meta.(field{:})) | ||
126 | meta_filtered.(field{:}) = myfilter(meta.(field{:})); | ||
127 | end | ||
128 | end | ||
129 | for k=1:length(meta.params) | ||
130 | meta_filtered.params{k} = myfilter(meta.params{k}); | ||
131 | end | ||
132 | end | ||
122 | meta_filtered = meta.copy; | ||
123 | meta_filtered.reset; | ||
124 | for field={'evaluations', 'ev_files', 'models'}; | ||
125 | if ~isempty(meta.(field{:})) | ||
126 | meta_filtered.(field{:}) = myfilter(meta.(field{:})); | ||
127 | end | ||
128 | end | ||
129 | for k=1:length(meta.params) | ||
130 | meta_filtered.params{k} = myfilter(meta.params{k}); | ||
131 | end | ||
132 | end | ||
133 | 133 | function cellarray = for_each_evaluation(meta, fieldname, varargin) | function cellarray = for_each_evaluation(meta, fieldname, varargin) |
134 | if length(varargin) > 0 | ||
135 | assert(length(varargin)==1); | ||
136 | index = varargin{1}; | ||
137 | get_element = @(array)array(index); | ||
138 | else | ||
139 | get_element = @(x) x; | ||
140 | end | ||
141 | get_field = @(ev)get_element(getfield(ev, fieldname)); | ||
134 | if length(varargin) > 0 | ||
135 | assert(length(varargin)==1); | ||
136 | index = varargin{1}; | ||
137 | get_element = @(array)array(index); | ||
138 | else | ||
139 | get_element = @(x) x; | ||
140 | end | ||
141 | get_field = @(ev)get_element(getfield(ev, fieldname)); | ||
142 | 142 | ||
143 | cellarray = cell(meta.dimensions); | ||
144 | for k=1:meta.evaluations_no | ||
145 | cellarray{k} = get_field(meta.evaluations{k}); | ||
146 | end | ||
143 | cellarray = cell(meta.dimensions); | ||
144 | for k=1:meta.evaluations_no | ||
145 | cellarray{k} = get_field(meta.evaluations{k}); | ||
146 | end | ||
147 | end | ||
148 | function set_default_sample_no(meta, default_sample_no) | ||
149 | for k=1:meta.evaluations_no | ||
150 | for l=1:meta.evaluations{k}.tracepairs_no | ||
151 | meta.evaluations{k}.measurement.homotraces(l,1).default_sample_no = default_sample_no; | ||
152 | meta.evaluations{k}.measurement.homotraces(l,2).default_sample_no = default_sample_no; | ||
153 | end | ||
154 | end | ||
155 | end | ||
156 | function save_figs(meta) | ||
157 | meta.my_save_fig(meta.ln_fig, 'ln_versus_gamma'); meta.ln_fig = []; | ||
158 | meta.my_save_fig(meta.ln_cont_fig, 'lnopt'); meta.ln_cont_fig = []; | ||
159 | meta.my_save_fig(meta.pw_cont_fig, 'pwopt'); meta.pw_cont_fig = []; | ||
160 | meta.my_save_fig(meta.ln_cut_fig, 'lnopt_cut'); meta.ln_cut_fig = []; | ||
161 | meta.my_save_fig(meta.pw_cut_fig, 'pwopt_cut'); meta.pw_cut_fig = []; | ||
147 | 162 | end | end |
148 | function set_default_sample_no(meta, default_sample_no) | ||
149 | for k=1:meta.evaluations_no | ||
150 | for l=1:meta.evaluations{k}.tracepairs_no | ||
151 | meta.evaluations{k}.measurement.homotraces(l,1).default_sample_no = default_sample_no; | ||
152 | meta.evaluations{k}.measurement.homotraces(l,2).default_sample_no = default_sample_no; | ||
153 | end | ||
154 | end | ||
155 | end | ||
156 | function save_figs(meta) | ||
157 | meta.my_save_fig(meta.ln_fig, 'ln_versus_gamma'); meta.ln_fig = []; | ||
158 | meta.my_save_fig(meta.ln_cont_fig, 'lnopt'); meta.ln_cont_fig = []; | ||
159 | meta.my_save_fig(meta.pw_cont_fig, 'pwopt'); meta.pw_cont_fig = []; | ||
160 | meta.my_save_fig(meta.ln_cut_fig, 'lnopt_cut'); meta.ln_cut_fig = []; | ||
161 | meta.my_save_fig(meta.pw_cut_fig, 'pwopt_cut'); meta.pw_cut_fig = []; | ||
162 | end | ||
163 | 163 | ||
164 | %% GETTERS | ||
165 | function dimensions = get.dimensions(meta) | ||
164 | %% GETTERS | ||
165 | function dimensions = get.dimensions(meta) | ||
166 | 166 | dimensions = size(meta.ev_files); | dimensions = size(meta.ev_files); |
167 | 167 | end | end |
168 | 168 | function gridtype = get.gridtype(meta) | function gridtype = get.gridtype(meta) |
169 | switch sum(meta.dimensions>1) | ||
170 | case 1 | ||
171 | gridtype = 'vector'; | ||
172 | case 2 | ||
173 | gridtype = 'matrix'; | ||
174 | otherwise | ||
175 | error('meta_ev:gridtype:unsupported','Unsupported grid-type.') | ||
176 | end | ||
177 | end | ||
178 | function evaluations_no = get.evaluations_no(meta) | ||
169 | switch sum(meta.dimensions>1) | ||
170 | case 1 | ||
171 | gridtype = 'vector'; | ||
172 | case 2 | ||
173 | gridtype = 'matrix'; | ||
174 | otherwise | ||
175 | error('meta_ev:gridtype:unsupported','Unsupported grid-type.') | ||
176 | end | ||
177 | end | ||
178 | function evaluations_no = get.evaluations_no(meta) | ||
179 | 179 | evaluations_no = numel(meta.ev_files); | evaluations_no = numel(meta.ev_files); |
180 | 180 | end | end |
181 | function tracepairs_no = get.tracepairs_no(meta) | ||
181 | function tracepairs_no = get.tracepairs_no(meta) | ||
182 | 182 | tracepairs_no = meta.common.tracepairs_no; | tracepairs_no = meta.common.tracepairs_no; |
183 | 183 | end | end |
184 | function opt_logneg_corrected = get.opt_logneg_corrected(meta) | ||
185 | opt_logneg_corrected = cell([1, meta.tracepairs_no]); | ||
186 | for k=1:meta.tracepairs_no | ||
187 | opt_logneg_corrected{k} = cell2mat(meta.for_each_evaluation('opt_logneg_corrected', k)); | ||
188 | end | ||
184 | function opt_logneg_corrected = get.opt_logneg_corrected(meta) | ||
185 | opt_logneg_corrected = cell([1, meta.tracepairs_no]); | ||
186 | for k=1:meta.tracepairs_no | ||
187 | opt_logneg_corrected{k} = cell2mat(meta.for_each_evaluation('opt_logneg_corrected', k)); | ||
188 | end | ||
189 | end | ||
190 | function opt_pulse_gammas = get.opt_pulse_gammas(meta) | ||
191 | opt_pulse_gammas = cell([1, meta.tracepairs_no]); | ||
192 | for k=1:meta.tracepairs_no | ||
193 | opt_pulse_gammas{k} = cell2mat(meta.for_each_evaluation('opt_pulse_gammas', k)); | ||
194 | end | ||
189 | 195 | end | end |
190 | function opt_pulse_gammas = get.opt_pulse_gammas(meta) | ||
191 | opt_pulse_gammas = cell([1, meta.tracepairs_no]); | ||
192 | for k=1:meta.tracepairs_no | ||
193 | opt_pulse_gammas{k} = cell2mat(meta.for_each_evaluation('opt_pulse_gammas', k)); | ||
194 | end | ||
195 | end | ||
196 | function opt_logneg_corrected_interp = get.opt_logneg_corrected_interp(meta) | ||
197 | if isempty(meta.opt_logneg_corrected_interp_private) | ||
198 | opt_logneg_corrected_interp = cell([1, meta.tracepairs_no]); | ||
199 | for k=1:meta.tracepairs_no | ||
200 | opt_logneg_corrected_interp{k} = meta.interpolate_ln_pw(meta.opt_logneg_corrected{k}); | ||
201 | end | ||
202 | meta.opt_logneg_corrected_interp_private = opt_logneg_corrected_interp; | ||
203 | else | ||
204 | opt_logneg_corrected_interp = meta.opt_logneg_corrected_interp_private; | ||
205 | end | ||
196 | function opt_logneg_corrected_interp = get.opt_logneg_corrected_interp(meta) | ||
197 | if isempty(meta.opt_logneg_corrected_interp_private) | ||
198 | opt_logneg_corrected_interp = cell([1, meta.tracepairs_no]); | ||
199 | for k=1:meta.tracepairs_no | ||
200 | opt_logneg_corrected_interp{k} = meta.interpolate_ln_pw(meta.opt_logneg_corrected{k}); | ||
201 | end | ||
202 | meta.opt_logneg_corrected_interp_private = opt_logneg_corrected_interp; | ||
203 | else | ||
204 | opt_logneg_corrected_interp = meta.opt_logneg_corrected_interp_private; | ||
205 | end | ||
206 | 206 | end | end |
207 | function opt_pulse_gammas_interp = get.opt_pulse_gammas_interp(meta) | ||
208 | if isempty(meta.opt_pulse_gammas_interp_private) | ||
209 | opt_pulse_gammas_interp = cell([1, meta.tracepairs_no]); | ||
210 | for k=1:meta.tracepairs_no | ||
211 | opt_pulse_gammas_interp{k} = meta.interpolate_ln_pw(meta.opt_pulse_gammas{k}); | ||
212 | end | ||
213 | meta.opt_pulse_gammas_interp_private = opt_pulse_gammas_interp; | ||
214 | else | ||
215 | opt_pulse_gammas_interp = meta.opt_pulse_gammas_interp_private; | ||
216 | end | ||
207 | function opt_pulse_gammas_interp = get.opt_pulse_gammas_interp(meta) | ||
208 | if isempty(meta.opt_pulse_gammas_interp_private) | ||
209 | opt_pulse_gammas_interp = cell([1, meta.tracepairs_no]); | ||
210 | for k=1:meta.tracepairs_no | ||
211 | opt_pulse_gammas_interp{k} = meta.interpolate_ln_pw(meta.opt_pulse_gammas{k}); | ||
212 | end | ||
213 | meta.opt_pulse_gammas_interp_private = opt_pulse_gammas_interp; | ||
214 | else | ||
215 | opt_pulse_gammas_interp = meta.opt_pulse_gammas_interp_private; | ||
216 | end | ||
217 | end | ||
218 | function common = get.common(meta) | ||
219 | if isempty(fieldnames(meta.common_private)) | ||
220 | fields = {'inverted_evaluation';... | ||
221 | 'mech_frequencies'; 'mech_frequencies_no';... | ||
222 | 'pulse_gammas'; 'pulse_gammas_no'; 'pulse_widths';... | ||
223 | 'detection_efficiency'; 'homodyne_visibility';... | ||
224 | 'pulse_pairs_coverage'; 'pulse_pairs_per_trace'; 'pulse_duration_seconds';... | ||
225 | 'samplingrate'; 'samples_per_trace'; 'samples_per_pulse';... | ||
226 | 'tracepairs_no'; 'signal_power_muW'}; | ||
227 | for k=1:numel(fields) | ||
228 | field = fields{k}; | ||
229 | try | ||
230 | values = meta.for_each_evaluation(field); | ||
231 | equal_to_first = @(value)isequal(value, values{1}); | ||
232 | all_equal = all(cellfun(equal_to_first, values)); | ||
233 | if all_equal | ||
234 | common.(field) = values{1}; | ||
235 | else | ||
236 | common.(field) = 'values differ'; | ||
237 | end | ||
238 | catch | ||
239 | common.(field) = NaN; | ||
240 | end | ||
241 | end | ||
242 | meta.common_private = common; | ||
243 | else | ||
244 | common = meta.common_private; | ||
245 | end | ||
246 | end | ||
247 | function common_path = get.common_path(meta) | ||
248 | ev_files = {meta.ev_files{:}}; | ||
249 | test_path = ev_files{1}; | ||
250 | splitindices = strfind(test_path,'/'); | ||
251 | for k=1:length(splitindices) | ||
252 | inds = 1:splitindices(k); | ||
253 | testfun = @(str)isequal(str(inds), test_path(inds)); | ||
254 | if all(cellfun(testfun, ev_files)) | ||
255 | common_path = test_path(inds); | ||
256 | end | ||
257 | end | ||
258 | end | ||
259 | function ev_dirs = get.ev_dirs(meta) | ||
260 | ev_dirs = cell(meta.dimensions); | ||
261 | for k=1:meta.evaluations_no | ||
262 | ev_dirs{k} = fileparts(meta.ev_files{k}); | ||
263 | end | ||
264 | end | ||
265 | end | ||
266 | methods(Hidden) | ||
267 | function reset_hidden_props(meta) | ||
268 | meta.params_interp = {}; | ||
269 | meta.opt_logneg_corrected_interp_private = {}; | ||
270 | meta.opt_pulse_gammas_interp_private = {}; | ||
271 | meta.common_private = struct(); | ||
272 | end | ||
273 | function ln_or_pw_interp = interpolate_ln_pw(meta, ln_or_pw, varargin) | ||
274 | refinement_factor = 5; | ||
275 | if length(varargin)>0 | ||
276 | refinement_factor = varargin{1}; | ||
277 | end | ||
278 | switch meta.gridtype | ||
279 | case 'vector' | ||
280 | error('not implemented') | ||
281 | case 'matrix' | ||
282 | X = meta.params{1}; | ||
283 | Xq = interp2(X,refinement_factor); | ||
284 | meta.params_interp{1} = Xq; | ||
285 | Y = meta.params{2}; | ||
286 | Yq = interp2(Y,refinement_factor); | ||
287 | meta.params_interp{2} = Yq; | ||
288 | ln_or_pw_interp = interp2(X,Y,ln_or_pw,Xq,Yq,'linear'); % other options: 'splines', 'linear' | ||
289 | end | ||
290 | end | ||
291 | function fig_path = my_save_fig(meta, fig_handle, fig_name) | ||
292 | if ~isempty(fig_handle) | ||
293 | label = ''; | ||
294 | if ~isempty(meta.fig_label) | ||
295 | label = [label,'__', meta.fig_label]; | ||
296 | end | ||
297 | if ~isempty(meta.meta_label) | ||
298 | label = [label,'__', meta.meta_label]; | ||
299 | end | ||
300 | meta.fig_label = ''; % reset fig_label after usage | ||
301 | fig_path = fullfile(meta.common_path, [fig_name, label]); | ||
302 | disp(['saving figures to ', fig_path, ' .fig / .pdf']); | ||
303 | saveas(fig_handle, fig_path, 'fig'); | ||
304 | saveas(fig_handle, fig_path, 'pdf'); | ||
305 | close(fig_handle); | ||
306 | try | ||
307 | [stat,stdout] = system(['pdfcrop ', fig_path,'.pdf ', fig_path,'.pdf']); | ||
308 | end | ||
309 | end | ||
310 | end | ||
311 | function my_postprocess_plot(meta, fig_handle) | ||
312 | figure(fig_handle); | ||
313 | title(tex_escape(sentence_case(meta.meta_title))); | ||
314 | grid | ||
217 | 315 | end | end |
218 | function common = get.common(meta) | ||
219 | if isempty(fieldnames(meta.common_private)) | ||
220 | fields = {'inverted_evaluation';... | ||
221 | 'mech_frequencies'; 'mech_frequencies_no';... | ||
222 | 'pulse_gammas'; 'pulse_gammas_no'; 'pulse_widths';... | ||
223 | 'detection_efficiency'; 'homodyne_visibility';... | ||
224 | 'pulse_pairs_coverage'; 'pulse_pairs_per_trace'; 'pulse_duration_seconds';... | ||
225 | 'samplingrate'; 'samples_per_trace'; 'samples_per_pulse';... | ||
226 | 'tracepairs_no'; 'signal_power_muW'}; | ||
227 | for k=1:numel(fields) | ||
228 | field = fields{k}; | ||
229 | try | ||
230 | values = meta.for_each_evaluation(field); | ||
231 | equal_to_first = @(value)isequal(value, values{1}); | ||
232 | all_equal = all(cellfun(equal_to_first, values)); | ||
233 | if all_equal | ||
234 | common.(field) = values{1}; | ||
235 | else | ||
236 | common.(field) = 'values differ'; | ||
237 | end | ||
238 | catch | ||
239 | common.(field) = NaN; | ||
240 | end | ||
241 | end | ||
242 | meta.common_private = common; | ||
243 | else | ||
244 | common = meta.common_private; | ||
245 | end | ||
246 | end | ||
247 | function common_path = get.common_path(meta) | ||
248 | ev_files = {meta.ev_files{:}}; | ||
249 | test_path = ev_files{1}; | ||
250 | splitindices = strfind(test_path,'/'); | ||
251 | for k=1:length(splitindices) | ||
252 | inds = 1:splitindices(k); | ||
253 | testfun = @(str)isequal(str(inds), test_path(inds)); | ||
254 | if all(cellfun(testfun, ev_files)) | ||
255 | common_path = test_path(inds); | ||
256 | end | ||
257 | end | ||
258 | end | ||
259 | function ev_dirs = get.ev_dirs(meta) | ||
260 | ev_dirs = cell(meta.dimensions); | ||
261 | for k=1:meta.evaluations_no | ||
262 | ev_dirs{k} = fileparts(meta.ev_files{k}); | ||
263 | end | ||
264 | end | ||
265 | end | ||
266 | methods(Hidden) | ||
267 | function reset_hidden_props(meta) | ||
268 | meta.params_interp = {}; | ||
269 | meta.opt_logneg_corrected_interp_private = {}; | ||
270 | meta.opt_pulse_gammas_interp_private = {}; | ||
271 | meta.common_private = struct(); | ||
272 | end | ||
273 | function ln_or_pw_interp = interpolate_ln_pw(meta, ln_or_pw, varargin) | ||
274 | refinement_factor = 5; | ||
275 | if length(varargin)>0 | ||
276 | refinement_factor = varargin{1}; | ||
277 | end | ||
278 | switch meta.gridtype | ||
279 | case 'vector' | ||
280 | error('not implemented') | ||
281 | case 'matrix' | ||
282 | X = meta.params{1}; | ||
283 | Xq = interp2(X,refinement_factor); | ||
284 | meta.params_interp{1} = Xq; | ||
285 | Y = meta.params{2}; | ||
286 | Yq = interp2(Y,refinement_factor); | ||
287 | meta.params_interp{2} = Yq; | ||
288 | ln_or_pw_interp = interp2(X,Y,ln_or_pw,Xq,Yq,'linear'); % other options: 'splines', 'linear' | ||
289 | end | ||
290 | end | ||
291 | function fig_path = my_save_fig(meta, fig_handle, fig_name) | ||
292 | if ~isempty(fig_handle) | ||
293 | label = ''; | ||
294 | if ~isempty(meta.fig_label) | ||
295 | label = [label,'__', meta.fig_label]; | ||
296 | end | ||
297 | if ~isempty(meta.meta_label) | ||
298 | label = [label,'__', meta.meta_label]; | ||
299 | end | ||
300 | meta.fig_label = ''; % reset fig_label after usage | ||
301 | fig_path = fullfile(meta.common_path, [fig_name, label]); | ||
302 | disp(['saving figures to ', fig_path, ' .fig / .pdf']); | ||
303 | saveas(fig_handle, fig_path, 'fig'); | ||
304 | saveas(fig_handle, fig_path, 'pdf'); | ||
305 | close(fig_handle); | ||
306 | try | ||
307 | [stat,stdout] = system(['pdfcrop ', fig_path,'.pdf ', fig_path,'.pdf']); | ||
308 | end | ||
309 | end | ||
310 | end | ||
311 | function my_postprocess_plot(meta, fig_handle) | ||
312 | figure(fig_handle); | ||
313 | title(tex_escape(sentence_case(meta.meta_title))); | ||
314 | grid | ||
315 | end | ||
316 | 316 | end | end |
317 | 317 | methods(Hidden, Static) | methods(Hidden, Static) |
318 | function [x_data, y_data, z_data] = limit_x_and_y(x_data_in, y_data_in, z_data_in, x_lims, y_lims) | ||
319 | if isempty(x_lims); x_lims = [-inf, inf]; end | ||
320 | if isempty(y_lims); y_lims = [-inf, inf]; end | ||
318 | function [x_data, y_data, z_data] = limit_x_and_y(x_data_in, y_data_in, z_data_in, x_lims, y_lims) | ||
319 | if isempty(x_lims); x_lims = [-inf, inf]; end | ||
320 | if isempty(y_lims); y_lims = [-inf, inf]; end | ||
321 | 321 | ||
322 | x_allowed = intersect(find(x_data_in>=min(x_lims)), find(x_data_in<=max(x_lims))); | ||
323 | y_allowed = intersect(find(y_data_in>=min(y_lims)), find(y_data_in<=max(y_lims))); | ||
324 | allowed = intersect(x_allowed, y_allowed); | ||
325 | [allowed_x, allowed_y] = ind2sub(size(x_data_in), allowed); | ||
326 | x_min_ind = min(allowed_x); | ||
327 | x_max_ind = max(allowed_x); | ||
328 | y_min_ind = min(allowed_y); | ||
329 | y_max_ind = max(allowed_y); | ||
330 | x_data = x_data_in(x_min_ind:x_max_ind, y_min_ind:y_max_ind); | ||
331 | y_data = y_data_in(x_min_ind:x_max_ind, y_min_ind:y_max_ind); | ||
332 | z_data = z_data_in(x_min_ind:x_max_ind, y_min_ind:y_max_ind); | ||
333 | end | ||
334 | function xylims(x_lims, y_lims) | ||
335 | if ~isempty(x_lims); xlim(x_lims); end | ||
336 | if ~isempty(y_lims); ylim(y_lims); end | ||
337 | end | ||
338 | end | ||
322 | x_allowed = intersect(find(x_data_in>=min(x_lims)), find(x_data_in<=max(x_lims))); | ||
323 | y_allowed = intersect(find(y_data_in>=min(y_lims)), find(y_data_in<=max(y_lims))); | ||
324 | allowed = intersect(x_allowed, y_allowed); | ||
325 | [allowed_x, allowed_y] = ind2sub(size(x_data_in), allowed); | ||
326 | x_min_ind = min(allowed_x); | ||
327 | x_max_ind = max(allowed_x); | ||
328 | y_min_ind = min(allowed_y); | ||
329 | y_max_ind = max(allowed_y); | ||
330 | x_data = x_data_in(x_min_ind:x_max_ind, y_min_ind:y_max_ind); | ||
331 | y_data = y_data_in(x_min_ind:x_max_ind, y_min_ind:y_max_ind); | ||
332 | z_data = z_data_in(x_min_ind:x_max_ind, y_min_ind:y_max_ind); | ||
333 | end | ||
334 | function xylims(x_lims, y_lims) | ||
335 | if ~isempty(x_lims); xlim(x_lims); end | ||
336 | if ~isempty(y_lims); ylim(y_lims); end | ||
337 | end | ||
338 | end | ||
339 | 339 | end | end |
File data_analysis/@meta_ev/plot_cuts.m changed (mode: 100644) (index 9dcb9bd..30cd24e) | |||
1 | 1 | function plot_cuts(meta, plot_type, tracepairs_ind, par_ind, par_vals, varargin) | function plot_cuts(meta, plot_type, tracepairs_ind, par_ind, par_vals, varargin) |
2 | assertEqual(meta.gridtype,'matrix',... | ||
3 | 'only implemented for gridtype "matrix"') | ||
4 | if isequal(par_vals, 'all') | ||
5 | meta_filtered = meta.copy; | ||
6 | else | ||
7 | meta_filtered = meta.filter_params(par_ind, par_vals); | ||
8 | end | ||
2 | assertEqual(meta.gridtype,'matrix',... | ||
3 | 'only implemented for gridtype "matrix"') | ||
4 | if isequal(par_vals, 'all') | ||
5 | meta_filtered = meta.copy; | ||
6 | else | ||
7 | meta_filtered = meta.filter_params(par_ind, par_vals); | ||
8 | end | ||
9 | 9 | ||
10 | switch lower(plot_type) | ||
11 | case {'logneg', 'opt_log_neg', 'entanglement'} | ||
12 | display_name = 'Max. log. negativity'; | ||
13 | fig_handle = 'ln_cut_fig'; | ||
14 | y_data = meta_filtered.opt_logneg_corrected{tracepairs_ind}; | ||
15 | cmap = flipud(cbrewer('div','RdBu',512)); | ||
16 | case {'pulsewidth', 'opt_pulse_gamma', 'opt_pulsewidth'} | ||
17 | display_name = 'Optimal pulse width [kHz]'; | ||
18 | fig_handle = 'pw_cut_fig'; | ||
19 | y_data = meta_filtered.opt_pulse_gammas{tracepairs_ind}/1E3; | ||
20 | cmap = cbrewer('seq','Blues',512); | ||
21 | otherwise | ||
22 | error(['Unsupported plottype: ', plot_type]); | ||
10 | switch lower(plot_type) | ||
11 | case {'logneg', 'opt_log_neg', 'entanglement'} | ||
12 | display_name = 'Max. log. negativity'; | ||
13 | fig_handle = 'ln_cut_fig'; | ||
14 | y_data = meta_filtered.opt_logneg_corrected{tracepairs_ind}; | ||
15 | cmap = flipud(cbrewer('div','RdBu',512)); | ||
16 | case {'pulsewidth', 'opt_pulse_gamma', 'opt_pulsewidth'} | ||
17 | display_name = 'Optimal pulse width [kHz]'; | ||
18 | fig_handle = 'pw_cut_fig'; | ||
19 | y_data = meta_filtered.opt_pulse_gammas{tracepairs_ind}/1E3; | ||
20 | cmap = cbrewer('seq','Blues',512); | ||
21 | otherwise | ||
22 | error(['Unsupported plottype: ', plot_type]); | ||
23 | 23 | end | end |
24 | 24 | ||
25 | x_scale = 'lin'; y_scale = 'lin'; | ||
26 | x_lims = []; y_lims = []; | ||
27 | fig = []; | ||
28 | linestyle = 'o:'; | ||
29 | colororder = []; | ||
30 | legend_postfix = ''; | ||
31 | legend_location = 'Best'; | ||
32 | for k=1:2:length(varargin) | ||
33 | switch lower(varargin{k}) | ||
34 | case {'x_scale','xscale'} | ||
35 | x_scale = varargin{k+1}; | ||
36 | case {'style','linestyle'} | ||
37 | linestyle = varargin{k+1}; | ||
38 | case {'x_lims','xlims','x_lim','xlim'} | ||
39 | x_lims = varargin{k+1}; | ||
40 | case {'y_scale','yscale'} | ||
41 | y_scale = varargin{k+1}; | ||
42 | case {'y_lims','ylims','y_lim','ylim'} | ||
43 | y_lims = varargin{k+1}; | ||
44 | case {'figure','fig'} | ||
45 | fig = varargin{k+1}; | ||
46 | case {'label','fig_label','figlabel'} | ||
47 | meta.fig_label = varargin{k+1}; | ||
48 | case {'colororder', 'color_order', 'colors'} | ||
49 | colororder = varargin{k+1}; | ||
50 | case {'legend_postfix','legendpostfix'} | ||
51 | legend_postfix = varargin{k+1}; | ||
52 | case {'legend_position','legendposition','legend_location','legendlocation'} | ||
53 | legend_location = varargin{k+1}; | ||
54 | otherwise | ||
55 | error(['unrecognized varargin-argument: ', varargin{k}]); | ||
56 | end | ||
57 | end | ||
58 | if isempty(fig) | ||
59 | meta.(fig_handle) = figure; hold all; | ||
60 | else | ||
61 | figure(fig); hold all; | ||
62 | meta.(fig_handle) = fig; | ||
63 | end | ||
64 | if ~isempty(colororder) | ||
65 | set(gca, 'ColorOrder', colororder); | ||
66 | end | ||
25 | x_scale = 'lin'; y_scale = 'lin'; | ||
26 | x_lims = []; y_lims = []; | ||
27 | fig = []; | ||
28 | linestyle = 'o:'; | ||
29 | colororder = []; | ||
30 | legend_postfix = ''; | ||
31 | legend_location = 'Best'; | ||
32 | for k=1:2:length(varargin) | ||
33 | switch lower(varargin{k}) | ||
34 | case {'x_scale','xscale'} | ||
35 | x_scale = varargin{k+1}; | ||
36 | case {'style','linestyle'} | ||
37 | linestyle = varargin{k+1}; | ||
38 | case {'x_lims','xlims','x_lim','xlim'} | ||
39 | x_lims = varargin{k+1}; | ||
40 | case {'y_scale','yscale'} | ||
41 | y_scale = varargin{k+1}; | ||
42 | case {'y_lims','ylims','y_lim','ylim'} | ||
43 | y_lims = varargin{k+1}; | ||
44 | case {'figure','fig'} | ||
45 | fig = varargin{k+1}; | ||
46 | case {'label','fig_label','figlabel'} | ||
47 | meta.fig_label = varargin{k+1}; | ||
48 | case {'colororder', 'color_order', 'colors'} | ||
49 | colororder = varargin{k+1}; | ||
50 | case {'legend_postfix','legendpostfix'} | ||
51 | legend_postfix = varargin{k+1}; | ||
52 | case {'legend_position','legendposition','legend_location','legendlocation'} | ||
53 | legend_location = varargin{k+1}; | ||
54 | otherwise | ||
55 | error(['unrecognized varargin-argument: ', varargin{k}]); | ||
56 | end | ||
57 | end | ||
58 | if isempty(fig) | ||
59 | meta.(fig_handle) = figure; hold all; | ||
60 | else | ||
61 | figure(fig); hold all; | ||
62 | meta.(fig_handle) = fig; | ||
63 | end | ||
64 | if ~isempty(colororder) | ||
65 | set(gca, 'ColorOrder', colororder); | ||
66 | end | ||
67 | 67 | ||
68 | if par_ind==1 | ||
69 | x_ind = 2; | ||
70 | x_data = meta_filtered.params{x_ind}; | ||
71 | elseif par_ind==2 | ||
72 | x_ind = 1; | ||
73 | x_data = meta_filtered.params{x_ind}'; | ||
74 | y_data = y_data'; | ||
68 | if par_ind==1 | ||
69 | x_ind = 2; | ||
70 | x_data = meta_filtered.params{x_ind}; | ||
71 | elseif par_ind==2 | ||
72 | x_ind = 1; | ||
73 | x_data = meta_filtered.params{x_ind}'; | ||
74 | y_data = y_data'; | ||
75 | 75 | ||
76 | end | ||
77 | if isempty(legend_postfix) | ||
78 | legend_parser = @(num) num2eng(num); | ||
79 | else | ||
80 | legend_parser = @(num) [num2eng(num), ' (', legend_postfix,')']; | ||
81 | end | ||
82 | cut_labels = arrayfun(legend_parser, unique(meta_filtered.params{par_ind}),... | ||
83 | 'UniformOutput', false); | ||
84 | plot(x_data, y_data, linestyle, 'LineWidth', 1.5, 'DisplayName', cut_labels); | ||
85 | labels(meta_filtered.param_names{x_ind},display_name); | ||
86 | set(gca, 'xscale', x_scale, 'yscale', y_scale) | ||
87 | meta_ev.xylims(x_lims, y_lims); | ||
88 | leg = legend('Location', legend_location); | ||
89 | legtitle = get(leg,'title'); | ||
90 | set(legtitle,'string', sentence_case(meta_filtered.param_names{par_ind}),... | ||
91 | 'interpreter', 'latex','FontSize',11); | ||
92 | set(leg, 'Color', 'w', 'FontWeight', 'normal',... | ||
93 | 'LineWidth', 1, 'Interpreter', 'latex','FontSize',11); | ||
76 | end | ||
77 | if isempty(legend_postfix) | ||
78 | legend_parser = @(num) num2eng(num); | ||
79 | else | ||
80 | legend_parser = @(num) [num2eng(num), ' (', legend_postfix,')']; | ||
81 | end | ||
82 | cut_labels = arrayfun(legend_parser, unique(meta_filtered.params{par_ind}),... | ||
83 | 'UniformOutput', false); | ||
84 | plot(x_data, y_data, linestyle, 'LineWidth', 1.5, 'DisplayName', cut_labels); | ||
85 | labels(meta_filtered.param_names{x_ind},display_name); | ||
86 | set(gca, 'xscale', x_scale, 'yscale', y_scale) | ||
87 | meta_ev.xylims(x_lims, y_lims); | ||
88 | leg = legend('Location', legend_location); | ||
89 | legtitle = get(leg,'title'); | ||
90 | set(legtitle,'string', sentence_case(meta_filtered.param_names{par_ind}),... | ||
91 | 'interpreter', 'latex','FontSize',11); | ||
92 | set(leg, 'Color', 'w', 'FontWeight', 'normal',... | ||
93 | 'LineWidth', 1, 'Interpreter', 'latex','FontSize',11); | ||
94 | 94 | ||
95 | meta.my_postprocess_plot(meta.(fig_handle)); | ||
96 | if isequal(display_name, 'Max. log. negativity') | ||
97 | hline=refline(0,0); set(hline, 'Color', 'k', 'DisplayName',' '); | ||
98 | end | ||
95 | meta.my_postprocess_plot(meta.(fig_handle)); | ||
96 | if isequal(display_name, 'Max. log. negativity') | ||
97 | hline=refline(0,0); set(hline, 'Color', 'k', 'DisplayName',' '); | ||
98 | end |
File data_analysis/@meta_ev/plot_logneg_versus_gamma.m changed (mode: 100644) (index 8627db9..d129631) | |||
1 | 1 | function plot_logneg_versus_gamma(meta, tracepairs_ind, varargin) | function plot_logneg_versus_gamma(meta, tracepairs_ind, varargin) |
2 | cmap = cbrewer('qual', 'Set1', meta.evaluations_no); | ||
3 | x_scale = 'log'; y_scale = 'lin'; | ||
4 | x_lims = []; y_lims = []; | ||
5 | fig = []; | ||
6 | for k=1:2:length(varargin) | ||
7 | switch lower(varargin{k}) | ||
8 | case {'x_scale','xscale'} | ||
9 | x_scale = varargin{k+1}; | ||
10 | case {'x_lims','xlims','x_lim','xlim'} | ||
11 | x_lims = varargin{k+1}; | ||
12 | case {'y_scale','yscale'} | ||
13 | y_scale = varargin{k+1}; | ||
14 | case {'y_lims','ylims','y_lim','ylim'} | ||
15 | y_lims = varargin{k+1}; | ||
16 | case {'label','fig_label','figlabel'} | ||
17 | meta.fig_label = varargin{k+1}; | ||
18 | case {'colororder', 'color_order', 'colors'} | ||
19 | cmap = varargin{k+1}; | ||
20 | case {'fig', 'figure'} | ||
21 | fig = varargin{k+1}; | ||
22 | otherwise | ||
23 | error(['unrecognized varargin-argument: ', varargin{k}]); | ||
24 | end | ||
25 | end | ||
26 | if isempty(fig) | ||
27 | fig = figure; | ||
28 | else | ||
2 | cmap = cbrewer('qual', 'Set1', meta.evaluations_no); | ||
3 | x_scale = 'log'; y_scale = 'lin'; | ||
4 | x_lims = []; y_lims = []; | ||
5 | fig = []; | ||
6 | for k=1:2:length(varargin) | ||
7 | switch lower(varargin{k}) | ||
8 | case {'x_scale','xscale'} | ||
9 | x_scale = varargin{k+1}; | ||
10 | case {'x_lims','xlims','x_lim','xlim'} | ||
11 | x_lims = varargin{k+1}; | ||
12 | case {'y_scale','yscale'} | ||
13 | y_scale = varargin{k+1}; | ||
14 | case {'y_lims','ylims','y_lim','ylim'} | ||
15 | y_lims = varargin{k+1}; | ||
16 | case {'label','fig_label','figlabel'} | ||
17 | meta.fig_label = varargin{k+1}; | ||
18 | case {'colororder', 'color_order', 'colors'} | ||
19 | cmap = varargin{k+1}; | ||
20 | case {'fig', 'figure'} | ||
21 | fig = varargin{k+1}; | ||
22 | otherwise | ||
23 | error(['unrecognized varargin-argument: ', varargin{k}]); | ||
24 | end | ||
25 | end | ||
26 | if isempty(fig) | ||
27 | fig = figure; | ||
28 | else | ||
29 | 29 | visibility = get(fig,'visible'); | visibility = get(fig,'visible'); |
30 | 30 | figure(fig); hold all; set(fig, 'visible', visibility); | figure(fig); hold all; set(fig, 'visible', visibility); |
31 | 31 | end | end |
32 | myplotlogneg = @(ev, color_ind) ev.plotLogneg('figure', fig,... | ||
33 | 'tracepairs', tracepairs_ind, 'save_fig', false, ... | ||
34 | 'color', cmap(color_ind,:),... | ||
35 | 'title', '', 'legend', false,... | ||
36 | 'show_physicality', false); | ||
37 | for k=1:meta.evaluations_no | ||
38 | myplotlogneg(meta.evaluations{k}, k); | ||
39 | end | ||
40 | set(gca, 'xscale', x_scale, 'yscale', y_scale) | ||
41 | meta.xylims(x_lims, y_lims); | ||
42 | meta.my_postprocess_plot(fig); | ||
43 | meta.ln_fig = fig; | ||
32 | myplotlogneg = @(ev, color_ind) ev.plotLogneg('figure', fig,... | ||
33 | 'tracepairs', tracepairs_ind, 'save_fig', false, ... | ||
34 | 'color', cmap(color_ind,:),... | ||
35 | 'title', '', 'legend', false,... | ||
36 | 'show_physicality', false); | ||
37 | for k=1:meta.evaluations_no | ||
38 | myplotlogneg(meta.evaluations{k}, k); | ||
39 | end | ||
40 | set(gca, 'xscale', x_scale, 'yscale', y_scale) | ||
41 | meta.xylims(x_lims, y_lims); | ||
42 | meta.my_postprocess_plot(fig); | ||
43 | meta.ln_fig = fig; |
File data_analysis/auxfunctions/OOP/assert_inherits_from.m changed (mode: 100644) (index 878e47e..f54da51) | |||
1 | 1 | function assert_inherits_from(obj, target_class) | function assert_inherits_from(obj, target_class) |
2 | myclass = class(obj); | ||
3 | supclasses = superclasses(myclass); | ||
2 | myclass = class(obj); | ||
3 | supclasses = superclasses(myclass); | ||
4 | 4 | ||
5 | is_target_class = isequal(myclass, target_class); | ||
6 | inherits_from_target_class = any(ismember(supclasses, target_class)); | ||
5 | is_target_class = isequal(myclass, target_class); | ||
6 | inherits_from_target_class = any(ismember(supclasses, target_class)); | ||
7 | 7 | ||
8 | assert(is_target_class || inherits_from_target_class,... | ||
9 | ['Class of input is ', myclass, ' which does not inherit from ', target_class]) | ||
8 | assert(is_target_class || inherits_from_target_class,... | ||
9 | ['Class of input is ', myclass, ' which does not inherit from ', target_class]) |
File data_analysis/auxfunctions/files/append_string_to_txtfile.m changed (mode: 100644) (index cfe9f42..e0a6eb2) | |||
1 | 1 | %% APPEND_STRING_TO_TXTFILE(string, file): takes a string and a file(name) | %% APPEND_STRING_TO_TXTFILE(string, file): takes a string and a file(name) |
2 | 2 | % and appends the string to the file (on a new line) | % and appends the string to the file (on a new line) |
3 | 3 | function append_string_to_txtfile(string, file) | function append_string_to_txtfile(string, file) |
4 | fid = fopen(file, 'a+'); | ||
5 | fprintf(fid, '%s\n', string); | ||
6 | fclose(fid); | ||
4 | fid = fopen(file, 'a+'); | ||
5 | fprintf(fid, '%s\n', string); | ||
6 | fclose(fid); | ||
7 | 7 | end | end |
File data_analysis/auxfunctions/files/isafile.m changed (mode: 100644) (index d012988..cfd6d2c) | |||
1 | 1 | function [ boolean ] = isafile( filePath, varargin) | function [ boolean ] = isafile( filePath, varargin) |
2 | %ISAFILE takes a file path and returns true if the path exists and points to a file and false otherwise | ||
3 | % Detailed explanation goes here | ||
4 | % if called with several input arguments it returns true if ALL inputs are filepaths | ||
5 | boolean = isafile_aux(filePath); | ||
6 | for k=1:length(varargin) | ||
7 | boolean = boolean && isafile_aux(varargin{k}); | ||
8 | end | ||
2 | %ISAFILE takes a file path and returns true if the path exists and points to a file and false otherwise | ||
3 | % Detailed explanation goes here | ||
4 | % if called with several input arguments it returns true if ALL inputs are filepaths | ||
5 | boolean = isafile_aux(filePath); | ||
6 | for k=1:length(varargin) | ||
7 | boolean = boolean && isafile_aux(varargin{k}); | ||
8 | end | ||
9 | 9 | ||
10 | 10 | function boolean = isafile_aux(filePath) | function boolean = isafile_aux(filePath) |
11 | boolean = isequal(exist(filePath,'file'),2); | ||
11 | boolean = isequal(exist(filePath,'file'),2); |
File data_analysis/auxfunctions/files/pseudo_hash.m changed (mode: 100644) (index bc5bfc3..d885418) | |||
1 | 1 | function hashsum = pseudo_hash(filepath, varargin) | function hashsum = pseudo_hash(filepath, varargin) |
2 | % takes path to a file which may contain large amounts of binary data | ||
3 | % and returns a quick "pseudo-hashsum" by inspecting the beginning and end of the file | ||
4 | % | ||
5 | % details: | ||
6 | % reads (up to) first 1e6 and last 1e6 bytes plus the filesize in bytes into an array | ||
7 | % returns SHA1-hashsum of the array | ||
8 | % | ||
9 | % TODO: opening a file for writing (but not writing anything) should not change the pseudo-hash | ||
10 | assert(exist(filepath)==2,... | ||
11 | ['File ', filepath, ' not found.']); | ||
2 | % takes path to a file which may contain large amounts of binary data | ||
3 | % and returns a quick "pseudo-hashsum" by inspecting the beginning and end of the file | ||
4 | % | ||
5 | % details: | ||
6 | % reads (up to) first 1e6 and last 1e6 bytes plus the filesize in bytes into an array | ||
7 | % returns SHA1-hashsum of the array | ||
8 | % | ||
9 | % TODO: opening a file for writing (but not writing anything) should not change the pseudo-hash | ||
10 | assert(exist(filepath)==2,... | ||
11 | ['File ', filepath, ' not found.']); | ||
12 | 12 | ||
13 | fileinfo = dir(filepath); | ||
14 | byte_no = fileinfo.bytes; | ||
13 | fileinfo = dir(filepath); | ||
14 | byte_no = fileinfo.bytes; | ||
15 | 15 | ||
16 | bytes = 1e6; | ||
17 | short = false; | ||
18 | for k=1:2:length(varargin) | ||
19 | switch varargin{k} | ||
20 | case 'bytes' | ||
21 | bytes = varargin{k+1}; | ||
22 | case 'short' | ||
23 | short = varargin{k+1}; | ||
24 | otherwise | ||
25 | error(['Unrecognized varargin-argument:', varargin{k}]); | ||
26 | end | ||
27 | end | ||
16 | bytes = 1e6; | ||
17 | short = false; | ||
18 | for k=1:2:length(varargin) | ||
19 | switch varargin{k} | ||
20 | case 'bytes' | ||
21 | bytes = varargin{k+1}; | ||
22 | case 'short' | ||
23 | short = varargin{k+1}; | ||
24 | otherwise | ||
25 | error(['Unrecognized varargin-argument:', varargin{k}]); | ||
26 | end | ||
27 | end | ||
28 | 28 | ||
29 | fid = fopen(filepath,'r'); | ||
30 | data_start = fread(fid, bytes); | ||
31 | fseek(fid, bytes, 'eof'); | ||
32 | data_end = fread(fid, bytes); | ||
33 | fclose(fid); | ||
29 | fid = fopen(filepath,'r'); | ||
30 | data_start = fread(fid, bytes); | ||
31 | fseek(fid, bytes, 'eof'); | ||
32 | data_end = fread(fid, bytes); | ||
33 | fclose(fid); | ||
34 | 34 | ||
35 | data = [data_start; data_end; byte_no]; | ||
35 | data = [data_start; data_end; byte_no]; | ||
36 | 36 | ||
37 | opt.Method = 'SHA-1'; | ||
38 | hashsum = DataHash(data, opt); | ||
39 | if short | ||
40 | hashsum = hashsum(1:8); | ||
37 | opt.Method = 'SHA-1'; | ||
38 | hashsum = DataHash(data, opt); | ||
39 | if short | ||
40 | hashsum = hashsum(1:8); | ||
41 | 41 | end | end |
File data_analysis/auxfunctions/gitrepos/get_git_status.m changed (mode: 100644) (index 72dec79..922c8c3) | |||
... | ... | function status = get_git_status(git_repo) | |
3 | 3 | cd(git_repo); | cd(git_repo); |
4 | 4 | status = git('status'); | status = git('status'); |
5 | 5 | cd(working_dir) | cd(working_dir) |
6 | |||
6 | |||
7 | 7 | clean_status_string = 'nothing to commit, working directory clean'; | clean_status_string = 'nothing to commit, working directory clean'; |
8 | 8 | if isempty(strfind(status, clean_status_string)) | if isempty(strfind(status, clean_status_string)) |
9 | cd(git_repo); | ||
10 | gitdiff = git('diff --name-status'); | ||
11 | cd(working_dir) | ||
12 | |||
13 | status = ['DIRTY',10, gitdiff]; | ||
9 | cd(git_repo); | ||
10 | gitdiff = git('diff --name-status'); | ||
11 | cd(working_dir) | ||
12 | |||
13 | status = ['DIRTY',10, gitdiff]; | ||
14 | 14 | else | else |
15 | status = 'CLEAN'; | ||
15 | status = 'CLEAN'; | ||
16 | 16 | end | end |
File data_analysis/auxfunctions/gitrepos/status_git_repos_on_path.m changed (mode: 100644) (index 7446e4a..8c7a3bc) | |||
1 | 1 | function gitstring = status_git_repos_on_path | function gitstring = status_git_repos_on_path |
2 | gitrepos_array = git_repos_on_path; | ||
3 | horiz_line = [10,repmat('_',1,72),10,10]; | ||
4 | gitstring = horiz_line; | ||
5 | for k=1:length(gitrepos_array) | ||
6 | git_repo = gitrepos_array{k}; | ||
7 | git_commit = get_git_commit_hash(git_repo); | ||
8 | git_status = get_git_status(git_repo); | ||
2 | gitrepos_array = git_repos_on_path; | ||
3 | horiz_line = [10,repmat('_',1,72),10,10]; | ||
4 | gitstring = horiz_line; | ||
5 | for k=1:length(gitrepos_array) | ||
6 | git_repo = gitrepos_array{k}; | ||
7 | git_commit = get_git_commit_hash(git_repo); | ||
8 | git_status = get_git_status(git_repo); | ||
9 | 9 | ||
10 | gitstring = [gitstring, git_repo, 9, git_commit, 9, git_status, horiz_line]; | ||
11 | end | ||
10 | gitstring = [gitstring, git_repo, 9, git_commit, 9, git_status, horiz_line]; | ||
11 | end |
File data_analysis/auxfunctions/gitrepos/test_git_conveniences.m changed (mode: 100644) (index 71bec51..7b31008) | |||
1 | 1 | function test_suite = get_git_commit_hash_test %#ok<STOUT> | function test_suite = get_git_commit_hash_test %#ok<STOUT> |
2 | clc; initTestSuite; | ||
2 | clc; initTestSuite; | ||
3 | 3 | ||
4 | 4 | function shared = setup | function shared = setup |
5 | shared.working_dir = pwd; | ||
6 | shared.testrepo = '__testrepo__'; | ||
7 | shared.testrepo2 = '__testrepo2__'; | ||
8 | shared.testfile = 'test.txt'; | ||
5 | shared.working_dir = pwd; | ||
6 | shared.testrepo = '__testrepo__'; | ||
7 | shared.testrepo2 = '__testrepo2__'; | ||
8 | shared.testfile = 'test.txt'; | ||
9 | 9 | ||
10 | 10 | % create test repository | % create test repository |
11 | 11 | git('init',shared.testrepo); | git('init',shared.testrepo); |
... | ... | function shared = setup | |
13 | 13 | dlmwrite(shared.testfile, [1,2,3], 'delimiter', 't'); | dlmwrite(shared.testfile, [1,2,3], 'delimiter', 't'); |
14 | 14 | git('add', shared.testfile); | git('add', shared.testfile); |
15 | 15 | git commit -m "Initialize repo" | git commit -m "Initialize repo" |
16 | cd(shared.working_dir); | ||
16 | cd(shared.working_dir); | ||
17 | 17 | ||
18 | % create test repository 2 | ||
19 | git('init',shared.testrepo2); | ||
20 | cd(shared.testrepo2); | ||
21 | dlmwrite(shared.testfile, [1,2,3], 'delimiter', 't'); | ||
22 | git('add', shared.testfile); | ||
23 | git commit -m "Initialize repo 2" | ||
24 | cd(shared.working_dir); | ||
18 | % create test repository 2 | ||
19 | git('init',shared.testrepo2); | ||
20 | cd(shared.testrepo2); | ||
21 | dlmwrite(shared.testfile, [1,2,3], 'delimiter', 't'); | ||
22 | git('add', shared.testfile); | ||
23 | git commit -m "Initialize repo 2" | ||
24 | cd(shared.working_dir); | ||
25 | 25 | ||
26 | 26 | function teardown(shared) | function teardown(shared) |
27 | 27 | rmdir(shared.testrepo, 's'); | rmdir(shared.testrepo, 's'); |
28 | rmdir(shared.testrepo2, 's'); | ||
29 | cd(shared.working_dir) | ||
30 | clear('shared'); | ||
28 | rmdir(shared.testrepo2, 's'); | ||
29 | cd(shared.working_dir) | ||
30 | clear('shared'); | ||
31 | 31 | ||
32 | 32 | function ht = test_identical_repos(shared) | function ht = test_identical_repos(shared) |
33 | hash = get_git_commit_hash(shared.testrepo); | ||
34 | hash_ = get_git_commit_hash(shared.testrepo); | ||
35 | hash__ = get_git_commit_hash(GetFullPath(shared.testrepo)); | ||
36 | assertEqual(hash, hash_) | ||
37 | assertEqual(hash, hash__) | ||
33 | hash = get_git_commit_hash(shared.testrepo); | ||
34 | hash_ = get_git_commit_hash(shared.testrepo); | ||
35 | hash__ = get_git_commit_hash(GetFullPath(shared.testrepo)); | ||
36 | assertEqual(hash, hash_) | ||
37 | assertEqual(hash, hash__) | ||
38 | 38 | ||
39 | 39 | function ht = test_identical_remote_repos(shared) | function ht = test_identical_remote_repos(shared) |
40 | hash = get_git_commit_hash(shared.testrepo); | ||
41 | cloned_repo = '__anothertestrepo__' | ||
42 | git('clone', shared.testrepo, cloned_repo) | ||
43 | hash = get_git_commit_hash(shared.testrepo); | ||
44 | hash_ = get_git_commit_hash(cloned_repo); | ||
45 | assertEqual(hash, hash_) | ||
46 | rmdir(cloned_repo, 's') | ||
40 | hash = get_git_commit_hash(shared.testrepo); | ||
41 | cloned_repo = '__anothertestrepo__' | ||
42 | git('clone', shared.testrepo, cloned_repo) | ||
43 | hash = get_git_commit_hash(shared.testrepo); | ||
44 | hash_ = get_git_commit_hash(cloned_repo); | ||
45 | assertEqual(hash, hash_) | ||
46 | rmdir(cloned_repo, 's') | ||
47 | 47 | ||
48 | 48 | function ht = test_distinct_remote_repos(shared) | function ht = test_distinct_remote_repos(shared) |
49 | hash = get_git_commit_hash(shared.testrepo); | ||
50 | cloned_repo = '__anothertestrepo__' | ||
51 | git('clone', shared.testrepo, cloned_repo) | ||
52 | cd(cloned_repo) | ||
53 | dlmwrite('test2.txt', [1,2,3], 'delimiter', 't'); | ||
54 | git('add', 'test2.txt'); | ||
55 | git commit -m "Modify repo" | ||
56 | cd(shared.working_dir) | ||
57 | hash = get_git_commit_hash(shared.testrepo); | ||
58 | hash_ = get_git_commit_hash(cloned_repo); | ||
59 | assertFalse(isequal(hash, hash_)) | ||
60 | rmdir(cloned_repo, 's') | ||
49 | hash = get_git_commit_hash(shared.testrepo); | ||
50 | cloned_repo = '__anothertestrepo__' | ||
51 | git('clone', shared.testrepo, cloned_repo) | ||
52 | cd(cloned_repo) | ||
53 | dlmwrite('test2.txt', [1,2,3], 'delimiter', 't'); | ||
54 | git('add', 'test2.txt'); | ||
55 | git commit -m "Modify repo" | ||
56 | cd(shared.working_dir) | ||
57 | hash = get_git_commit_hash(shared.testrepo); | ||
58 | hash_ = get_git_commit_hash(cloned_repo); | ||
59 | assertFalse(isequal(hash, hash_)) | ||
60 | rmdir(cloned_repo, 's') | ||
61 | 61 | ||
62 | 62 | function ht = test_distinct_repos(shared) | function ht = test_distinct_repos(shared) |
63 | hash = get_git_commit_hash(shared.testrepo); | ||
64 | hash2 = get_git_commit_hash(shared.testrepo2); | ||
65 | assertFalse(isequal(hash, hash2)) | ||
63 | hash = get_git_commit_hash(shared.testrepo); | ||
64 | hash2 = get_git_commit_hash(shared.testrepo2); | ||
65 | assertFalse(isequal(hash, hash2)) | ||
66 | 66 | ||
67 | 67 | function ht = test_status(shared) | function ht = test_status(shared) |
68 | status = get_git_status(shared.testrepo); | ||
69 | assertEqual(status, 'CLEAN'); | ||
68 | status = get_git_status(shared.testrepo); | ||
69 | assertEqual(status, 'CLEAN'); | ||
70 | 70 | ||
71 | % locally modify testrepo | ||
72 | cd(shared.testrepo); | ||
73 | dlmwrite(shared.testfile, [1,2,3,4,5], 'delimiter', 't'); | ||
74 | cd(shared.working_dir); | ||
75 | status = get_git_status(shared.testrepo); | ||
76 | assertEqual(status(1:5), 'DIRTY'); | ||
71 | % locally modify testrepo | ||
72 | cd(shared.testrepo); | ||
73 | dlmwrite(shared.testfile, [1,2,3,4,5], 'delimiter', 't'); | ||
74 | cd(shared.working_dir); | ||
75 | status = get_git_status(shared.testrepo); | ||
76 | assertEqual(status(1:5), 'DIRTY'); |
File data_analysis/auxfunctions/matrixcomp/householder_ON.m changed (mode: 100644 -> 100755) (index 11302df..45fe333) | |||
... | ... | function Q = householder_ON(A) | |
3 | 3 | % produces an m-by-m othogonal matrix Q out of the n-columns of A (m-by-n), | % produces an m-by-m othogonal matrix Q out of the n-columns of A (m-by-n), |
4 | 4 | % s.t. if the columns of A are independent the first n columns of Q span | % s.t. if the columns of A are independent the first n columns of Q span |
5 | 5 | % the same sub vector space. | % the same sub vector space. |
6 | % This algorithm is based on Housholder relfections | ||
6 | % This algorithm is based on Housholder relfections | ||
7 | 7 | % (see https://en.wikipedia.org/wiki/QR_decomposition#Using_Householder_reflections) | % (see https://en.wikipedia.org/wiki/QR_decomposition#Using_Householder_reflections) |
8 | 8 | % and provide more robust othogonality than a modified Gram-Schmidt | % and provide more robust othogonality than a modified Gram-Schmidt |
9 | 9 | % algorithm; in the sense that the deviation of Q*Q' from identity marix is | % algorithm; in the sense that the deviation of Q*Q' from identity marix is |
... | ... | for k=1:min(m-1,n) | |
19 | 19 | end | end |
20 | 20 | ||
21 | 21 | for k=min(m-1,n):-1:1 | for k=min(m-1,n):-1:1 |
22 | Q = Q - 2*v(:,k)*(v(:,k)'*Q); | ||
22 | Q = Q - 2*v(:,k)*(v(:,k)'*Q); | ||
23 | 23 | end | end |
File data_analysis/auxfunctions/matrixcomp/rootm.m changed (mode: 100644) (index d74f274..c420eee) | |||
... | ... | for c = 1:n-1 | |
41 | 41 | for i = 1:n-c | for i = 1:n-c |
42 | 42 | sum1 = 0; | sum1 = 0; |
43 | 43 | for d = 1:p-2 | for d = 1:p-2 |
44 | sum2 = 0; | ||
45 | for k = i+1:i+c-1 | ||
44 | sum2 = 0; | ||
45 | for k = i+1:i+c-1 | ||
46 | 46 | sum2 = sum2 + U(i,k)*R(k,(d-1)*n + i+c); | sum2 = sum2 + U(i,k)*R(k,(d-1)*n + i+c); |
47 | 47 | end | end |
48 | 48 | sum1 = sum1 + U(i,i)^(p-2-d)*sum2; | sum1 = sum1 + U(i,i)^(p-2-d)*sum2; |
49 | end | ||
50 | sum3 = 0; | ||
49 | end | ||
50 | sum3 = 0; | ||
51 | 51 | for k = i+1:i+c-1 | for k = i+1:i+c-1 |
52 | 52 | sum3 = sum3 + U(i,k)*U(k,i+c); | sum3 = sum3 + U(i,k)*U(k,i+c); |
53 | 53 | end | end |
... | ... | for c = 1:n-1 | |
55 | 55 | sum4 = 0; | sum4 = 0; |
56 | 56 | for j = 0:p-1 | for j = 0:p-1 |
57 | 57 | sum4 = sum4 + U(i,i)^j*U(i+c,i+c)^(p-1-j); | sum4 = sum4 + U(i,i)^j*U(i+c,i+c)^(p-1-j); |
58 | end | ||
58 | end | ||
59 | 59 | ||
60 | 60 | U(i,i+c) = (T(i,i+c) - sum1)/(sum4); | U(i,i+c) = (T(i,i+c) - sum1)/(sum4); |
61 | 61 | ||
... | ... | for c = 1:n-1 | |
67 | 67 | sum6 = 0; | sum6 = 0; |
68 | 68 | for h = 1:q-1 | for h = 1:q-1 |
69 | 69 | sum7 = 0; | sum7 = 0; |
70 | for w=i+1:i+c-1 | ||
71 | sum7 = sum7 + U(i,w)*R(w,(h-1)*n +i+c); | ||
70 | for w=i+1:i+c-1 | ||
71 | sum7 = sum7 + U(i,w)*R(w,(h-1)*n +i+c); | ||
72 | 72 | end | end |
73 | 73 | sum6 = sum6 + U(i,i)^(q-1-h)*sum7; | sum6 = sum6 + U(i,i)^(q-1-h)*sum7; |
74 | 74 | end | end |
File data_analysis/auxfunctions/monitor/estimated_time_of_arrival.m changed (mode: 100644) (index f0b4f37..7a6396f) | |||
1 | 1 | function print_eta = estimated_time_of_arrival() | function print_eta = estimated_time_of_arrival() |
2 | start_time = clock; | ||
3 | |||
2 | start_time = clock; | ||
3 | |||
4 | 4 | function print_eta_fct(iterations_passed, iteration_no) | function print_eta_fct(iterations_passed, iteration_no) |
5 | time_diff = etime(clock, start_time); | ||
6 | est_duration_min = (time_diff/60)*iteration_no/iterations_passed; | ||
5 | time_diff = etime(clock, start_time); | ||
6 | est_duration_min = (time_diff/60)*iteration_no/iterations_passed; | ||
7 | 7 | precision = 3; | precision = 3; |
8 | if est_duration_min < 1 | ||
9 | return | ||
8 | if est_duration_min < 1 | ||
9 | return | ||
10 | 10 | %disp(['estimated duration [seconds]: ',... | %disp(['estimated duration [seconds]: ',... |
11 | 11 | %num2str(60*est_duration_min, precision)]); | %num2str(60*est_duration_min, precision)]); |
12 | 12 | ||
13 | elseif est_duration_min < 60 | ||
14 | disp(['estimated duration [minutes]: ',... | ||
13 | elseif est_duration_min < 60 | ||
14 | disp(['estimated duration [minutes]: ',... | ||
15 | 15 | num2str(est_duration_min, precision)]); | num2str(est_duration_min, precision)]); |
16 | elseif est_duration_min < 60*24 | ||
17 | disp(['estimated duration [hours]: ',... | ||
16 | elseif est_duration_min < 60*24 | ||
17 | disp(['estimated duration [hours]: ',... | ||
18 | 18 | num2str(est_duration_min/60, precision)]); | num2str(est_duration_min/60, precision)]); |
19 | else | ||
20 | disp(['estimated duration [days]: ',... | ||
19 | else | ||
20 | disp(['estimated duration [days]: ',... | ||
21 | 21 | num2str(est_duration_min/(24*60), precision)]); | num2str(est_duration_min/(24*60), precision)]); |
22 | end | ||
23 | est_arrival = datestr(addtodate(now, round(est_duration_min*60),'second')); | ||
24 | disp(['estimated time of arrival: ',... | ||
25 | est_arrival]); | ||
22 | end | ||
23 | est_arrival = datestr(addtodate(now, round(est_duration_min*60),'second')); | ||
24 | disp(['estimated time of arrival: ',... | ||
25 | est_arrival]); | ||
26 | 26 | end | end |
27 | 27 | ||
28 | 28 | print_eta = @print_eta_fct; | print_eta = @print_eta_fct; |
File data_analysis/auxfunctions/orthonormality/assert_orthonormality.m changed (mode: 100644) (index 5316acf..252d674) | |||
1 | 1 | function on_info = assert_orthonormality(Q, norm_tol, orthog_tol) | function on_info = assert_orthonormality(Q, norm_tol, orthog_tol) |
2 | % Asserts that the rows of matrix Q are mutually orthonormal | ||
3 | % within numerical tolerances specified by 'norm_tol' and 'orthog_tol' | ||
4 | % If the assertion fails, additional information is displayed | ||
5 | % about the cause of the failure and the size of the deviation | ||
6 | |||
7 | failure = false; | ||
8 | [~, orthog, normal, on_info] = orthonormality(Q, norm_tol, orthog_tol); | ||
9 | |||
10 | if ~orthog | ||
11 | failure = true; | ||
12 | |||
13 | % display info about the cause and size of failure | ||
14 | [deviations, sortorder] = sort(on_info.orthog.deviations, 'descend'); | ||
15 | off_cols = on_info.orthog.offenders.cols(sortorder); | ||
16 | off_rows = on_info.orthog.offenders.rows(sortorder); | ||
17 | |||
18 | disp(['\nPairs of rows violating orthogonality & amount of violation:',10,... | ||
19 | '(sorted in order of decreasing violation)']) | ||
20 | disp(arrayfun(@num2str, [off_cols, off_rows, deviations],... | ||
21 | 'UniformOutput', false)) | ||
22 | disp('Orthogonality test failed!'); | ||
23 | % disp(arrayfun(@num2str, Q*Q', 'UniformOutput', false)) | ||
24 | end | ||
25 | |||
26 | if ~normal | ||
27 | failure = true; | ||
28 | |||
29 | % display info about the cause and size of failure | ||
30 | [deviations, sortorder] = sort(on_info.norm.deviations, 'descend'); | ||
31 | offenders = on_info.norm.offenders(sortorder); | ||
32 | |||
33 | disp(['Rows violating normality and amount of violation:',10,... | ||
34 | '(sorted in order of decreasing violation)']) | ||
35 | disp(arrayfun(@num2str, [offenders, deviations],... | ||
36 | 'UniformOutput', false)) | ||
37 | disp('Normality test failed!'); | ||
38 | end | ||
39 | |||
40 | if failure | ||
41 | error('Orthonormality test failed!') | ||
42 | end | ||
2 | % Asserts that the rows of matrix Q are mutually orthonormal | ||
3 | % within numerical tolerances specified by 'norm_tol' and 'orthog_tol' | ||
4 | % If the assertion fails, additional information is displayed | ||
5 | % about the cause of the failure and the size of the deviation | ||
6 | |||
7 | failure = false; | ||
8 | [~, orthog, normal, on_info] = orthonormality(Q, norm_tol, orthog_tol); | ||
9 | |||
10 | if ~orthog | ||
11 | failure = true; | ||
12 | |||
13 | % display info about the cause and size of failure | ||
14 | [deviations, sortorder] = sort(on_info.orthog.deviations, 'descend'); | ||
15 | off_cols = on_info.orthog.offenders.cols(sortorder); | ||
16 | off_rows = on_info.orthog.offenders.rows(sortorder); | ||
17 | |||
18 | disp(['\nPairs of rows violating orthogonality & amount of violation:',10,... | ||
19 | '(sorted in order of decreasing violation)']) | ||
20 | disp(arrayfun(@num2str, [off_cols, off_rows, deviations],... | ||
21 | 'UniformOutput', false)) | ||
22 | disp('Orthogonality test failed!'); | ||
23 | % disp(arrayfun(@num2str, Q*Q', 'UniformOutput', false)) | ||
24 | end | ||
25 | |||
26 | if ~normal | ||
27 | failure = true; | ||
28 | |||
29 | % display info about the cause and size of failure | ||
30 | [deviations, sortorder] = sort(on_info.norm.deviations, 'descend'); | ||
31 | offenders = on_info.norm.offenders(sortorder); | ||
32 | |||
33 | disp(['Rows violating normality and amount of violation:',10,... | ||
34 | '(sorted in order of decreasing violation)']) | ||
35 | disp(arrayfun(@num2str, [offenders, deviations],... | ||
36 | 'UniformOutput', false)) | ||
37 | disp('Normality test failed!'); | ||
38 | end | ||
39 | |||
40 | if failure | ||
41 | error('Orthonormality test failed!') | ||
42 | end |
File data_analysis/auxfunctions/orthonormality/orthonormality.m changed (mode: 100644) (index d05e4db..f55635c) | |||
... | ... | function [orthonorm, orthog, normal, on_info] = orthonormality(Q, norm_tol, orth | |
2 | 2 | % [orthonorm, orthog, normal, info] = orthonormality(Q, norm_tol, orthog_tol) | % [orthonorm, orthog, normal, info] = orthonormality(Q, norm_tol, orthog_tol) |
3 | 3 | % returns a boolean 'orthonorm' indicating whether the rows of matrix Q | % returns a boolean 'orthonorm' indicating whether the rows of matrix Q |
4 | 4 | % are orthonormal within numerical tolerances norn_tol and orthog_tol. | % are orthonormal within numerical tolerances norn_tol and orthog_tol. |
5 | % | ||
5 | % | ||
6 | 6 | % The booleans 'orthog' and 'normal' indicate orthogonality and normality separately. | % The booleans 'orthog' and 'normal' indicate orthogonality and normality separately. |
7 | 7 | % | % |
8 | 8 | % orthonorm (orthog, normal) = True ==> All rows are orthonormal (orthogonal, normal). | % orthonorm (orthog, normal) = True ==> All rows are orthonormal (orthogonal, normal). |
... | ... | function [orthonorm, orthog, normal, on_info] = orthonormality(Q, norm_tol, orth | |
12 | 12 | % | % |
13 | 13 | % Basic Idea: | % Basic Idea: |
14 | 14 | % for QQ^T, check if the diagonal elements are within a tolerence 'norm_tol' | % for QQ^T, check if the diagonal elements are within a tolerence 'norm_tol' |
15 | % from 1 (assesses the normalisation) and if the non-diagonal elements are | ||
16 | % within a tolerence 'orthog_tol' from 0 (assesses orthogonality). | ||
15 | % from 1 (assesses the normalisation) and if the non-diagonal elements are | ||
16 | % within a tolerence 'orthog_tol' from 0 (assesses orthogonality). | ||
17 | 17 | ||
18 | 18 | on_info = {}; | on_info = {}; |
19 | 19 | ||
... | ... | orthog = isempty(orthog_viol_rows); | |
43 | 43 | if ~orthog | if ~orthog |
44 | 44 | on_info.orthog.offenders.cols = orthog_viol_cols; | on_info.orthog.offenders.cols = orthog_viol_cols; |
45 | 45 | on_info.orthog.offenders.rows = orthog_viol_rows; | on_info.orthog.offenders.rows = orthog_viol_rows; |
46 | |||
46 | |||
47 | 47 | orthog_critical_devs = zeros(size(orthog_viol_rows)); | orthog_critical_devs = zeros(size(orthog_viol_rows)); |
48 | 48 | for k=1:length(orthog_viol_rows) | for k=1:length(orthog_viol_rows) |
49 | 49 | row = orthog_viol_rows(k); | row = orthog_viol_rows(k); |
File data_analysis/auxfunctions/permute_data/permute_data.m changed (mode: 100644) (index 27b5818..a787395) | |||
1 | 1 | function data_permuted = permute_data(data_original, varargin) | function data_permuted = permute_data(data_original, varargin) |
2 | % permute_data takes traces with quadratures ordered as 'q1', 'q2',... 'p1', | ||
3 | % 'p2',... 'x1', 'x2',... 'y1', 'y2' and returns the the same traces | ||
4 | % reordered with quadratures ordered as 'q1', 'p1', 'q2', | ||
5 | %'p2',... 'x1', 'y1', 'x2', 'y2',... | ||
6 | % | ||
7 | % permute_data(traces, 'inverse', true) performs the inverse reordering. | ||
2 | % permute_data takes traces with quadratures ordered as 'q1', 'q2',... 'p1', | ||
3 | % 'p2',... 'x1', 'x2',... 'y1', 'y2' and returns the the same traces | ||
4 | % reordered with quadratures ordered as 'q1', 'p1', 'q2', | ||
5 | %'p2',... 'x1', 'y1', 'x2', 'y2',... | ||
6 | % | ||
7 | % permute_data(traces, 'inverse', true) performs the inverse reordering. | ||
8 | 8 | ||
9 | inverse = false; | ||
10 | for k=1:2:length(varargin) | ||
11 | switch varargin{k} | ||
12 | case {'inverse', 'Inverse'} | ||
13 | inverse = varargin{k+1}; | ||
14 | otherwise | ||
15 | error(['Unrecognized varargin-argument ', varargin{k}]); | ||
16 | end | ||
17 | end | ||
9 | inverse = false; | ||
10 | for k=1:2:length(varargin) | ||
11 | switch varargin{k} | ||
12 | case {'inverse', 'Inverse'} | ||
13 | inverse = varargin{k+1}; | ||
14 | otherwise | ||
15 | error(['Unrecognized varargin-argument ', varargin{k}]); | ||
16 | end | ||
17 | end | ||
18 | 18 | ||
19 | col_no = size(data_original, 2); | ||
20 | mode_no = col_no/4; | ||
21 | |||
22 | perm_vec = []; | ||
23 | perm_vec_stub = [1:mode_no:col_no/2]; | ||
24 | for k=1:mode_no | ||
25 | perm_vec = [perm_vec, perm_vec_stub + (k -1)]; | ||
26 | end | ||
19 | col_no = size(data_original, 2); | ||
20 | mode_no = col_no/4; | ||
27 | 21 | ||
28 | perm_vec_stub = perm_vec_stub + 2*mode_no; | ||
29 | for k=1:mode_no | ||
30 | perm_vec = [perm_vec, perm_vec_stub + (k -1)]; | ||
31 | end | ||
22 | perm_vec = []; | ||
23 | perm_vec_stub = [1:mode_no:col_no/2]; | ||
24 | for k=1:mode_no | ||
25 | perm_vec = [perm_vec, perm_vec_stub + (k -1)]; | ||
26 | end | ||
32 | 27 | ||
33 | if inverse | ||
34 | perm_vec_inv(perm_vec) = 1:length(perm_vec); | ||
35 | perm_vec = perm_vec_inv; | ||
36 | end | ||
37 | %disp(perm_vec) | ||
38 | data_permuted = data_original(:,perm_vec); | ||
28 | perm_vec_stub = perm_vec_stub + 2*mode_no; | ||
29 | for k=1:mode_no | ||
30 | perm_vec = [perm_vec, perm_vec_stub + (k -1)]; | ||
31 | end | ||
32 | |||
33 | if inverse | ||
34 | perm_vec_inv(perm_vec) = 1:length(perm_vec); | ||
35 | perm_vec = perm_vec_inv; | ||
36 | end | ||
37 | %disp(perm_vec) | ||
38 | data_permuted = data_original(:,perm_vec); |
File data_analysis/auxfunctions/permute_data/read_permute_write_data.m changed (mode: 100644) (index e04d610..24d232d) | |||
1 | 1 | function [permuted_data_file, permuted_data_CM_file] = read_permute_write_data(fullpath, varargin) | function [permuted_data_file, permuted_data_CM_file] = read_permute_write_data(fullpath, varargin) |
2 | data_original = dlmread(fullpath, '\t'); | ||
3 | data_permuted = permute_data(data_original, varargin{:}); | ||
4 | dlmwrite(fullpath, data_permuted, '\t'); | ||
5 | permuted_data_file = fullpath; | ||
2 | data_original = dlmread(fullpath, '\t'); | ||
3 | data_permuted = permute_data(data_original, varargin{:}); | ||
4 | dlmwrite(fullpath, data_permuted, '\t'); | ||
5 | permuted_data_file = fullpath; | ||
6 | 6 | ||
7 | CM = cov(data_permuted); | ||
8 | [folder, filename, fileext] = fileparts(fullpath); | ||
9 | CM_filepath = fullfile(folder, ['CM_', filename, fileext]); | ||
10 | dlmwrite(CM_filepath, CM, '\t'); | ||
11 | permuted_data_CM_file = CM_filepath; | ||
7 | CM = cov(data_permuted); | ||
8 | [folder, filename, fileext] = fileparts(fullpath); | ||
9 | CM_filepath = fullfile(folder, ['CM_', filename, fileext]); | ||
10 | dlmwrite(CM_filepath, CM, '\t'); | ||
11 | permuted_data_CM_file = CM_filepath; |
File data_analysis/auxfunctions/permute_data/read_permute_write_data__folder.m changed (mode: 100644) (index 30ba997..60a02d7) | |||
1 | 1 | function read_permute_write_data__folder() | function read_permute_write_data__folder() |
2 | inverse_permutation = false; | ||
3 | for k=1:30 | ||
4 | filename = sprintf('%02d.tsv', k) | ||
2 | inverse_permutation = false; | ||
3 | for k=1:30 | ||
4 | filename = sprintf('%02d.tsv', k) | ||
5 | 5 | ||
6 | %% check: | ||
7 | if k==30 | ||
8 | CM_filename = ['CM_', filename]; | ||
9 | CM = dlmread(CM_filename, '\t'); | ||
10 | figure; heatmap(CM) | ||
11 | title(['CM before; p1p1: ',num2str(CM(4,4)),'; x1x2: ', num2str(CM(7,8))]); | ||
12 | end | ||
13 | |||
14 | read_permute_write_data(filename, 'inverse', inverse_permutation) | ||
15 | end | ||
16 | |||
17 | %% check: | ||
18 | CM_filename = ['CM_', filename]; | ||
19 | CM = dlmread(CM_filename, '\t'); | ||
20 | figure; heatmap(CM) | ||
21 | title(['CM after; p1p1: ',num2str(CM(2,2)),'; x1x2: ', num2str(CM(7,9))]); | ||
6 | %% check: | ||
7 | if k==30 | ||
8 | CM_filename = ['CM_', filename]; | ||
9 | CM = dlmread(CM_filename, '\t'); | ||
10 | figure; heatmap(CM) | ||
11 | title(['CM before; p1p1: ',num2str(CM(4,4)),'; x1x2: ', num2str(CM(7,8))]); | ||
12 | end | ||
13 | |||
14 | read_permute_write_data(filename, 'inverse', inverse_permutation) | ||
15 | end | ||
16 | |||
17 | %% check: | ||
18 | CM_filename = ['CM_', filename]; | ||
19 | CM = dlmread(CM_filename, '\t'); | ||
20 | figure; heatmap(CM) | ||
21 | title(['CM after; p1p1: ',num2str(CM(2,2)),'; x1x2: ', num2str(CM(7,9))]); |
File data_analysis/auxfunctions/plots/gridxy.m changed (mode: 100644) (index cedcbe6..82eb533) | |||
... | ... | function hh = gridxy(x,varargin) | |
7 | 7 | % or horizontal lines are plotted. | % or horizontal lines are plotted. |
8 | 8 | % | % |
9 | 9 | % The lines are plotted as a single graphics object. H = GRIDXY(..) returns | % The lines are plotted as a single graphics object. H = GRIDXY(..) returns |
10 | % a graphics handle to that line object. | ||
10 | % a graphics handle to that line object. | ||
11 | 11 | % | % |
12 | 12 | % GRIDXY(..., 'Prop1','Val1','Prop2','Val2', ...) uses the properties | % GRIDXY(..., 'Prop1','Val1','Prop2','Val2', ...) uses the properties |
13 | 13 | % and values specified for color, linestyle, etc. Execute GET(H), where H is | % and values specified for color, linestyle, etc. Execute GET(H), where H is |
... | ... | function hh = gridxy(x,varargin) | |
16 | 16 | % | % |
17 | 17 | % Examples | % Examples |
18 | 18 | % % some random plot | % % some random plot |
19 | % plot(10*rand(100,1), 10*rand(100,1),'bo') ; | ||
19 | % plot(10*rand(100,1), 10*rand(100,1),'bo') ; | ||
20 | 20 | % % horizontal red dashed grid | % % horizontal red dashed grid |
21 | 21 | % gridxy([1.1 3.2 4.5],'Color','r','Linestyle',':') ; | % gridxy([1.1 3.2 4.5],'Color','r','Linestyle',':') ; |
22 | 22 | % % vertical solid thicker yellowish grid, and store the handle | % % vertical solid thicker yellowish grid, and store the handle |
... | ... | else | |
56 | 56 | if ischar(va{1}), | if ischar(va{1}), |
57 | 57 | % optional arguments are | % optional arguments are |
58 | 58 | y = [] ; | y = [] ; |
59 | elseif isnumeric(va{1}) | ||
59 | elseif isnumeric(va{1}) | ||
60 | 60 | y = va{1} ; | y = va{1} ; |
61 | 61 | va = va(2:end) ; | va = va(2:end) ; |
62 | 62 | else | else |
... | ... | yy2 = repmat(y(:).',3,1) ; | |
90 | 90 | ||
91 | 91 | % create data for a single line object | % create data for a single line object |
92 | 92 | xx1 = [xx1 xx2] ; | xx1 = [xx1 xx2] ; |
93 | if ~isempty(xx1), | ||
93 | if ~isempty(xx1), | ||
94 | 94 | yy1 = [yy1 yy2] ; | yy1 = [yy1 yy2] ; |
95 | 95 | % add the line to the current axes | % add the line to the current axes |
96 | 96 | np = get(hca,'nextplot') ; | np = get(hca,'nextplot') ; |
97 | 97 | set(hca,'nextplot','add') ; | set(hca,'nextplot','add') ; |
98 | h = line('xdata',xx1(:),'ydata',yy1(:)) ; | ||
98 | h = line('xdata',xx1(:),'ydata',yy1(:)) ; | ||
99 | 99 | set(hca,'ylim',ylim,'xlim',xlim) ; % reset the limits | set(hca,'ylim',ylim,'xlim',xlim) ; % reset the limits |
100 | |||
100 | |||
101 | 101 | uistack(h,'bottom') ; % push lines to the bottom of the graph | uistack(h,'bottom') ; % push lines to the bottom of the graph |
102 | 102 | set(hca,'nextplot',np,'Layer','top') ; % reset the nextplot state | set(hca,'nextplot',np,'Layer','top') ; % reset the nextplot state |
103 | 103 | ||
104 | 104 | if ~isempty(va), | if ~isempty(va), |
105 | 105 | try | try |
106 | set(h,va{:}) ; % set line properties | ||
106 | set(h,va{:}) ; % set line properties | ||
107 | 107 | catch | catch |
108 | 108 | msg = lasterror ; | msg = lasterror ; |
109 | 109 | error(msg.message(21:end)) ; | error(msg.message(21:end)) ; |
... | ... | end | |
117 | 117 | if nargout==1, % if requested return handle | if nargout==1, % if requested return handle |
118 | 118 | hh = h ; | hh = h ; |
119 | 119 | end | end |
120 | |||
121 | |||
122 | |||
123 | |||
124 | |||
125 | |||
126 | |||
127 | |||
128 |
File data_analysis/auxfunctions/plots/linspecer.m changed (mode: 100644) (index bf242c3..faeaada) | |||
2 | 2 | % This function creates an Nx3 array of N [R B G] colors | % This function creates an Nx3 array of N [R B G] colors |
3 | 3 | % These can be used to plot lots of lines with distinguishable and nice | % These can be used to plot lots of lines with distinguishable and nice |
4 | 4 | % looking colors. | % looking colors. |
5 | % | ||
5 | % | ||
6 | 6 | % lineStyles = linspecer(N); makes N colors for you to use: lineStyles(ii,:) | % lineStyles = linspecer(N); makes N colors for you to use: lineStyles(ii,:) |
7 | % | ||
8 | % colormap(linspecer); set your colormap to have easily distinguishable | ||
7 | % | ||
8 | % colormap(linspecer); set your colormap to have easily distinguishable | ||
9 | 9 | % colors and a pleasing aesthetic | % colors and a pleasing aesthetic |
10 | % | ||
10 | % | ||
11 | 11 | % lineStyles = linspecer(N,'qualitative'); forces the colors to all be distinguishable (up to 12) | % lineStyles = linspecer(N,'qualitative'); forces the colors to all be distinguishable (up to 12) |
12 | % lineStyles = linspecer(N,'sequential'); forces the colors to vary along a spectrum | ||
13 | % | ||
12 | % lineStyles = linspecer(N,'sequential'); forces the colors to vary along a spectrum | ||
13 | % | ||
14 | 14 | % % Examples demonstrating the colors. | % % Examples demonstrating the colors. |
15 | % | ||
15 | % | ||
16 | 16 | % LINE COLORS | % LINE COLORS |
17 | 17 | % N=6; | % N=6; |
18 | % X = linspace(0,pi*3,1000); | ||
19 | % Y = bsxfun(@(x,n)sin(x+2*n*pi/N), X.', 1:N); | ||
18 | % X = linspace(0,pi*3,1000); | ||
19 | % Y = bsxfun(@(x,n)sin(x+2*n*pi/N), X.', 1:N); | ||
20 | 20 | % C = linspecer(N); | % C = linspecer(N); |
21 | 21 | % axes('NextPlot','replacechildren', 'ColorOrder',C); | % axes('NextPlot','replacechildren', 'ColorOrder',C); |
22 | 22 | % plot(X,Y,'linewidth',5) | % plot(X,Y,'linewidth',5) |
23 | 23 | % ylim([-1.1 1.1]); | % ylim([-1.1 1.1]); |
24 | % | ||
24 | % | ||
25 | 25 | % SIMPLER LINE COLOR EXAMPLE | % SIMPLER LINE COLOR EXAMPLE |
26 | 26 | % N = 6; X = linspace(0,pi*3,1000); | % N = 6; X = linspace(0,pi*3,1000); |
27 | 27 | % C = linspecer(N) | % C = linspecer(N) |
31 | 31 | % plot(X,Y,'color',C(ii,:),'linewidth',3); | % plot(X,Y,'color',C(ii,:),'linewidth',3); |
32 | 32 | % hold on; | % hold on; |
33 | 33 | % end | % end |
34 | % | ||
34 | % | ||
35 | 35 | % COLORMAP EXAMPLE | % COLORMAP EXAMPLE |
36 | 36 | % A = rand(15); | % A = rand(15); |
37 | 37 | % figure; imagesc(A); % default colormap | % figure; imagesc(A); % default colormap |
38 | 38 | % figure; imagesc(A); colormap(linspecer); % linspecer colormap | % figure; imagesc(A); colormap(linspecer); % linspecer colormap |
39 | % | ||
39 | % | ||
40 | 40 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
41 | 41 | % by Jonathan Lansey, March 2009-2013 � Lansey at gmail.com % | % by Jonathan Lansey, March 2009-2013 � Lansey at gmail.com % |
42 | 42 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
43 | % | ||
43 | % | ||
44 | 44 | %% credits and where the function came from | %% credits and where the function came from |
45 | 45 | % The colors are largely taken from: | % The colors are largely taken from: |
46 | 46 | % http://colorbrewer2.org and Cynthia Brewer, Mark Harrower and The Pennsylvania State University | % http://colorbrewer2.org and Cynthia Brewer, Mark Harrower and The Pennsylvania State University |
47 | % | ||
48 | % | ||
47 | % | ||
48 | % | ||
49 | 49 | % She studied this from a phsychometric perspective and crafted the colors | % She studied this from a phsychometric perspective and crafted the colors |
50 | 50 | % beautifully. | % beautifully. |
51 | % | ||
51 | % | ||
52 | 52 | % I made choices from the many there to decide the nicest once for plotting | % I made choices from the many there to decide the nicest once for plotting |
53 | 53 | % lines in Matlab. I also made a small change to one of the colors I | % lines in Matlab. I also made a small change to one of the colors I |
54 | 54 | % thought was a bit too bright. In addition some interpolation is going on | % thought was a bit too bright. In addition some interpolation is going on |
55 | 55 | % for the sequential line styles. | % for the sequential line styles. |
56 | % | ||
57 | % | ||
56 | % | ||
57 | % | ||
58 | 58 | %% | %% |
59 | 59 | ||
60 | 60 | function lineStyles=linspecer(N,varargin) | function lineStyles=linspecer(N,varargin) |
... | ... | if ~isempty(varargin)>0 % you set a parameter? | |
91 | 91 | otherwise | otherwise |
92 | 92 | warning(['parameter ''' varargin{1} ''' not recognized']); | warning(['parameter ''' varargin{1} ''' not recognized']); |
93 | 93 | end | end |
94 | end | ||
95 | |||
94 | end | ||
95 | |||
96 | 96 | % predefine some colormaps | % predefine some colormaps |
97 | 97 | set3 = colorBrew2mat({[141, 211, 199];[ 255, 237, 111];[ 190, 186, 218];[ 251, 128, 114];[ 128, 177, 211];[ 253, 180, 98];[ 179, 222, 105];[ 188, 128, 189];[ 217, 217, 217];[ 204, 235, 197];[ 252, 205, 229];[ 255, 255, 179]}'); | set3 = colorBrew2mat({[141, 211, 199];[ 255, 237, 111];[ 190, 186, 218];[ 251, 128, 114];[ 128, 177, 211];[ 253, 180, 98];[ 179, 222, 105];[ 188, 128, 189];[ 217, 217, 217];[ 204, 235, 197];[ 252, 205, 229];[ 255, 255, 179]}'); |
98 | 98 | set1JL = brighten(colorBrew2mat({[228, 26, 28];[ 55, 126, 184];[ 77, 175, 74];[ 255, 127, 0];[ 255, 237, 111]*.95;[ 166, 86, 40];[ 247, 129, 191];[ 153, 153, 153];[ 152, 78, 163]}')); | set1JL = brighten(colorBrew2mat({[228, 26, 28];[ 55, 126, 184];[ 77, 175, 74];[ 255, 127, 0];[ 255, 237, 111]*.95;[ 166, 86, 40];[ 247, 129, 191];[ 153, 153, 153];[ 152, 78, 163]}')); |
... | ... | end | |
123 | 123 | function varIn = colorBrew2mat(varIn) | function varIn = colorBrew2mat(varIn) |
124 | 124 | for ii=1:length(varIn) % just divide by 255 | for ii=1:length(varIn) % just divide by 255 |
125 | 125 | varIn{ii}=varIn{ii}/255; | varIn{ii}=varIn{ii}/255; |
126 | end | ||
126 | end | ||
127 | 127 | end | end |
128 | 128 | ||
129 | 129 | function varIn = brighten(varIn,varargin) % increase the brightness | function varIn = brighten(varIn,varargin) % increase the brightness |
130 | 130 | ||
131 | 131 | if isempty(varargin), | if isempty(varargin), |
132 | frac = .9; | ||
132 | frac = .9; | ||
133 | 133 | else | else |
134 | frac = varargin{1}; | ||
134 | frac = varargin{1}; | ||
135 | 135 | end | end |
136 | 136 | ||
137 | 137 | for ii=1:length(varIn) | for ii=1:length(varIn) |
138 | 138 | varIn{ii}=varIn{ii}*frac+(1-frac); | varIn{ii}=varIn{ii}*frac+(1-frac); |
139 | end | ||
139 | end | ||
140 | 140 | end | end |
141 | 141 | ||
142 | 142 | function varIn = dim(varIn,f) | function varIn = dim(varIn,f) |
File data_analysis/auxfunctions/plots/plotCorrelationMatrix.m changed (mode: 100644) (index b7bd875..4b8c1a8) | |||
1 | 1 | function plotCorrelationMatrix(cm, varargin) | function plotCorrelationMatrix(cm, varargin) |
2 | 2 | % plotCorrelationMatrix(cm, varargin) takes a covariance matrix cm and plots the entries of cm using a color encoding | % plotCorrelationMatrix(cm, varargin) takes a covariance matrix cm and plots the entries of cm using a color encoding |
3 | % | ||
3 | % | ||
4 | 4 | % customization via key-value-pairs: | % customization via key-value-pairs: |
5 | 5 | % - 'log', true (default: false): use logscale for the color scale | % - 'log', true (default: false): use logscale for the color scale |
6 | 6 | % - 'abs', true (default: false): plot the absolute values of the covariances | % - 'abs', true (default: false): plot the absolute values of the covariances |
... | ... | format = '%0.1e'; | |
22 | 22 | muted = false; | muted = false; |
23 | 23 | ||
24 | 24 | for k=1:2:length(varargin) | for k=1:2:length(varargin) |
25 | switch varargin{k} | ||
25 | switch varargin{k} | ||
26 | 26 | case {'abs', 'Abs'} | case {'abs', 'Abs'} |
27 | absvalues = varargin{k+1}; | ||
28 | case {'logscale', 'log', 'Log', 'Logscale', 'Log_scale'} | ||
29 | logscale = varargin{k+1}; | ||
27 | absvalues = varargin{k+1}; | ||
28 | case {'logscale', 'log', 'Log', 'Logscale', 'Log_scale'} | ||
29 | logscale = varargin{k+1}; | ||
30 | 30 | ||
31 | case {'title', 'title_string', 'Title', 'titlestring', 'Titlestring'} | ||
32 | title_string = varargin{k+1}; | ||
31 | case {'title', 'title_string', 'Title', 'titlestring', 'Titlestring'} | ||
32 | title_string = varargin{k+1}; | ||
33 | 33 | case {'show_labels', 'labels', 'Labels', 'Show_labels'} | case {'show_labels', 'labels', 'Labels', 'Show_labels'} |
34 | 34 | show_labels = varargin{k+1}; | show_labels = varargin{k+1}; |
35 | 35 | case {'colormap', 'Colormap'} | case {'colormap', 'Colormap'} |
36 | colormap = varargin{k+1}; | ||
37 | case {'fontsize', 'Fontsize'} | ||
38 | fontsize = varargin{k+1}; | ||
36 | colormap = varargin{k+1}; | ||
37 | case {'fontsize', 'Fontsize'} | ||
38 | fontsize = varargin{k+1}; | ||
39 | 39 | case {'format', 'Format'} | case {'format', 'Format'} |
40 | format = varargin{k+1}; | ||
40 | format = varargin{k+1}; | ||
41 | 41 | case {'mute', 'Mute'} | case {'mute', 'Mute'} |
42 | 42 | if varargin{k+1} | if varargin{k+1} |
43 | 43 | muted = true | muted = true |
44 | 44 | elseif ismember(varargin{k+1}, {'true', 'True'}) | elseif ismember(varargin{k+1}, {'true', 'True'}) |
45 | 45 | muted = true; | muted = true; |
46 | 46 | end | end |
47 | |||
48 | otherwise | ||
49 | error(['Unrecognized varargin-argument: ', varargin{k}]); | ||
50 | end | ||
47 | |||
48 | otherwise | ||
49 | error(['Unrecognized varargin-argument: ', varargin{k}]); | ||
50 | end | ||
51 | 51 | end | end |
52 | 52 | ||
53 | 53 | N = length(cm); | N = length(cm); |
... | ... | if absvalues | |
75 | 75 | colormap = 'summer'; | colormap = 'summer'; |
76 | 76 | end | end |
77 | 77 | % don't change colormap if a colormap was chose | % don't change colormap if a colormap was chose |
78 | cm = abs(cm); | ||
78 | cm = abs(cm); | ||
79 | 79 | end | end |
80 | 80 | ||
81 | 81 | ||
82 | 82 | if logscale | if logscale |
83 | heatmap(cm, labels, labels,... | ||
84 | format,'Colormap', colormap,... | ||
85 | 'UseLogColormap', true,... | ||
86 | 'FontSize', fontsize,... | ||
83 | heatmap(cm, labels, labels,... | ||
84 | format,'Colormap', colormap,... | ||
85 | 'UseLogColormap', true,... | ||
86 | 'FontSize', fontsize,... | ||
87 | 87 | 'Colorbar', {'SouthOutside'}, 'GridLines', ':'); | 'Colorbar', {'SouthOutside'}, 'GridLines', ':'); |
88 | 88 | else | else |
89 | heatmap(cm, labels, labels,... | ||
90 | format,'Colormap', colormap,... | ||
91 | 'FontSize', fontsize,... | ||
89 | heatmap(cm, labels, labels,... | ||
90 | format,'Colormap', colormap,... | ||
91 | 'FontSize', fontsize,... | ||
92 | 92 | 'Colorbar', {'SouthOutside'}, 'GridLines', ':'); | 'Colorbar', {'SouthOutside'}, 'GridLines', ':'); |
93 | 93 | end | end |
94 | 94 | ||
95 | 95 | title(title_string) | title(title_string) |
96 |
File data_analysis/auxfunctions/plots/quickCreateSaveNPS.m changed (mode: 100644) (index 17ba264..e14ace8) | |||
... | ... | titlestr = varargin{end-1}; | |
12 | 12 | filepath = varargin{end}; | filepath = varargin{end}; |
13 | 13 | ||
14 | 14 | for k = 1:2:length(varargin)-2 | for k = 1:2:length(varargin)-2 |
15 | assert(ischar(varargin{k}),['Legend string expected at position ', num2str(k)]); | ||
16 | assert(isnumeric(varargin{k+1}),['Numeric data expected at position ', num2str(k+1)]); | ||
15 | assert(ischar(varargin{k}),['Legend string expected at position ', num2str(k)]); | ||
16 | assert(isnumeric(varargin{k+1}),['Numeric data expected at position ', num2str(k+1)]); | ||
17 | 17 | ||
18 | datasetno = datasetno + 1; | ||
18 | datasetno = datasetno + 1; | ||
19 | 19 | ||
20 | legendstr = varargin{k}; | ||
21 | data = varargin{k+1}; | ||
20 | legendstr = varargin{k}; | ||
21 | data = varargin{k+1}; | ||
22 | 22 | ||
23 | [nps, freq] = pwelch(data, [], [], [], 70); | ||
23 | [nps, freq] = pwelch(data, [], [], [], 70); | ||
24 | 24 | ||
25 | plot(freq, pow2db(nps), 'o-.','color',cc(datasetno,:), 'MarkerFaceColor', cc(datasetno,:),... | ||
26 | 'LineWidth',1,'MarkerSize',2, 'DisplayName', legendstr); | ||
25 | plot(freq, pow2db(nps), 'o-.','color',cc(datasetno,:), 'MarkerFaceColor', cc(datasetno,:),... | ||
26 | 'LineWidth',1,'MarkerSize',2, 'DisplayName', legendstr); | ||
27 | 27 | end | end |
28 | 28 | title(titlestr, 'interpreter', 'none'); | title(titlestr, 'interpreter', 'none'); |
29 | 29 | xlabel('Frequency [in units of mechanical frequency]'); | xlabel('Frequency [in units of mechanical frequency]'); |
File data_analysis/auxfunctions/plots/sampleNPSfromMeasurementData.m changed (mode: 100644) (index d409a4d..20c2edb) | |||
... | ... | fid = fopen( filepath, 'r'); | |
15 | 15 | [],[],[], samplingRate); | [],[],[], samplingRate); |
16 | 16 | fclose(fid); | fclose(fid); |
17 | 17 | end | end |
18 |
File data_analysis/auxfunctions/postprocess/calibrate_cm.m changed (mode: 100644) (index 5907696..47d11c8) | |||
1 | 1 | function [cm_cal, shotnoise_cm_cal] = calibrate_cm(cm, shotnoise_cm) | function [cm_cal, shotnoise_cm_cal] = calibrate_cm(cm, shotnoise_cm) |
2 | assert(isequal(size(cm), size(shotnoise_cm)),... | ||
3 | 'Matrices must have the same shape!'); | ||
4 | assert(size(cm,1)==size(cm,1),... | ||
5 | 'Matrices must be quadratic.') | ||
6 | assert(mod(size(cm,1),2)==0,... | ||
7 | 'Matrices must have even number of rows and columns.') | ||
2 | assert(isequal(size(cm), size(shotnoise_cm)),... | ||
3 | 'Matrices must have the same shape!'); | ||
4 | assert(size(cm,1)==size(cm,1),... | ||
5 | 'Matrices must be quadratic.') | ||
6 | assert(mod(size(cm,1),2)==0,... | ||
7 | 'Matrices must have even number of rows and columns.') | ||
8 | 8 | ||
9 | mode_no = size(cm, 1)/2; | ||
10 | shotnoise_vars = diag(shotnoise_cm); | ||
11 | shotnoise_vars_means = mean(reshape(shotnoise_vars, 2, mode_no)); | ||
12 | shotnoise_std_devs = reshape(... | ||
13 | repmat(sqrt(shotnoise_vars_means),2,1),... | ||
14 | 2*mode_no,1); | ||
15 | calibration_mat = diag(1./shotnoise_std_devs)/sqrt(2); | ||
16 | |||
17 | cm_cal = calibration_mat*cm*calibration_mat; | ||
18 | shotnoise_cm_cal = calibration_mat*shotnoise_cm*calibration_mat; | ||
9 | mode_no = size(cm, 1)/2; | ||
10 | shotnoise_vars = diag(shotnoise_cm); | ||
11 | shotnoise_vars_means = mean(reshape(shotnoise_vars, 2, mode_no)); | ||
12 | shotnoise_std_devs = reshape(... | ||
13 | repmat(sqrt(shotnoise_vars_means),2,1),... | ||
14 | 2*mode_no,1); | ||
15 | calibration_mat = diag(1./shotnoise_std_devs)/sqrt(2); | ||
16 | |||
17 | cm_cal = calibration_mat*cm*calibration_mat; | ||
18 | shotnoise_cm_cal = calibration_mat*shotnoise_cm*calibration_mat; |
File data_analysis/auxfunctions/postprocess/calibrate_cm_test.m changed (mode: 100644) (index cde8426..6110da0) | |||
1 | 1 | function test_suite = calibrate_cm_test %#ok<STOUT> | function test_suite = calibrate_cm_test %#ok<STOUT> |
2 | initTestSuite; | ||
2 | initTestSuite; | ||
3 | 3 | ||
4 | 4 | function shotnoise_cm_test | function shotnoise_cm_test |
5 | mode_no = 10; | ||
6 | % expected mode order: q1, p1, q2, p2, x1, y1, x2, y2 | ||
7 | shotnoise_cm = diag([0.4, 0.6, 0.9, 1.1, 2.1, 1.9, 2, 3]); | ||
8 | shotnoise_cm_cal_exp = diag([0.4, 0.6, 0.45, 0.55, 0.525, 0.475, 0.4, 0.6]); | ||
9 | cm = randn(size(shotnoise_cm)); | ||
10 | |||
11 | [cm_cal, shotnoise_cm_cal] = calibrate_cm(cm, shotnoise_cm); | ||
12 | assertAlmostEqual(shotnoise_cm_cal, shotnoise_cm_cal_exp, 10*eps) | ||
5 | mode_no = 10; | ||
6 | % expected mode order: q1, p1, q2, p2, x1, y1, x2, y2 | ||
7 | shotnoise_cm = diag([0.4, 0.6, 0.9, 1.1, 2.1, 1.9, 2, 3]); | ||
8 | shotnoise_cm_cal_exp = diag([0.4, 0.6, 0.45, 0.55, 0.525, 0.475, 0.4, 0.6]); | ||
9 | cm = randn(size(shotnoise_cm)); | ||
10 | |||
11 | [cm_cal, shotnoise_cm_cal] = calibrate_cm(cm, shotnoise_cm); | ||
12 | assertAlmostEqual(shotnoise_cm_cal, shotnoise_cm_cal_exp, 10*eps) | ||
13 | 13 | ||
14 | 14 | function cm_multimode_trivial_test | function cm_multimode_trivial_test |
15 | mode_no = 10; | ||
16 | shotnoise_cm = diag(0.5*ones(2*mode_no,1)); | ||
17 | cm = randn(size(shotnoise_cm)); | ||
18 | |||
19 | [cm_cal, shotnoise_cm_cal] = calibrate_cm(cm, shotnoise_cm); | ||
20 | assertAlmostEqual(cm, cm_cal, 10*eps) | ||
15 | mode_no = 10; | ||
16 | shotnoise_cm = diag(0.5*ones(2*mode_no,1)); | ||
17 | cm = randn(size(shotnoise_cm)); | ||
18 | |||
19 | [cm_cal, shotnoise_cm_cal] = calibrate_cm(cm, shotnoise_cm); | ||
20 | assertAlmostEqual(cm, cm_cal, 10*eps) | ||
21 | 21 | ||
22 | 22 | function cm_multimode_almost_trivial_test | function cm_multimode_almost_trivial_test |
23 | mode_no = 10; | ||
24 | shotnoise_cm = diag(ones(2*mode_no,1)); | ||
25 | cm = randn(size(shotnoise_cm)); | ||
26 | |||
27 | [cm_cal, shotnoise_cm_cal] = calibrate_cm(cm, shotnoise_cm); | ||
28 | assertAlmostEqual(cm/2, cm_cal, 10*eps) | ||
23 | mode_no = 10; | ||
24 | shotnoise_cm = diag(ones(2*mode_no,1)); | ||
25 | cm = randn(size(shotnoise_cm)); | ||
26 | |||
27 | [cm_cal, shotnoise_cm_cal] = calibrate_cm(cm, shotnoise_cm); | ||
28 | assertAlmostEqual(cm/2, cm_cal, 10*eps) | ||
29 | 29 | ||
30 | 30 | function cm_singlemode_test | function cm_singlemode_test |
31 | shotnoise_cm = diag([0.9, 1.1, 1.9, 2.1]); | ||
32 | cm = randn(size(shotnoise_cm)); | ||
33 | [cm_cal, shotnoise_cm_cal] = calibrate_cm(cm, shotnoise_cm); | ||
34 | shotnoise_vars_check(shotnoise_cm_cal); | ||
31 | shotnoise_cm = diag([0.9, 1.1, 1.9, 2.1]); | ||
32 | cm = randn(size(shotnoise_cm)); | ||
33 | [cm_cal, shotnoise_cm_cal] = calibrate_cm(cm, shotnoise_cm); | ||
34 | shotnoise_vars_check(shotnoise_cm_cal); | ||
35 | 35 | ||
36 | 36 | function cm_twomode_test | function cm_twomode_test |
37 | shotnoise_cm = diag([0.9, 1.1, 1.9, 2.1, 3.9, 4.1, 5.9, 6.1]); | ||
38 | cm = randn(size(shotnoise_cm)); | ||
39 | [cm_cal, shotnoise_cm_cal] = calibrate_cm(cm, shotnoise_cm); | ||
40 | shotnoise_vars_check(shotnoise_cm_cal); | ||
37 | shotnoise_cm = diag([0.9, 1.1, 1.9, 2.1, 3.9, 4.1, 5.9, 6.1]); | ||
38 | cm = randn(size(shotnoise_cm)); | ||
39 | [cm_cal, shotnoise_cm_cal] = calibrate_cm(cm, shotnoise_cm); | ||
40 | shotnoise_vars_check(shotnoise_cm_cal); | ||
41 | 41 | ||
42 | 42 | function cm_twomode_invariance_test | function cm_twomode_invariance_test |
43 | shotnoise_cm = diag([0.9, 1.1, 1.9, 2.1, 3.9, 4.1, 5.9, 6.1]); | ||
44 | cm = randn(size(shotnoise_cm)); | ||
45 | [cm_cal, shotnoise_cm_cal] = calibrate_cm(cm, shotnoise_cm); | ||
46 | [cm_cal2, shotnoise_cm_cal2] = calibrate_cm(cm_cal, shotnoise_cm_cal); | ||
47 | |||
48 | assertElementsAlmostEqual(cm_cal, cm_cal2); | ||
49 | assertElementsAlmostEqual(shotnoise_cm_cal, shotnoise_cm_cal2); | ||
43 | shotnoise_cm = diag([0.9, 1.1, 1.9, 2.1, 3.9, 4.1, 5.9, 6.1]); | ||
44 | cm = randn(size(shotnoise_cm)); | ||
45 | [cm_cal, shotnoise_cm_cal] = calibrate_cm(cm, shotnoise_cm); | ||
46 | [cm_cal2, shotnoise_cm_cal2] = calibrate_cm(cm_cal, shotnoise_cm_cal); | ||
47 | |||
48 | assertElementsAlmostEqual(cm_cal, cm_cal2); | ||
49 | assertElementsAlmostEqual(shotnoise_cm_cal, shotnoise_cm_cal2); | ||
50 | 50 | ||
51 | 51 | function shotnoise_vars_check(cm) | function shotnoise_vars_check(cm) |
52 | mode_no = size(cm,1)/2; | ||
53 | means = mean(repmat(diag(cm),2,mode_no)); | ||
54 | assertElementsAlmostEqual(means, 0.5*ones(size(means))); | ||
52 | mode_no = size(cm,1)/2; | ||
53 | means = mean(repmat(diag(cm),2,mode_no)); | ||
54 | assertElementsAlmostEqual(means, 0.5*ones(size(means))); |
File data_analysis/auxfunctions/structs/export_fields.m changed (mode: 100644) (index 451e6fc..b3f2a44) | |||
8 | 8 | % export_fields(struc, fields, 'save', filename, 'force', BOOL) | % export_fields(struc, fields, 'save', filename, 'force', BOOL) |
9 | 9 | % overwrite the existing file | % overwrite the existing file |
10 | 10 | function [outstruct] = export_fields(struc, fields, varargin) | function [outstruct] = export_fields(struc, fields, varargin) |
11 | for i=1:length(fields) | ||
12 | field = fields{i}; | ||
13 | disp(field) | ||
14 | outstruct.(field) = struc.(field); | ||
15 | end | ||
11 | for i=1:length(fields) | ||
12 | field = fields{i}; | ||
13 | disp(field) | ||
14 | outstruct.(field) = struc.(field); | ||
15 | end | ||
16 | 16 | ||
17 | filename = ''; | ||
18 | force = false; | ||
19 | for k=1:2:length(varargin) | ||
20 | switch varargin{k} | ||
21 | case 'save' | ||
22 | filename = varargin{k+1}; | ||
23 | case 'force' | ||
24 | force = varargin{k+1}; | ||
25 | otherwise | ||
26 | error(['unrecognized varargin_argument: ',varargin{k}]); | ||
27 | end | ||
28 | end | ||
17 | filename = ''; | ||
18 | force = false; | ||
19 | for k=1:2:length(varargin) | ||
20 | switch varargin{k} | ||
21 | case 'save' | ||
22 | filename = varargin{k+1}; | ||
23 | case 'force' | ||
24 | force = varargin{k+1}; | ||
25 | otherwise | ||
26 | error(['unrecognized varargin_argument: ',varargin{k}]); | ||
27 | end | ||
28 | end | ||
29 | 29 | ||
30 | if filename | ||
31 | if ~force | ||
32 | assert(~isafile(filename), [filename, ' already exists!']); | ||
33 | end | ||
34 | save(filename, '-struct', 'outstruct') | ||
35 | end | ||
30 | if filename | ||
31 | if ~force | ||
32 | assert(~isafile(filename), [filename, ' already exists!']); | ||
33 | end | ||
34 | save(filename, '-struct', 'outstruct') | ||
35 | end | ||
36 | 36 | end | end |
37 | 37 | %target_fields = {'pulse_gammas', 'mech_frequencies', 'samples_per_pulse', 'logneg_corrected', 'tracepairs_no', 'samples_per_trace', 'pulse_pairs_per_trace', 'pulse_duration_periods', 'mech_frequencies_no', 'pulse_gammas_no', 'samplingrate', 'signal_power_muW'} | %target_fields = {'pulse_gammas', 'mech_frequencies', 'samples_per_pulse', 'logneg_corrected', 'tracepairs_no', 'samples_per_trace', 'pulse_pairs_per_trace', 'pulse_duration_periods', 'mech_frequencies_no', 'pulse_gammas_no', 'samplingrate', 'signal_power_muW'} |
File data_analysis/auxfunctions/structs/getPropertyQueryFunction.m changed (mode: 100644) (index 7f9e332..57eb43c) | |||
1 | 1 | function getPropFunction = getPropertyQueryFunction( property) | function getPropFunction = getPropertyQueryFunction( property) |
2 | getPropFunction = @(object)(object.(property)); | ||
2 | getPropFunction = @(object)(object.(property)); | ||
3 | 3 | end | end |
File data_analysis/entanglement/calculate_pulsed_logneg_theory.m changed (mode: 100644) (index d84e5eb..0dd7ab0) | |||
... | ... | function [model] = calculate_pulsed_logneg_theory(varargin) | |
4 | 4 | % and returns model augmented by the fields pulse_gammas and log_neg | % and returns model augmented by the fields pulse_gammas and log_neg |
5 | 5 | % | % |
6 | 6 | % model = calculate_pulsed_logneg_theory() does the same using | % model = calculate_pulsed_logneg_theory() does the same using |
7 | % model.mat in the current directory | ||
7 | % model.mat in the current directory | ||
8 | 8 | if nargin==0 | if nargin==0 |
9 | 9 | disp(['using model.mat in ',10, pwd]); | disp(['using model.mat in ',10, pwd]); |
10 | 10 | load(fullfile(pwd,'model.mat')); | load(fullfile(pwd,'model.mat')); |
File data_analysis/entanglement/combine_evaluations.m changed (mode: 100644) (index 82cf05e..1d4f092) | |||
... | ... | end | |
27 | 27 | % second index l .... pulse width | % second index l .... pulse width |
28 | 28 | % %% | % %% |
29 | 29 | % for k=1:5 | % for k=1:5 |
30 | % figure; | ||
30 | % figure; | ||
31 | 31 | % plotCorrelationMatrix(cov(combine_traces(k,5))) | % plotCorrelationMatrix(cov(combine_traces(k,5))) |
32 | 32 | % end | % end |
33 | % | ||
33 | % | ||
34 | 34 | % %% | % %% |
35 | 35 | % for l=3:6 | % for l=3:6 |
36 | % figure; | ||
36 | % figure; | ||
37 | 37 | % plotCorrelationMatrix(cov(combine_traces(3,l))) | % plotCorrelationMatrix(cov(combine_traces(3,l))) |
38 | 38 | % end | % end |
39 | 39 |
File data_analysis/entanglement/running_logneg_CM.m changed (mode: 100644) (index 67bb9fe..f43c86d) | |||
... | ... | dttcm = zeros(107,1); dttln = zeros(107,1); | |
8 | 8 | start=5; stop=12; | start=5; stop=12; |
9 | 9 | for gamind = start:stop | for gamind = start:stop |
10 | 10 | gamma = pulse_gammas(gamind); | gamma = pulse_gammas(gamind); |
11 | |||
12 | %% calculate theory CM and logneg | ||
11 | |||
12 | %% calculate theory CM and logneg | ||
13 | 13 | if true%set theory parameters | if true%set theory parameters |
14 | 14 | omm = model.om.omm; | omm = model.om.omm; |
15 | 15 | omd = omm; % demodulation frequency | omd = omm; % demodulation frequency |
... | ... | for gamind = start:stop | |
26 | 26 | end | end |
27 | 27 | fref = model.om.exp_omm/(2*pi); | fref = model.om.exp_omm/(2*pi); |
28 | 28 | pulsegamma = gamma/fref; | pulsegamma = gamma/fref; |
29 | |||
29 | |||
30 | 30 | ||
31 | 31 | theorycm = pccovbm(cp*nmech*ga, ga, 2*pi*pulsegamma,nmech,1-eta,omd,omm); | theorycm = pccovbm(cp*nmech*ga, ga, 2*pi*pulsegamma,nmech,1-eta,omd,omm); |
32 | theoryln = real(logneg(theorycm)); | ||
33 | |||
32 | theoryln = real(logneg(theorycm)); | ||
33 | |||
34 | 34 | %% data | %% data |
35 | 35 | snvar = mean(diag(pulse_CM{1}{gamind})); | snvar = mean(diag(pulse_CM{1}{gamind})); |
36 | 36 | array = [... | array = [... |
... | ... | for gamind = start:stop | |
42 | 42 | %% calculate running logneg and CM | %% calculate running logneg and CM |
43 | 43 | interval = 100; | interval = 100; |
44 | 44 | [covs, means] = running_stats(array, interval); | [covs, means] = running_stats(array, interval); |
45 | |||
45 | |||
46 | 46 | %dual homo correction | %dual homo correction |
47 | 47 | covs = cellfun(@(cm) (2*cm-eye(4)/2), covs, 'UniformOutput',false); | covs = cellfun(@(cm) (2*cm-eye(4)/2), covs, 'UniformOutput',false); |
48 | 48 | lognegs = cellfun(@logneg, covs); | lognegs = cellfun(@logneg, covs); |
49 | |||
49 | |||
50 | 50 | stepno = length(covs); | stepno = length(covs); |
51 | 51 | ||
52 | 52 | %% distances to theory | %% distances to theory |
... | ... | for gamind = start:stop | |
56 | 56 | ||
57 | 57 | %% distances to final | %% distances to final |
58 | 58 | finalcm = covs{stepno}; | finalcm = covs{stepno}; |
59 | finalln = lognegs(stepno); | ||
59 | finalln = lognegs(stepno); | ||
60 | 60 | distances_to_final = cellfun(@(cm) norm(cm-finalcm)/norm(finalcm), covs); | distances_to_final = cellfun(@(cm) norm(cm-finalcm)/norm(finalcm), covs); |
61 | 61 | ln_distances_to_final = abs((lognegs-finalln)/finalln); | ln_distances_to_final = abs((lognegs-finalln)/finalln); |
62 | |||
62 | |||
63 | 63 | %% add to average | %% add to average |
64 | 64 | dtfcm = dtfcm + distances_to_final; | dtfcm = dtfcm + distances_to_final; |
65 | 65 | dtfln = dtfln + ln_distances_to_final; | dtfln = dtfln + ln_distances_to_final; |
File data_analysis/gaussianity/gaussianity_plots.m changed (mode: 100644) (index 73ffa2b..ea05ffa) | |||
1 | 1 | function gaussianity_plots(trace, varargin) | function gaussianity_plots(trace, varargin) |
2 | 2 | % don't show figures while batch processing | % don't show figures while batch processing |
3 | 3 | set(0,'DefaultFigureVisible','off') | set(0,'DefaultFigureVisible','off') |
4 | |||
4 | |||
5 | 5 | quadno = size(trace,2); | quadno = size(trace,2); |
6 | 6 | modeno = quadno/4; | modeno = quadno/4; |
7 | 7 | assert((modeno==round(modeno))&&(modeno>0)); | assert((modeno==round(modeno))&&(modeno>0)); |
8 | |||
8 | |||
9 | 9 | figwidth = 560; | figwidth = 560; |
10 | 10 | figheight = 420; | figheight = 420; |
11 | |||
12 | modes = 1:modeno; | ||
11 | |||
12 | modes = 1:modeno; | ||
13 | 13 | subplotwidth = min(2,modeno); | subplotwidth = min(2,modeno); |
14 | 14 | subplotheight = ceil(modeno/subplotwidth); | subplotheight = ceil(modeno/subplotwidth); |
15 | |||
15 | |||
16 | 16 | normalize = true; | normalize = true; |
17 | 17 | export = false; | export = false; |
18 | 18 | mute = false; | mute = false; |
... | ... | function gaussianity_plots(trace, varargin) | |
47 | 47 | if subplotwidth > 3 | if subplotwidth > 3 |
48 | 48 | figwidth = (subplotwidth/3)*figwidth; | figwidth = (subplotwidth/3)*figwidth; |
49 | 49 | end | end |
50 | |||
50 | |||
51 | 51 | stddevs = std(trace); | stddevs = std(trace); |
52 | 52 | inset = ' '; | inset = ' '; |
53 | getstddevstr = @(modeind)[inset, 'q: ',num2str(stddevs(2*modeind-1)),10,... | ||
53 | getstddevstr = @(modeind)[inset, 'q: ',num2str(stddevs(2*modeind-1)),10,... | ||
54 | 54 | inset, 'p: ',num2str(stddevs(2*modeind)),10,... | inset, 'p: ',num2str(stddevs(2*modeind)),10,... |
55 | 55 | inset, 'x: ',num2str(stddevs(2*modeno + 2*modeind-1)),10,... | inset, 'x: ',num2str(stddevs(2*modeno + 2*modeind-1)),10,... |
56 | 56 | inset, 'y: ',num2str(stddevs(2*modeno + 2*modeind))]; | inset, 'y: ',num2str(stddevs(2*modeno + 2*modeind))]; |
... | ... | function gaussianity_plots(trace, varargin) | |
59 | 59 | trace(:,k) = trace(:,k)/stddevs(k); | trace(:,k) = trace(:,k)/stddevs(k); |
60 | 60 | end | end |
61 | 61 | end | end |
62 | |||
62 | |||
63 | 63 | getinds = @(modeind)[2*modeind-1, 2*modeind,... | getinds = @(modeind)[2*modeind-1, 2*modeind,... |
64 | 64 | 2*modeno + 2*modeind-1, 2*modeno + 2*modeind]; | 2*modeno + 2*modeind-1, 2*modeno + 2*modeind]; |
65 | 65 | getsubtrace = @(m)trace(:,getinds(m)); | getsubtrace = @(m)trace(:,getinds(m)); |
66 | |||
66 | |||
67 | 67 | if normalize | if normalize |
68 | 68 | normalizestr = [10, ' (data has been divided by its std. deviation)']; | normalizestr = [10, ' (data has been divided by its std. deviation)']; |
69 | 69 | else | else |
... | ... | function gaussianity_plots(trace, varargin) | |
73 | 73 | cdffig = figure('visible',visible,'position', [0, 0, figwidth, figheight]); | cdffig = figure('visible',visible,'position', [0, 0, figwidth, figheight]); |
74 | 74 | qqfig = figure('visible',visible,'position', [0, 0, figwidth, figheight]); | qqfig = figure('visible',visible,'position', [0, 0, figwidth, figheight]); |
75 | 75 | kdensfig = figure('visible',visible,'position', [0, 0, figwidth, figheight]); | kdensfig = figure('visible',visible,'position', [0, 0, figwidth, figheight]); |
76 | |||
76 | |||
77 | 77 | if mute | if mute |
78 | 78 | postprocess = @(m){ title('');... | postprocess = @(m){ title('');... |
79 | 79 | ntitle([inset, 'Mode ',num2str(m)],... | ntitle([inset, 'Mode ',num2str(m)],... |
... | ... | function gaussianity_plots(trace, varargin) | |
88 | 88 | 'location','northwest');... | 'location','northwest');... |
89 | 89 | legend({'q','p','x','y'}, 'Location', 'SouthEast')}; | legend({'q','p','x','y'}, 'Location', 'SouthEast')}; |
90 | 90 | end | end |
91 | s = 0; | ||
91 | s = 0; | ||
92 | 92 | for m=modes | for m=modes |
93 | 93 | s = s + 1; | s = s + 1; |
94 | 94 | change_current_figure(histfig); subplot(subplotheight, subplotwidth, s); hold all | change_current_figure(histfig); subplot(subplotheight, subplotwidth, s); hold all |
... | ... | function gaussianity_plots(trace, varargin) | |
98 | 98 | if mute && s==numel(modes) | if mute && s==numel(modes) |
99 | 99 | legend({'q','p','x','y'}, 'Location', 'SouthEastOutside'); | legend({'q','p','x','y'}, 'Location', 'SouthEastOutside'); |
100 | 100 | end | end |
101 | |||
101 | |||
102 | 102 | change_current_figure(cdffig); subplot(subplotheight, subplotwidth, s); hold all | change_current_figure(cdffig); subplot(subplotheight, subplotwidth, s); hold all |
103 | 103 | arrayfun(@(n)cdfplot(trace(:,n)), getinds(m)); | arrayfun(@(n)cdfplot(trace(:,n)), getinds(m)); |
104 | 104 | postprocess(m); | postprocess(m); |
... | ... | function gaussianity_plots(trace, varargin) | |
106 | 106 | if mute && s==numel(modes) | if mute && s==numel(modes) |
107 | 107 | legend({'q','p','x','y'}, 'Location', 'SouthEastOutside'); | legend({'q','p','x','y'}, 'Location', 'SouthEastOutside'); |
108 | 108 | end | end |
109 | |||
109 | |||
110 | 110 | change_current_figure(kdensfig); subplot(subplotheight, subplotwidth, s); hold all | change_current_figure(kdensfig); subplot(subplotheight, subplotwidth, s); hold all |
111 | 111 | arrayfun(@(n)ksdensity(trace(:,n)), getinds(m)); | arrayfun(@(n)ksdensity(trace(:,n)), getinds(m)); |
112 | 112 | postprocess(m); | postprocess(m); |
... | ... | function gaussianity_plots(trace, varargin) | |
114 | 114 | if mute && s==numel(modes) | if mute && s==numel(modes) |
115 | 115 | legend({'q','p','x','y'}, 'Location', 'SouthEastOutside'); | legend({'q','p','x','y'}, 'Location', 'SouthEastOutside'); |
116 | 116 | end | end |
117 | |||
117 | |||
118 | 118 | change_current_figure(qqfig); subplot(subplotheight, subplotwidth, s); hold all | change_current_figure(qqfig); subplot(subplotheight, subplotwidth, s); hold all |
119 | 119 | qqplot(getsubtrace(m)); | qqplot(getsubtrace(m)); |
120 | 120 | postprocess(m); | postprocess(m); |
... | ... | function gaussianity_plots(trace, varargin) | |
131 | 131 | change_current_figure(cdffig); mysuptitle('Empirical CDF'); set(cdffig, 'visible', visible) | change_current_figure(cdffig); mysuptitle('Empirical CDF'); set(cdffig, 'visible', visible) |
132 | 132 | change_current_figure(kdensfig); mysuptitle('Kernel density estimate'); set(kdensfig, 'visible', visible) | change_current_figure(kdensfig); mysuptitle('Kernel density estimate'); set(kdensfig, 'visible', visible) |
133 | 133 | change_current_figure(qqfig); mysuptitle('Quantile-quantile plot'); set(qqfig, 'visible', visible) | change_current_figure(qqfig); mysuptitle('Quantile-quantile plot'); set(qqfig, 'visible', visible) |
134 | |||
134 | |||
135 | 135 | if export | if export |
136 | 136 | % note: hist does not work with pdf export. | % note: hist does not work with pdf export. |
137 | 137 | export_fig(histfig, [exportstr, '_', 'hist'],... | export_fig(histfig, [exportstr, '_', 'hist'],... |
... | ... | function gaussianity_plots(trace, varargin) | |
144 | 144 | '-pdf','-transparent') | '-pdf','-transparent') |
145 | 145 | end | end |
146 | 146 | end | end |
147 | |||
148 | |||
147 | |||
148 | |||
149 | 149 | ||
150 | 150 | ||
151 | 151 |
File data_analysis/gaussianity/gaussianity_plots_2d.m changed (mode: 100644) (index 5144ccc..3b48a27) | |||
... | ... | function gaussianity_plots_2d(trace, varargin) | |
2 | 2 | quadno = size(trace,2); | quadno = size(trace,2); |
3 | 3 | modeno = quadno/4; | modeno = quadno/4; |
4 | 4 | assert((modeno==round(modeno))&&(modeno>0)); | assert((modeno==round(modeno))&&(modeno>0)); |
5 | |||
6 | modes = 1:modeno; | ||
5 | |||
6 | modes = 1:modeno; | ||
7 | 7 | quadlabels = cell(1,4*modeno); | quadlabels = cell(1,4*modeno); |
8 | 8 | for m=modes | for m=modes |
9 | 9 | quadlabels{2*m-1} = ['q',num2str(m)]; | quadlabels{2*m-1} = ['q',num2str(m)]; |
... | ... | function gaussianity_plots_2d(trace, varargin) | |
11 | 11 | quadlabels{2*modeno+2*m-1} = ['x',num2str(m)]; | quadlabels{2*modeno+2*m-1} = ['x',num2str(m)]; |
12 | 12 | quadlabels{2*modeno+2*m} = ['y',num2str(m)]; | quadlabels{2*modeno+2*m} = ['y',num2str(m)]; |
13 | 13 | end | end |
14 | |||
14 | |||
15 | 15 | normalize = true; | normalize = true; |
16 | 16 | export = false; | export = false; |
17 | 17 | visible = 'on'; | visible = 'on'; |
... | ... | function gaussianity_plots_2d(trace, varargin) | |
30 | 30 | case {'export','Export','save','Save'} | case {'export','Export','save','Save'} |
31 | 31 | if ~(varargin{k+1}==false) | if ~(varargin{k+1}==false) |
32 | 32 | export = true; | export = true; |
33 | visible = 'off'; | ||
33 | visible = 'off'; | ||
34 | 34 | exportstr = varargin{k+1}; | exportstr = varargin{k+1}; |
35 | 35 | end | end |
36 | 36 | otherwise | otherwise |
37 | 37 | error(['Unrecognized varargin-argument: ', varargin{k}]) | error(['Unrecognized varargin-argument: ', varargin{k}]) |
38 | 38 | end | end |
39 | 39 | end | end |
40 | |||
40 | |||
41 | 41 | stddevs = std(trace); | stddevs = std(trace); |
42 | 42 | getstddevstr = @(m,n)[' std. deviations of raw data: ',10,... | getstddevstr = @(m,n)[' std. deviations of raw data: ',10,... |
43 | ' ', quadlabels{m},': ', num2str(stddevs(m)),10,... | ||
43 | ' ', quadlabels{m},': ', num2str(stddevs(m)),10,... | ||
44 | 44 | ' ', quadlabels{n},': ', num2str(stddevs(n))]; | ' ', quadlabels{n},': ', num2str(stddevs(n))]; |
45 | 45 | if normalize | if normalize |
46 | 46 | for k=1:quadno | for k=1:quadno |
... | ... | function gaussianity_plots_2d(trace, varargin) | |
50 | 50 | ||
51 | 51 | getsubtrace = @(m)trace(:,m); | getsubtrace = @(m)trace(:,m); |
52 | 52 | gettracepair = @(m,n)(getsubtrace([m,n])); | gettracepair = @(m,n)(getsubtrace([m,n])); |
53 | |||
53 | |||
54 | 54 | fig = figure('visible', visible); hold all | fig = figure('visible', visible); hold all |
55 | 55 | kde_contour_2 = @(m,n) kde_contour(gettracepair(m,n),... | kde_contour_2 = @(m,n) kde_contour(gettracepair(m,n),... |
56 | 56 | quadlabels{m}, quadlabels{n},... | quadlabels{m}, quadlabels{n},... |
57 | 57 | [titlestr,10,getstddevstr(m,n)]); | [titlestr,10,getstddevstr(m,n)]); |
58 | 58 | for k=1:numel(modeorder) | for k=1:numel(modeorder) |
59 | 59 | quads = modeorder{k}; | quads = modeorder{k}; |
60 | subplot(subplotheight, subplotwidth,k); | ||
60 | subplot(subplotheight, subplotwidth,k); | ||
61 | 61 | kde_contour_2(quads(1), quads(2)) | kde_contour_2(quads(1), quads(2)) |
62 | 62 | if normalize | if normalize |
63 | 63 | mylim = 3; | mylim = 3; |
... | ... | function gaussianity_plots_2d(trace, varargin) | |
67 | 67 | end | end |
68 | 68 | suptitle(['Bivariate distribution for ',... | suptitle(['Bivariate distribution for ',... |
69 | 69 | titlestr],'plotregion',0.95) | titlestr],'plotregion',0.95) |
70 | |||
70 | |||
71 | 71 | if export | if export |
72 | 72 | filename = [exportstr, '_', 'hist2d.pdf']; | filename = [exportstr, '_', 'hist2d.pdf']; |
73 | 73 | saveas(fig,filename) | saveas(fig,filename) |
... | ... | function [] = kde_contour(data, xlab, ylab, titlestr) | |
79 | 79 | cmap = cbrewer('seq','Blues',50); | cmap = cbrewer('seq','Blues',50); |
80 | 80 | contourf(X,Y,density); colorbar; colormap(cmap); | contourf(X,Y,density); colorbar; colormap(cmap); |
81 | 81 | xlabel(xlab); ylabel(ylab); | xlabel(xlab); ylabel(ylab); |
82 | |||
83 |
File data_analysis/obsolete/@entanglement_evaluation_obsolete/entanglement_evaluation_obsolete.m changed (mode: 100644) (index 8ba1cfb..cbf4731) | |||
1 | 1 | classdef entanglement_evaluation_obsolete < class_conveniences | classdef entanglement_evaluation_obsolete < class_conveniences |
2 | % entanglement_evaluation_obsolete is a handle class | ||
3 | % which collects deprecated methods and properties of the | ||
4 | % entanglement_evaluation class | ||
5 | properties(Hidden) | ||
6 | quality_factors@double vector % for each mode | ||
2 | % entanglement_evaluation_obsolete is a handle class | ||
3 | % which collects deprecated methods and properties of the | ||
4 | % entanglement_evaluation class | ||
5 | properties(Hidden) | ||
6 | quality_factors@double vector % for each mode | ||
7 | 7 | coupling_rates@double vector % linearized coupling for each mode | coupling_rates@double vector % linearized coupling for each mode |
8 | 8 | bare_couplings@double vector % single-photon coupling for each mode | bare_couplings@double vector % single-photon coupling for each mode |
9 | 9 | ||
... | ... | classdef entanglement_evaluation_obsolete < class_conveniences | |
14 | 14 | ||
15 | 15 | opt_pulse_widths@double vector % optimal pulsewidth acc. to singlemode theory | opt_pulse_widths@double vector % optimal pulsewidth acc. to singlemode theory |
16 | 16 | opt_log_negs@double vector % optimal logneg acc. to singlemode theory | opt_log_negs@double vector % optimal logneg acc. to singlemode theory |
17 | end | ||
17 | end | ||
18 | 18 | ||
19 | properties(Hidden, Transient, Dependent) | ||
20 | pulse_Q@cell matrix | ||
19 | properties(Hidden, Transient, Dependent) | ||
20 | pulse_Q@cell matrix | ||
21 | 21 | pulse_P@cell matrix | pulse_P@cell matrix |
22 | 22 | pulse_X@cell matrix | pulse_X@cell matrix |
23 | 23 | pulse_Y@cell matrix | pulse_Y@cell matrix |
24 | 24 | end | end |
25 | 25 | ||
26 | 26 | properties(Hidden, Dependent) | properties(Hidden, Dependent) |
27 | cooperativities@double vector % cooperativity from g, kappa, gamma, T for each mode | ||
27 | cooperativities@double vector % cooperativity from g, kappa, gamma, T for each mode | ||
28 | 28 | nbars@double vector %thermal occupation from T and omega for each mode | nbars@double vector %thermal occupation from T and omega for each mode |
29 | 29 | omegas@double vector %mechanical frequencies for each mode | omegas@double vector %mechanical frequencies for each mode |
30 | 30 | gammas@double vector %mechanical linewidths from Q and omega for each mode | gammas@double vector %mechanical linewidths from Q and omega for each mode |
31 | end | ||
31 | end | ||
32 | 32 | ||
33 | 33 | properties(Hidden, Transient) | properties(Hidden, Transient) |
34 | 34 | correlation_functions@cell matrix | correlation_functions@cell matrix |
35 | 35 | end | end |
36 | 36 | ||
37 | methods(Static, Hidden) | ||
37 | methods(Static, Hidden) | ||
38 | 38 | [optWidth, optLogNeg] = findOptimalPulseWidth(g,kappa,gamma_m, n_bar) | [optWidth, optLogNeg] = findOptimalPulseWidth(g,kappa,gamma_m, n_bar) |
39 | 39 | end | end |
40 | 40 | ||
... | ... | classdef entanglement_evaluation_obsolete < class_conveniences | |
114 | 114 | gammas(k) = omega_m/Q; | gammas(k) = omega_m/Q; |
115 | 115 | end | end |
116 | 116 | end | end |
117 | end | ||
117 | end | ||
118 | 118 | end | end |
File data_analysis/obsolete/@entanglement_evaluation_obsolete/exportCrossCorrelationFunctions.m changed (mode: 100644) (index 6582a36..43a319e) | |||
... | ... | function obj = exportCrossCorrelationFunctions(obj) | |
2 | 2 | % saves the correlation fcts to suitably named files in obj.evaluation_folder | % saves the correlation fcts to suitably named files in obj.evaluation_folder |
3 | 3 | correlation_functions = {}; | correlation_functions = {}; |
4 | 4 | for tp=1:obj.tracepairs_no | for tp=1:obj.tracepairs_no |
5 | correlation_functions{tp} = obj.correlation_functions{tp}; | ||
5 | correlation_functions{tp} = obj.correlation_functions{tp}; | ||
6 | 6 | end | end |
7 | 7 | save(fullfile(obj.evaluation_folder, 'correlation_functions.mat'),... | save(fullfile(obj.evaluation_folder, 'correlation_functions.mat'),... |
8 | 8 | 'correlation_functions'); | 'correlation_functions'); |
File data_analysis/obsolete/@entanglement_evaluation_obsolete/findOptimalPulseWidth.m changed (mode: 100644) (index 2fd7a81..a998f56) | |||
... | ... | function [optWidth, optLogNeg] = findOptimalPulseWidth(g,kappa,gamma_m, n_bar) | |
5 | 5 | losses = 0; %losses do not change the optimal pulse width! | losses = 0; %losses do not change the optimal pulse width! |
6 | 6 | om_demod = 1; | om_demod = 1; |
7 | 7 | om_mech = 1; | om_mech = 1; |
8 | |||
8 | |||
9 | 9 | cm = pccovbm(g^2/kappa,gamma_m,pulse_width,n_bar,... | cm = pccovbm(g^2/kappa,gamma_m,pulse_width,n_bar,... |
10 | 10 | losses,om_demod, om_mech); | losses,om_demod, om_mech); |
11 | 11 | ln = logneg(cm); | ln = logneg(cm); |
File data_analysis/obsolete/@entanglement_evaluation_obsolete/getOptPulseWidths.m changed (mode: 100644) (index 9f8b0b4..0ee628b) | |||
... | ... | function obj = getOptPulseWidths(obj) | |
7 | 7 | gamma_m = obj.gammas(f); | gamma_m = obj.gammas(f); |
8 | 8 | kappa = obj.kappa; | kappa = obj.kappa; |
9 | 9 | ||
10 | %find the optimal pulse width for the above parameters | ||
10 | %find the optimal pulse width for the above parameters | ||
11 | 11 | [opt_pw, opt_ln] = obj.findOptimalPulseWidth(... | [opt_pw, opt_ln] = obj.findOptimalPulseWidth(... |
12 | 12 | g/omega_m, kappa/omega_m, gamma_m/omega_m, nbar); | g/omega_m, kappa/omega_m, gamma_m/omega_m, nbar); |
13 | 13 | obj.opt_pulse_widths(f) = opt_pw*omega_m; | obj.opt_pulse_widths(f) = opt_pw*omega_m; |
File data_analysis/obsolete/@entanglement_evaluation_obsolete/importCrossCorrelationFunctions.m changed (mode: 100644) (index 3776e25..6c1d672) | |||
1 | 1 | function obj = importCrossCorrelationFunctions(obj, folder) | function obj = importCrossCorrelationFunctions(obj, folder) |
2 | % reads the correlation fcts from suitably named files in folder | ||
2 | % reads the correlation fcts from suitably named files in folder | ||
3 | 3 | correlation_functions = load(fullfile(folder, 'correlation_functions.mat')); | correlation_functions = load(fullfile(folder, 'correlation_functions.mat')); |
4 | 4 | obj.correlation_functions = correlation_functions.correlation_functions; | obj.correlation_functions = correlation_functions.correlation_functions; |
5 | 5 | end | end |
File data_analysis/obsolete/plottable_property/noise_power_spectrum.m changed (mode: 100644) (index b059e31..bb0e31d) | |||
1 | 1 | classdef noise_power_spectrum < plottable_property | classdef noise_power_spectrum < plottable_property |
2 | %Uvarvstime = varianceVersusTime(timetrace) creates an object with | ||
2 | %Uvarvstime = varianceVersusTime(timetrace) creates an object with | ||
3 | 3 | % PROPERTIES: | % PROPERTIES: |
4 | 4 | % - x : time | % - x : time |
5 | 5 | % - y : noisepower integrated from HF_cutoff to LF_cutoff | % - y : noisepower integrated from HF_cutoff to LF_cutoff |
6 | 6 | % - x_label, y_label | % - x_label, y_label |
7 | 7 | % - property_description | % - property_description |
8 | % | ||
8 | % | ||
9 | 9 | % varvstime is a plottable_property object | % varvstime is a plottable_property object |
10 | 10 | properties | properties |
11 | 11 | x | x |
... | ... | classdef noise_power_spectrum < plottable_property | |
14 | 14 | properties(Constant) | properties(Constant) |
15 | 15 | x_label = 'Frequency [Hz]'; | x_label = 'Frequency [Hz]'; |
16 | 16 | y_label = 'Noise power spectral density [V^2/Hz]' | y_label = 'Noise power spectral density [V^2/Hz]' |
17 | |||
17 | |||
18 | 18 | start_time = 0; | start_time = 0; |
19 | 19 | end_time = 0.1; | end_time = 0.1; |
20 | 20 | end | end |
21 | 21 | properties(Dependent) | properties(Dependent) |
22 | 22 | property_description | property_description |
23 | 23 | end | end |
24 | |||
24 | |||
25 | 25 | methods | methods |
26 | 26 | %% constructor | %% constructor |
27 | 27 | function obj = noise_power_spectrum(timetrace) | function obj = noise_power_spectrum(timetrace) |
28 | 28 | obj = obj@plottable_property(timetrace); | obj = obj@plottable_property(timetrace); |
29 | |||
29 | |||
30 | 30 | start_sample = timetrace.sample_from_time(obj.start_time); | start_sample = timetrace.sample_from_time(obj.start_time); |
31 | 31 | end_sample = timetrace.sample_from_time(obj.end_time); | end_sample = timetrace.sample_from_time(obj.end_time); |
32 | 32 | sample_no = end_sample - start_sample; | sample_no = end_sample - start_sample; |
33 | |||
33 | |||
34 | 34 | timetrace.fopen; | timetrace.fopen; |
35 | 35 | timetrace.fseek(start_sample); | timetrace.fseek(start_sample); |
36 | 36 | data = timetrace.fread(sample_no); | data = timetrace.fread(sample_no); |
37 | 37 | timetrace.fclose | timetrace.fclose |
38 | |||
38 | |||
39 | 39 | [obj.y,obj.x] = pwelch(data,[],[],[],timetrace.samplingrate); | [obj.y,obj.x] = pwelch(data,[],[],[],timetrace.samplingrate); |
40 | 40 | end | end |
41 | |||
41 | |||
42 | 42 | %% other | %% other |
43 | 43 | function desc =get.property_description(obj) | function desc =get.property_description(obj) |
44 | 44 | desc = ['Noise power spectral density for t=',... | desc = ['Noise power spectral density for t=',... |
45 | 45 | num2str(obj.start_time),' to t=',... | num2str(obj.start_time),' to t=',... |
46 | 46 | num2str(obj.end_time)]; | num2str(obj.end_time)]; |
47 | 47 | end | end |
48 | end | ||
48 | end | ||
49 | 49 | end | end |
File data_analysis/obsolete/plottable_property/plottable_property.m changed (mode: 100644) (index 439d2a1..55bc2d2) | |||
... | ... | classdef (Abstract) plottable_property | |
9 | 9 | % PROPERTIES: | % PROPERTIES: |
10 | 10 | % - x, y: x- and y-data | % - x, y: x- and y-data |
11 | 11 | % - x_label, y_label (Constant across all instances) | % - x_label, y_label (Constant across all instances) |
12 | % | ||
12 | % | ||
13 | 13 | % in addition plottable_property provides | % in addition plottable_property provides |
14 | 14 | % PROPERTIES | % PROPERTIES |
15 | % - dataset_label: dataset_label | ||
15 | % - dataset_label: dataset_label | ||
16 | 16 | % - some selfexplenatory prop.s controlling the plot | % - some selfexplenatory prop.s controlling the plot |
17 | 17 | % METHODS | % METHODS |
18 | 18 | % - plot: plot y vs x with suitable labels | % - plot: plot y vs x with suitable labels |
... | ... | classdef (Abstract) plottable_property | |
27 | 27 | properties(Abstract, Dependent) | properties(Abstract, Dependent) |
28 | 28 | property_description | property_description |
29 | 29 | end | end |
30 | properties | ||
30 | properties | ||
31 | 31 | dataset_label | dataset_label |
32 | 32 | end | end |
33 | 33 | properties(Constant) | properties(Constant) |
34 | 34 | LineWidth = 1.4; | LineWidth = 1.4; |
35 | 35 | MarkerSize = 3; | MarkerSize = 3; |
36 | 36 | end | end |
37 | |||
37 | |||
38 | 38 | methods | methods |
39 | 39 | function obj = plottable_property(timetrace) | function obj = plottable_property(timetrace) |
40 | 40 | assert(isa(timetrace, 'timetrace'),... | assert(isa(timetrace, 'timetrace'),... |
41 | 41 | 'Expecting a timetrace object'); | 'Expecting a timetrace object'); |
42 | 42 | obj.dataset_label = timetrace.dataset_label; | obj.dataset_label = timetrace.dataset_label; |
43 | 43 | end | end |
44 | |||
44 | |||
45 | 45 | function plot(obj, varargin) | function plot(obj, varargin) |
46 | 46 | plot(obj.x, obj.y, 'c-',... | plot(obj.x, obj.y, 'c-',... |
47 | 47 | 'DisplayName',obj.dataset_label,... | 'DisplayName',obj.dataset_label,... |
48 | 48 | 'LineWidth', obj.LineWidth,... | 'LineWidth', obj.LineWidth,... |
49 | 49 | 'MarkerSize',obj.MarkerSize,... | 'MarkerSize',obj.MarkerSize,... |
50 | 50 | varargin{:}); | varargin{:}); |
51 | |||
51 | |||
52 | 52 | xlabel(obj.x_label); | xlabel(obj.x_label); |
53 | 53 | ylabel(obj.y_label); | ylabel(obj.y_label); |
54 | 54 | t = title(obj.property_description); | t = title(obj.property_description); |
... | ... | classdef (Abstract) plottable_property | |
56 | 56 | set(t, 'Interpreter', 'none'); | set(t, 'Interpreter', 'none'); |
57 | 57 | set(l, 'Interpreter', 'none'); | set(l, 'Interpreter', 'none'); |
58 | 58 | end | end |
59 | |||
59 | |||
60 | 60 | end | end |
61 | 61 | end | end |
File data_analysis/obsolete/plottable_property/variance_versus_time.m changed (mode: 100644) (index 4788812..137bd32) | |||
1 | 1 | classdef variance_versus_time < plottable_property | classdef variance_versus_time < plottable_property |
2 | %Uvarvstime = variance_versus_time(timetrace) creates an object with | ||
2 | %Uvarvstime = variance_versus_time(timetrace) creates an object with | ||
3 | 3 | % PROPERTIES: | % PROPERTIES: |
4 | 4 | % - x : time | % - x : time |
5 | 5 | % - y : noisepower integrated from HF_cutoff to LF_cutoff | % - y : noisepower integrated from HF_cutoff to LF_cutoff |
6 | 6 | % - x_label, y_label | % - x_label, y_label |
7 | 7 | % - property_description | % - property_description |
8 | % | ||
8 | % | ||
9 | 9 | % varvstime is a plottable_property object | % varvstime is a plottable_property object |
10 | 10 | properties | properties |
11 | 11 | x | x |
... | ... | classdef variance_versus_time < plottable_property | |
14 | 14 | properties(Constant) | properties(Constant) |
15 | 15 | x_label = 'Time [s]'; | x_label = 'Time [s]'; |
16 | 16 | y_label = 'Integrated Noise power [V^2]' | y_label = 'Integrated Noise power [V^2]' |
17 | |||
17 | |||
18 | 18 | HF_cutoff = 2E6; | HF_cutoff = 2E6; |
19 | 19 | LF_cutoff = 1E3; | LF_cutoff = 1E3; |
20 | 20 | end | end |
21 | 21 | properties(Dependent) | properties(Dependent) |
22 | 22 | property_description | property_description |
23 | 23 | end | end |
24 | |||
24 | |||
25 | 25 | methods | methods |
26 | 26 | %% constructor | %% constructor |
27 | 27 | function obj = variance_versus_time(timetrace) | function obj = variance_versus_time(timetrace) |
28 | 28 | obj = obj@plottable_property(timetrace); | obj = obj@plottable_property(timetrace); |
29 | 29 | samplingrate = timetrace.samplingrate; | samplingrate = timetrace.samplingrate; |
30 | |||
30 | |||
31 | 31 | samples_to_skip = samplingrate/(2*obj.HF_cutoff); | samples_to_skip = samplingrate/(2*obj.HF_cutoff); |
32 | 32 | block_size = samplingrate/obj.LF_cutoff; | block_size = samplingrate/obj.LF_cutoff; |
33 | 33 | nBlocks = floor(timetrace.sample_no/... | nBlocks = floor(timetrace.sample_no/... |
... | ... | classdef variance_versus_time < plottable_property | |
37 | 37 | %%%% | %%%% |
38 | 38 | disp([10,'calculating variance vs time for '... | disp([10,'calculating variance vs time for '... |
39 | 39 | timetrace.filename,'...',10]) | timetrace.filename,'...',10]) |
40 | |||
40 | |||
41 | 41 | fopen(timetrace); | fopen(timetrace); |
42 | 42 | for iBlock=1:nBlocks | for iBlock=1:nBlocks |
43 | 43 | data = fread(timetrace, block_size, samples_to_skip); | data = fread(timetrace, block_size, samples_to_skip); |
... | ... | classdef variance_versus_time < plottable_property | |
49 | 49 | fclose(timetrace); | fclose(timetrace); |
50 | 50 | obj.dataset_label = timetrace.dataset_label; | obj.dataset_label = timetrace.dataset_label; |
51 | 51 | end | end |
52 | |||
52 | |||
53 | 53 | %% other | %% other |
54 | 54 | function desc =get.property_description(obj) | function desc =get.property_description(obj) |
55 | 55 | desc = ['Noise power integrated from ',... | desc = ['Noise power integrated from ',... |
56 | 56 | num2str(obj.LF_cutoff), '[Hz] to ', ... | num2str(obj.LF_cutoff), '[Hz] to ', ... |
57 | 57 | num2str(obj.HF_cutoff), '[Hz].']; | num2str(obj.HF_cutoff), '[Hz].']; |
58 | 58 | end | end |
59 | end | ||
59 | end | ||
60 | 60 | end | end |
File data_analysis/unittests/PXItrace_test.m changed (mode: 100644) (index 6cdf1d1..63e28ea) | |||
1 | 1 | function test_suite = PXItrace_test %#ok<STOUT> | function test_suite = PXItrace_test %#ok<STOUT> |
2 | localFunctionHandles = cellfun(@str2func,... | ||
3 | which('-subfun', mfilename('fullpath')), 'UniformOutput', false); | ||
4 | test_suite = buildFunctionHandleTestSuite(localFunctionHandles); | ||
5 | |||
2 | localFunctionHandles = cellfun(@str2func,... | ||
3 | which('-subfun', mfilename('fullpath')), 'UniformOutput', false); | ||
4 | test_suite = buildFunctionHandleTestSuite(localFunctionHandles); | ||
5 | |||
6 | 6 | function shared = setup | function shared = setup |
7 | shared.DAQrange = 0; | ||
8 | shared.amplification = 10; | ||
9 | |||
10 | shared.sample_no = 1e4; | ||
11 | shared.data = randn(shared.sample_no,1); | ||
12 | |||
13 | shared.precision = 'double'; | ||
14 | shared.folder = tempname; | ||
15 | assert(~(exist(shared.folder)==7),... | ||
16 | [shared.folder, ' exists already.']); | ||
17 | mkdir(shared.folder) | ||
18 | shared.file = fullfile(shared.folder, '.PXItrace.dat'); | ||
19 | |||
20 | fid = fopen(shared.file,'w'); | ||
21 | fwrite(fid, shared.data, shared.precision); | ||
22 | fclose(fid); | ||
7 | shared.DAQrange = 0; | ||
8 | shared.amplification = 10; | ||
9 | |||
10 | shared.sample_no = 1e4; | ||
11 | shared.data = randn(shared.sample_no,1); | ||
12 | |||
13 | shared.precision = 'double'; | ||
14 | shared.folder = tempname; | ||
15 | assert(~(exist(shared.folder)==7),... | ||
16 | [shared.folder, ' exists already.']); | ||
17 | mkdir(shared.folder) | ||
18 | shared.file = fullfile(shared.folder, '.PXItrace.dat'); | ||
19 | |||
20 | fid = fopen(shared.file,'w'); | ||
21 | fwrite(fid, shared.data, shared.precision); | ||
22 | fclose(fid); | ||
23 | 23 | ||
24 | 24 | function teardown(shared) | function teardown(shared) |
25 | delete(shared.file); | ||
26 | rmdir(shared.folder); | ||
25 | delete(shared.file); | ||
26 | rmdir(shared.folder); | ||
27 | 27 | ||
28 | 28 | function pt = pt_setup_test(shared) | function pt = pt_setup_test(shared) |
29 | pt = PXItrace(shared.file,... | ||
30 | 'precision', shared.precision,... | ||
31 | 'DAQrange', shared.DAQrange,... | ||
32 | 'amplification', shared.amplification); | ||
29 | pt = PXItrace(shared.file,... | ||
30 | 'precision', shared.precision,... | ||
31 | 'DAQrange', shared.DAQrange,... | ||
32 | 'amplification', shared.amplification); | ||
33 | 33 | ||
34 | 34 | function pt = read_data_test(shared) | function pt = read_data_test(shared) |
35 | pt = pt_setup_test(shared); | ||
36 | pt.fopen(); | ||
37 | assertEqual(pt.fread(shared.sample_no), shared.data/shared.amplification); | ||
35 | pt = pt_setup_test(shared); | ||
36 | pt.fopen(); | ||
37 | assertEqual(pt.fread(shared.sample_no), shared.data/shared.amplification); | ||
38 | 38 | ||
39 | startingsample = 10; | ||
40 | sample_no = 2; | ||
41 | pt.fseek(startingsample); | ||
42 | assertEqual(... | ||
43 | pt.fread(sample_no),... | ||
44 | shared.data(startingsample:startingsample+sample_no-1)/shared.amplification); | ||
39 | startingsample = 10; | ||
40 | sample_no = 2; | ||
41 | pt.fseek(startingsample); | ||
42 | assertEqual(... | ||
43 | pt.fread(sample_no),... | ||
44 | shared.data(startingsample:startingsample+sample_no-1)/shared.amplification); | ||
45 | 45 | ||
46 | pt.fseek(1); | ||
47 | assertEqual(... | ||
48 | pt.fread(shared.sample_no),... | ||
49 | shared.data/shared.amplification); | ||
46 | pt.fseek(1); | ||
47 | assertEqual(... | ||
48 | pt.fread(shared.sample_no),... | ||
49 | shared.data/shared.amplification); | ||
50 | 50 | ||
51 | pt.fclose(); | ||
51 | pt.fclose(); | ||
52 | 52 | ||
53 | 53 | function pt = properties_test(shared) | function pt = properties_test(shared) |
54 | pt = pt_setup_test(shared); | ||
55 | assertEqual(pt.sample_no, shared.sample_no) | ||
56 | assertEqual(pt.precision, shared.precision) | ||
54 | pt = pt_setup_test(shared); | ||
55 | assertEqual(pt.sample_no, shared.sample_no) | ||
56 | assertEqual(pt.precision, shared.precision) | ||
57 | 57 | ||
58 | assertEqual(pt.DAQrange, shared.DAQrange) | ||
59 | assertEqual(pt.amplification, shared.amplification) | ||
58 | assertEqual(pt.DAQrange, shared.DAQrange) | ||
59 | assertEqual(pt.amplification, shared.amplification) | ||
60 | 60 | ||
61 | [folder, filename, fileext] = fileparts(shared.file); | ||
62 | assertEqual(pt.filepath, shared.file) | ||
63 | assertEqual(pt.directory, folder) | ||
64 | assertEqual(pt.filename, [filename, fileext]) | ||
61 | [folder, filename, fileext] = fileparts(shared.file); | ||
62 | assertEqual(pt.filepath, shared.file) | ||
63 | assertEqual(pt.directory, folder) | ||
64 | assertEqual(pt.filename, [filename, fileext]) | ||
65 | 65 | ||
66 | if pt.precision=='double' | ||
67 | assertEqual(pt.bytes_per_sample, 8) | ||
68 | end | ||
66 | if pt.precision=='double' | ||
67 | assertEqual(pt.bytes_per_sample, 8) | ||
68 | end | ||
69 | 69 | ||
70 | 70 | function pt = pseudohash_test(shared) | function pt = pseudohash_test(shared) |
71 | pt = pt_setup_test(shared); | ||
72 | assertEqual(... | ||
73 | pseudo_hash(shared.file),... | ||
74 | pt.pseudohash) | ||
71 | pt = pt_setup_test(shared); | ||
72 | assertEqual(... | ||
73 | pseudo_hash(shared.file),... | ||
74 | pt.pseudohash) | ||
75 | 75 | ||
76 | 76 | function pt = pseudohash_modified_test(shared) | function pt = pseudohash_modified_test(shared) |
77 | pt = pt_setup_test(shared); | ||
78 | % fid = fopen(shared.file, 'w'); | ||
79 | % %fwrite(fid, randn(1)); | ||
80 | % fclose(fid); | ||
81 | assertEqual(... | ||
82 | pseudo_hash(shared.file),... | ||
83 | pt.pseudohash) | ||
77 | pt = pt_setup_test(shared); | ||
78 | % fid = fopen(shared.file, 'w'); | ||
79 | % %fwrite(fid, randn(1)); | ||
80 | % fclose(fid); | ||
81 | assertEqual(... | ||
82 | pseudo_hash(shared.file),... | ||
83 | pt.pseudohash) | ||
84 | 84 | ||
85 | 85 | function pt = dummy_test(shared) | function pt = dummy_test(shared) |
86 | constructor_test = @()PXItrace(shared.file, 'dummy', true); | ||
87 | assertExceptionThrown(constructor_test, 'PXItrace:FileExists') | ||
88 | |||
89 | file = '.PXItrace_dummy.dat'; | ||
90 | pt = PXItrace(file, 'dummy', true); | ||
91 | assert(isafile(file)); | ||
92 | %delete(file); not necesary, since the dummy file is deleted upon destruction anyways.. | ||
86 | constructor_test = @()PXItrace(shared.file, 'dummy', true); | ||
87 | assertExceptionThrown(constructor_test, 'PXItrace:FileExists') | ||
88 | |||
89 | file = '.PXItrace_dummy.dat'; | ||
90 | pt = PXItrace(file, 'dummy', true); | ||
91 | assert(isafile(file)); | ||
92 | %delete(file); not necesary, since the dummy file is deleted upon destruction anyways.. | ||
93 | 93 | ||
94 | 94 | function pt = delete_dummy_test(shared) | function pt = delete_dummy_test(shared) |
95 | file = '.PXItrace_dummy.dat'; | ||
96 | pt = PXItrace(file, 'dummy', true); | ||
97 | % deleting the object should call the destructor which should delete the dummy file | ||
98 | clear('pt') | ||
99 | assert(~isafile(file)) | ||
95 | file = '.PXItrace_dummy.dat'; | ||
96 | pt = PXItrace(file, 'dummy', true); | ||
97 | % deleting the object should call the destructor which should delete the dummy file | ||
98 | clear('pt') | ||
99 | assert(~isafile(file)) |
File data_analysis/unittests/blocked_cross_correlation_test.m changed (mode: 100644) (index eb65bab..fa75520) | |||
1 | 1 | function test_suite = blocked_cross_correlation_test %#ok<STOUT> | function test_suite = blocked_cross_correlation_test %#ok<STOUT> |
2 | localFunctionHandles = cellfun(@str2func,... | ||
3 | which('-subfun', mfilename('fullpath')), 'UniformOutput', false); | ||
4 | test_suite = buildFunctionHandleTestSuite(localFunctionHandles); | ||
2 | localFunctionHandles = cellfun(@str2func,... | ||
3 | which('-subfun', mfilename('fullpath')), 'UniformOutput', false); | ||
4 | test_suite = buildFunctionHandleTestSuite(localFunctionHandles); | ||
5 | 5 | ||
6 | 6 | function shared = setup | function shared = setup |
7 | shared.sample_no = 1e2; | ||
8 | % NOTE: only get same results if blocked_cross_correlation can process all data! | ||
9 | % --> need to have shared.sample_no a multiple of block_size for the tests to pass.. | ||
10 | shared.x.data = randn(shared.sample_no, 1); | ||
11 | shared.p.data = randn(shared.sample_no, 1); | ||
12 | |||
13 | shared.precision = 'double'; | ||
14 | shared.DAQrange = 0; | ||
15 | shared.amplification = 1; | ||
16 | |||
17 | shared.folder = tempname; | ||
18 | assert(~(exist(shared.folder)==7),... | ||
19 | [shared.folder, ' exists already.']); | ||
20 | mkdir(shared.folder) | ||
21 | shared.x.file = fullfile(shared.folder, '.x.dat'); | ||
22 | shared.p.file = fullfile(shared.folder, '.p.dat'); | ||
23 | |||
24 | for mytrace = {shared.x, shared.p} | ||
25 | mytrace = mytrace{:}; | ||
26 | fid = fopen(mytrace.file,'w'); | ||
27 | fwrite(fid, mytrace.data, shared.precision); | ||
28 | fclose(fid); | ||
29 | end | ||
30 | myPXItrace = @(file)PXItrace(file,... | ||
31 | 'precision', shared.precision,... | ||
32 | 'DAQrange',shared.DAQrange,... | ||
33 | 'amplification', shared.amplification); | ||
34 | shared.x.PXItrace = myPXItrace(shared.x.file); | ||
35 | shared.p.PXItrace = myPXItrace(shared.p.file); | ||
7 | shared.sample_no = 1e2; | ||
8 | % NOTE: only get same results if blocked_cross_correlation can process all data! | ||
9 | % --> need to have shared.sample_no a multiple of block_size for the tests to pass.. | ||
10 | shared.x.data = randn(shared.sample_no, 1); | ||
11 | shared.p.data = randn(shared.sample_no, 1); | ||
12 | |||
13 | shared.precision = 'double'; | ||
14 | shared.DAQrange = 0; | ||
15 | shared.amplification = 1; | ||
16 | |||
17 | shared.folder = tempname; | ||
18 | assert(~(exist(shared.folder)==7),... | ||
19 | [shared.folder, ' exists already.']); | ||
20 | mkdir(shared.folder) | ||
21 | shared.x.file = fullfile(shared.folder, '.x.dat'); | ||
22 | shared.p.file = fullfile(shared.folder, '.p.dat'); | ||
23 | |||
24 | for mytrace = {shared.x, shared.p} | ||
25 | mytrace = mytrace{:}; | ||
26 | fid = fopen(mytrace.file,'w'); | ||
27 | fwrite(fid, mytrace.data, shared.precision); | ||
28 | fclose(fid); | ||
29 | end | ||
30 | myPXItrace = @(file)PXItrace(file,... | ||
31 | 'precision', shared.precision,... | ||
32 | 'DAQrange',shared.DAQrange,... | ||
33 | 'amplification', shared.amplification); | ||
34 | shared.x.PXItrace = myPXItrace(shared.x.file); | ||
35 | shared.p.PXItrace = myPXItrace(shared.p.file); | ||
36 | 36 | ||
37 | 37 | function teardown(shared) | function teardown(shared) |
38 | for mytrace = {shared.x, shared.p} | ||
39 | mytrace = mytrace{:}; | ||
40 | delete(mytrace.file); | ||
41 | end | ||
42 | rmdir(shared.folder) | ||
38 | for mytrace = {shared.x, shared.p} | ||
39 | mytrace = mytrace{:}; | ||
40 | delete(mytrace.file); | ||
41 | end | ||
42 | rmdir(shared.folder) | ||
43 | 43 | ||
44 | 44 | function read_data_test(shared) | function read_data_test(shared) |
45 | for mytrace = {shared.x, shared.p} | ||
46 | mytrace = mytrace{:}; | ||
47 | mytrace.PXItrace.fopen(); | ||
48 | mydata = mytrace.PXItrace.fread(mytrace.PXItrace.sample_no); | ||
49 | mytrace.PXItrace.fclose(); | ||
45 | for mytrace = {shared.x, shared.p} | ||
46 | mytrace = mytrace{:}; | ||
47 | mytrace.PXItrace.fopen(); | ||
48 | mydata = mytrace.PXItrace.fread(mytrace.PXItrace.sample_no); | ||
49 | mytrace.PXItrace.fclose(); | ||
50 | 50 | ||
51 | assertEqual(mytrace.data, mydata); | ||
51 | assertEqual(mytrace.data, mydata); | ||
52 | 52 | end | end |
53 | 53 | ||
54 | 54 | function blocked_cross_correlation_regular_test(shared) | function blocked_cross_correlation_regular_test(shared) |
55 | max_lags = 10; | ||
55 | max_lags = 10; | ||
56 | 56 | xtrace = shared.x.PXItrace; | xtrace = shared.x.PXItrace; |
57 | 57 | ptrace = shared.p.PXItrace; | ptrace = shared.p.PXItrace; |
58 | 58 | ||
59 | [T, xp, xx, pp] = evalc('blocked_cross_correlation(xtrace, ptrace, max_lags);'); | ||
60 | % suppress std out from call to blocked_cross_correlation | ||
59 | [T, xp, xx, pp] = evalc('blocked_cross_correlation(xtrace, ptrace, max_lags);'); | ||
60 | % suppress std out from call to blocked_cross_correlation | ||
61 | 61 | ||
62 | 62 | rel_tol = 1e-13; | rel_tol = 1e-13; |
63 | assertElementsAlmostEqual(xx, flipud(xx), 'relative', rel_tol); | ||
64 | assertElementsAlmostEqual(pp, flipud(pp), 'relative', rel_tol); | ||
63 | assertElementsAlmostEqual(xx, flipud(xx), 'relative', rel_tol); | ||
64 | assertElementsAlmostEqual(pp, flipud(pp), 'relative', rel_tol); | ||
65 | 65 | ||
66 | xx_ = xcorr(shared.x.data, shared.x.data, max_lags); | ||
67 | xp_ = xcorr(shared.x.data, shared.p.data, max_lags); | ||
68 | assertElementsAlmostEqual(xx, xx_, 'relative', rel_tol); | ||
69 | assertElementsAlmostEqual(xp, xp_, 'relative', rel_tol); | ||
66 | xx_ = xcorr(shared.x.data, shared.x.data, max_lags); | ||
67 | xp_ = xcorr(shared.x.data, shared.p.data, max_lags); | ||
68 | assertElementsAlmostEqual(xx, xx_, 'relative', rel_tol); | ||
69 | assertElementsAlmostEqual(xp, xp_, 'relative', rel_tol); | ||
70 | 70 | ||
71 | 71 | function blocked_cross_correlation_methods_test(shared) | function blocked_cross_correlation_methods_test(shared) |
72 | max_lags = 2; | ||
72 | max_lags = 2; | ||
73 | 73 | ||
74 | 74 | xtrace = shared.x.PXItrace; | xtrace = shared.x.PXItrace; |
75 | 75 | ptrace = shared.p.PXItrace; | ptrace = shared.p.PXItrace; |
76 | 76 | ||
77 | 77 | for scaleopt = {'none', 'biased', 'unbiased', 'coeff'} | for scaleopt = {'none', 'biased', 'unbiased', 'coeff'} |
78 | scaleopt = scaleopt{:}; | ||
78 | scaleopt = scaleopt{:}; | ||
79 | 79 | ||
80 | [T, xp, xx, pp] = evalc('blocked_cross_correlation(xtrace, ptrace, max_lags, scaleopt);'); | ||
81 | % suppress std out from call to blocked_cross_correlation | ||
80 | [T, xp, xx, pp] = evalc('blocked_cross_correlation(xtrace, ptrace, max_lags, scaleopt);'); | ||
81 | % suppress std out from call to blocked_cross_correlation | ||
82 | 82 | ||
83 | rel_tol = 1e-13; | ||
84 | assertElementsAlmostEqual(xx, flipud(xx), 'relative', rel_tol); | ||
85 | assertElementsAlmostEqual(pp, flipud(pp), 'relative', rel_tol); | ||
83 | rel_tol = 1e-13; | ||
84 | assertElementsAlmostEqual(xx, flipud(xx), 'relative', rel_tol); | ||
85 | assertElementsAlmostEqual(pp, flipud(pp), 'relative', rel_tol); | ||
86 | 86 | ||
87 | xx_ = xcorr(shared.x.data, shared.x.data, max_lags, scaleopt); | ||
88 | xp_ = xcorr(shared.x.data, shared.p.data, max_lags, scaleopt); | ||
87 | xx_ = xcorr(shared.x.data, shared.x.data, max_lags, scaleopt); | ||
88 | xp_ = xcorr(shared.x.data, shared.p.data, max_lags, scaleopt); | ||
89 | 89 | ||
90 | assertElementsAlmostEqual(xx, xx_, 'relative', rel_tol); | ||
91 | assertElementsAlmostEqual(xp, xp_, 'relative', rel_tol); | ||
92 | end | ||
90 | assertElementsAlmostEqual(xx, xx_, 'relative', rel_tol); | ||
91 | assertElementsAlmostEqual(xp, xp_, 'relative', rel_tol); | ||
92 | end |
File data_analysis/unittests/entanglement_evaluation_test.m changed (mode: 100644) (index 9cfe5be..8f959b1) | |||
1 | 1 | function test_suite = entanglement_evaluation_test %#ok<STOUT> | function test_suite = entanglement_evaluation_test %#ok<STOUT> |
2 | localFunctionHandles = cellfun(@str2func,... | ||
3 | which('-subfun', mfilename('fullpath')), 'UniformOutput', false); | ||
4 | test_suite = buildFunctionHandleTestSuite(localFunctionHandles); | ||
2 | localFunctionHandles = cellfun(@str2func,... | ||
3 | which('-subfun', mfilename('fullpath')), 'UniformOutput', false); | ||
4 | test_suite = buildFunctionHandleTestSuite(localFunctionHandles); | ||
5 | 5 | ||
6 | 6 | function shared = setup | function shared = setup |
7 | shared.evaluation_folder = tempname; | ||
8 | assert(~(exist(shared.evaluation_folder)==7),... | ||
9 | [shared.evaluation_folder, ' exists already.']); | ||
10 | mkdir(shared.evaluation_folder) | ||
7 | shared.evaluation_folder = tempname; | ||
8 | assert(~(exist(shared.evaluation_folder)==7),... | ||
9 | [shared.evaluation_folder, ' exists already.']); | ||
10 | mkdir(shared.evaluation_folder) | ||
11 | 11 | ||
12 | shared.samplingrate = 100; | ||
13 | shared.sampleno = 1e4; | ||
12 | shared.samplingrate = 100; | ||
13 | shared.sampleno = 1e4; | ||
14 | 14 | ||
15 | shared.mech_freqs = [1, 1.345]; | ||
16 | shared.timevec = (0:shared.sampleno-1)'/shared.samplingrate; | ||
15 | shared.mech_freqs = [1, 1.345]; | ||
16 | shared.timevec = (0:shared.sampleno-1)'/shared.samplingrate; | ||
17 | 17 | ||
18 | shared.x.data = sin(2*pi*shared.mech_freqs(1)*shared.timevec) + sin(2*pi*shared.mech_freqs(2)*shared.timevec); | ||
19 | shared.p.data = cos(2*pi*shared.mech_freqs(1)*shared.timevec) + cos(2*pi*shared.mech_freqs(1)*shared.timevec); | ||
18 | shared.x.data = sin(2*pi*shared.mech_freqs(1)*shared.timevec) + sin(2*pi*shared.mech_freqs(2)*shared.timevec); | ||
19 | shared.p.data = cos(2*pi*shared.mech_freqs(1)*shared.timevec) + cos(2*pi*shared.mech_freqs(1)*shared.timevec); | ||
20 | 20 | ||
21 | shared.precision = 'double'; | ||
21 | shared.precision = 'double'; | ||
22 | 22 | ||
23 | shared.x.file = [tempname, '.dat']; | ||
24 | shared.p.file = [tempname, '.dat']; | ||
23 | shared.x.file = [tempname, '.dat']; | ||
24 | shared.p.file = [tempname, '.dat']; | ||
25 | 25 | ||
26 | for mytrace = {shared.x, shared.p} | ||
27 | mytrace = mytrace{:}; | ||
28 | fid = fopen(mytrace.file,'w'); | ||
29 | fwrite(fid, mytrace.data, shared.precision); | ||
30 | fclose(fid); | ||
31 | end | ||
26 | for mytrace = {shared.x, shared.p} | ||
27 | mytrace = mytrace{:}; | ||
28 | fid = fopen(mytrace.file,'w'); | ||
29 | fwrite(fid, mytrace.data, shared.precision); | ||
30 | fclose(fid); | ||
31 | end | ||
32 | 32 | ||
33 | 33 | function teardown(shared) | function teardown(shared) |
34 | for mytrace = {shared.x, shared.p} | ||
35 | mytrace = mytrace{:}; | ||
36 | delete(mytrace.file); | ||
37 | end | ||
38 | rmdir(shared.evaluation_folder, 's'); | ||
39 | clear('shared'); | ||
34 | for mytrace = {shared.x, shared.p} | ||
35 | mytrace = mytrace{:}; | ||
36 | delete(mytrace.file); | ||
37 | end | ||
38 | rmdir(shared.evaluation_folder, 's'); | ||
39 | clear('shared'); | ||
40 | 40 | ||
41 | 41 | %% OTHER AUX FUNCTIONS %% | %% OTHER AUX FUNCTIONS %% |
42 | 42 | function meas = dual_homo_measurement_setup(shared) | function meas = dual_homo_measurement_setup(shared) |
43 | meas = dual_homo_measurement('samplingrate', shared.samplingrate); | ||
44 | meas.add_trace_pair(... | ||
45 | shared.x.file,... | ||
46 | shared.p.file,... | ||
47 | 'precision',shared.precision,... | ||
48 | 'DAQrange', 0,... | ||
49 | 'amplification', 1,... | ||
50 | 'signal_power_muW', 0); | ||
51 | meas.add_trace_pair(... | ||
52 | shared.x.file,... | ||
53 | shared.p.file,... | ||
54 | 'precision',shared.precision,... | ||
55 | 'DAQrange', 0,... | ||
56 | 'amplification', 1,... | ||
57 | 'signal_power_muW', 100); | ||
43 | meas = dual_homo_measurement('samplingrate', shared.samplingrate); | ||
44 | meas.add_trace_pair(... | ||
45 | shared.x.file,... | ||
46 | shared.p.file,... | ||
47 | 'precision',shared.precision,... | ||
48 | 'DAQrange', 0,... | ||
49 | 'amplification', 1,... | ||
50 | 'signal_power_muW', 0); | ||
51 | meas.add_trace_pair(... | ||
52 | shared.x.file,... | ||
53 | shared.p.file,... | ||
54 | 'precision',shared.precision,... | ||
55 | 'DAQrange', 0,... | ||
56 | 'amplification', 1,... | ||
57 | 'signal_power_muW', 100); | ||
58 | 58 | %%%%%%%%%%%%%%%%%%%%%%%%%%%% | %%%%%%%%%%%%%%%%%%%%%%%%%%%% |
59 | 59 | ||
60 | 60 | function ev = ev_setup_test(shared) | function ev = ev_setup_test(shared) |
61 | meas = dual_homo_measurement_setup(shared); | ||
62 | ev = entanglement_evaluation('measurement', meas); | ||
63 | ev.evaluation_folder = shared.evaluation_folder; | ||
61 | meas = dual_homo_measurement_setup(shared); | ||
62 | ev = entanglement_evaluation('measurement', meas); | ||
63 | ev.evaluation_folder = shared.evaluation_folder; | ||
64 | 64 | ||
65 | 65 | function properties_test(shared) | function properties_test(shared) |
66 | ev = ev_setup_test(shared); | ||
67 | assertEqual(ev.samplingrate, shared.samplingrate); | ||
66 | ev = ev_setup_test(shared); | ||
67 | assertEqual(ev.samplingrate, shared.samplingrate); | ||
68 | 68 | ||
69 | 69 | function software_version_test(shared) | function software_version_test(shared) |
70 | ev = ev_setup_test(shared); | ||
71 | swv = ev.software_version; | ||
72 | assert(~isempty(swv) && isequal(class(swv), 'char')); | ||
73 | swv2 = ev.software_version; | ||
74 | assertEqual(swv, swv2); | ||
70 | ev = ev_setup_test(shared); | ||
71 | swv = ev.software_version; | ||
72 | assert(~isempty(swv) && isequal(class(swv), 'char')); | ||
73 | swv2 = ev.software_version; | ||
74 | assertEqual(swv, swv2); | ||
75 | 75 | ||
76 | 76 | function modefunctions_dummy_test(shared) | function modefunctions_dummy_test(shared) |
77 | ev = ev_setup_test(shared); | ||
78 | ev.mech_frequencies = [1, 2, 3]; | ||
79 | ev.pulse_gammas = logspace(-1,1,2); | ||
80 | [T,ev] = evalc('ev.calculateModeVectors(''dummy'',true)'); % supress std out from fct call | ||
77 | ev = ev_setup_test(shared); | ||
78 | ev.mech_frequencies = [1, 2, 3]; | ||
79 | ev.pulse_gammas = logspace(-1,1,2); | ||
80 | [T,ev] = evalc('ev.calculateModeVectors(''dummy'',true)'); % supress std out from fct call | ||
81 | 81 | ||
82 | 82 | function modefunctions_gammalist_test(shared) | function modefunctions_gammalist_test(shared) |
83 | ev = ev_setup_test(shared); | ||
84 | ev.mech_frequencies = [1, 3]; | ||
85 | gamma1_list = logspace(-3,-1,3); | ||
86 | gamma2_list = logspace(-3,-2,2); | ||
87 | gamma_lists = {gamma1_list, gamma2_list}; | ||
88 | ev.pulse_widths = allcomb(gamma_lists{:}); | ||
89 | ev.samples_per_pulse = round(ev.samples_per_pulse/100); | ||
90 | |||
91 | [T,ev] = evalc('ev.calculate_mode_vectors_gammalist()'); | ||
92 | |||
93 | % pulse_gammas is simply an index running over all possible combinations of pulse widths | ||
94 | % (in this version of the mode vector calculation) | ||
95 | assertEqual(ev.pulse_gammas, 1:length(gamma1_list)*length(gamma2_list)); | ||
96 | |||
97 | % estimate decay constant | ||
98 | testgammas_nonangular = zeros(size(ev.readout_modes,1),1); | ||
99 | for g=1:size(ev.readout_modes,1) | ||
100 | testmode = abs(ev.readout_modes(g,1:1000))'; | ||
101 | testgammas_nonangular(g) = ev.samplingrate*mean(-diff(testmode)./testmode(1:end-1))/(2*pi); | ||
102 | end | ||
103 | ratios = testgammas_nonangular./reshape(ev.pulse_widths',[],1); | ||
104 | % ratios | ||
105 | assert(all((0.8<ratios) & (ratios<1.2))) | ||
106 | % figure; bar(ratios) | ||
107 | |||
108 | % quick evaluation run | ||
109 | gamma1_list = logspace(1,3,3); | ||
110 | gamma2_list = logspace(1,2,2); | ||
111 | gamma_lists = {gamma1_list, gamma2_list}; | ||
112 | ev.pulse_widths = allcomb(gamma_lists{:}); | ||
113 | ev.samples_per_pulse = 100; | ||
114 | |||
115 | [T,ev] = evalc('ev.calculate_mode_vectors_gammalist()'); | ||
116 | pulsepairs_no = 2; | ||
117 | [T,ev] = evalc('ev.calculatePulsedQuadratures(1, ''pulsepairs'', pulsepairs_no);'); | ||
118 | [T,ev] = evalc('ev.calculatePulsedQuadratures(2, ''pulsepairs'', pulsepairs_no);'); | ||
119 | |||
120 | ev.calculatePulsedCMs; | ||
121 | ev.calibratePulsedCMs('shotnoise_ind', 1); | ||
122 | ev.exportResults; | ||
83 | ev = ev_setup_test(shared); | ||
84 | ev.mech_frequencies = [1, 3]; | ||
85 | gamma1_list = logspace(-3,-1,3); | ||
86 | gamma2_list = logspace(-3,-2,2); | ||
87 | gamma_lists = {gamma1_list, gamma2_list}; | ||
88 | ev.pulse_widths = allcomb(gamma_lists{:}); | ||
89 | ev.samples_per_pulse = round(ev.samples_per_pulse/100); | ||
90 | |||
91 | [T,ev] = evalc('ev.calculate_mode_vectors_gammalist()'); | ||
92 | |||
93 | % pulse_gammas is simply an index running over all possible combinations of pulse widths | ||
94 | % (in this version of the mode vector calculation) | ||
95 | assertEqual(ev.pulse_gammas, 1:length(gamma1_list)*length(gamma2_list)); | ||
96 | |||
97 | % estimate decay constant | ||
98 | testgammas_nonangular = zeros(size(ev.readout_modes,1),1); | ||
99 | for g=1:size(ev.readout_modes,1) | ||
100 | testmode = abs(ev.readout_modes(g,1:1000))'; | ||
101 | testgammas_nonangular(g) = ev.samplingrate*mean(-diff(testmode)./testmode(1:end-1))/(2*pi); | ||
102 | end | ||
103 | ratios = testgammas_nonangular./reshape(ev.pulse_widths',[],1); | ||
104 | % ratios | ||
105 | assert(all((0.8<ratios) & (ratios<1.2))) | ||
106 | % figure; bar(ratios) | ||
107 | |||
108 | % quick evaluation run | ||
109 | gamma1_list = logspace(1,3,3); | ||
110 | gamma2_list = logspace(1,2,2); | ||
111 | gamma_lists = {gamma1_list, gamma2_list}; | ||
112 | ev.pulse_widths = allcomb(gamma_lists{:}); | ||
113 | ev.samples_per_pulse = 100; | ||
114 | |||
115 | [T,ev] = evalc('ev.calculate_mode_vectors_gammalist()'); | ||
116 | pulsepairs_no = 2; | ||
117 | [T,ev] = evalc('ev.calculatePulsedQuadratures(1, ''pulsepairs'', pulsepairs_no);'); | ||
118 | [T,ev] = evalc('ev.calculatePulsedQuadratures(2, ''pulsepairs'', pulsepairs_no);'); | ||
119 | |||
120 | ev.calculatePulsedCMs; | ||
121 | ev.calibratePulsedCMs('shotnoise_ind', 1); | ||
122 | ev.exportResults; | ||
123 | 123 | ||
124 | 124 | function modefunctions_test(shared) | function modefunctions_test(shared) |
125 | ev = ev_setup_test(shared); | ||
126 | ev.mech_frequencies = [1, 2, 3]; | ||
127 | ev.opt_pulse_widths = ones(size(ev.mech_frequencies)); | ||
128 | ev.pulse_gammas = logspace(-1,1,2); | ||
129 | [T,ev] = evalc('ev.calculateModeVectors;'); % supress std out from fct call | ||
130 | |||
131 | % check approximate equality with mode functions as of commit e3e72443e0acce38cf9de712f32dd57dde7f069a | ||
132 | % (up to different relative signs for different mode functions) | ||
133 | tol = 1e-2; | ||
134 | relsign = assertRowsAlmostEqualUptoSign(ev.readout_modes(:,1:3),... | ||
135 | [0.1115 + 0.0070i, 0.1102 + 0.0139i, 0.1084 + 0.0207i;... | ||
136 | 0.1108 - 0.0080i, 0.1088 + 0.0060i, 0.1051 + 0.0194i;... | ||
137 | 0.1097 - 0.0119i, 0.1065 + 0.0088i, 0.0996 + 0.0282i;... | ||
138 | 0.8441 + 0.0531i, 0.4477 + 0.0566i, 0.2365 + 0.0451i;... | ||
139 | 0.0817 - 0.4438i, -0.0738 + 0.3576i, -0.1607 + 0.4920i;... | ||
140 | -0.2255 - 0.0842i, 0.4708 + 0.2149i, 0.1491 + 0.1134i],... | ||
141 | 'relative', tol); | ||
142 | relsign = assertRowsAlmostEqualUptoSign(ev.entangling_modes(:,end-2:end),... | ||
143 | [0.1084 + 0.0207i, 0.1102 + 0.0139i, 0.1115 + 0.0070i;... | ||
144 | 0.1051 + 0.0194i, 0.1088 + 0.0060i, 0.1108 - 0.0080i;... | ||
145 | 0.0996 + 0.0282i, 0.1065 + 0.0088i, 0.1097 - 0.0119i;... | ||
146 | 0.2365 + 0.0451i, 0.4477 + 0.0566i, 0.8441 + 0.0531i;... | ||
147 | -0.1607 + 0.4920i, -0.0738 + 0.3576i, 0.0817 - 0.4438i;... | ||
148 | 0.1491 + 0.1134i, 0.4708 + 0.2149i, -0.2255 - 0.0842i],... | ||
149 | 'relative', tol); | ||
150 | |||
151 | %figure; plot(real(ev.readout_modes')) | ||
152 | |||
153 | %%% check that the orthonormality test does the right thing | ||
154 | on_matrix_entangling = ev.entangling_modes*(ev.entangling_modes)'; | ||
155 | [modefct_no, samples_per_pulse] = size(ev.entangling_modes); | ||
156 | assertEqual(size(on_matrix_entangling), modefct_no*[1,1]) | ||
157 | norm_tol = inf; orthog_tol = inf; % don't care about precision here, only about checking rows vs checking columns | ||
158 | on_info = assert_orthonormality(ev.readout_modes,norm_tol, orthog_tol); | ||
159 | assertEqual(on_info.matrix_size, modefct_no*[1,1]) | ||
160 | %%%% | ||
161 | |||
162 | % check orthonormality | ||
163 | on_matrix_readout = ev.readout_modes*(ev.readout_modes)'; | ||
164 | for k=1:ev.pulse_gammas_no | ||
165 | start_mode = (k-1)*ev.mech_frequencies_no + 1; | ||
166 | stop_mode = k*ev.mech_frequencies_no; | ||
167 | assertElementsAlmostEqual(... | ||
168 | on_matrix_entangling(start_mode:stop_mode,start_mode:stop_mode),... | ||
169 | eye(ev.mech_frequencies_no), 'absolute', 1e-12) | ||
170 | assertElementsAlmostEqual(... | ||
171 | on_matrix_readout(start_mode:stop_mode,start_mode:stop_mode),... | ||
172 | eye(ev.mech_frequencies_no), 'absolute', 1e-12) | ||
173 | end | ||
174 | |||
175 | % check correct sidebands are addressed | ||
176 | tol = 1e-12; | ||
177 | mean_rotation_freq = @(vector)mean(diff(phase(vector))*shared.samplingrate)/(2*pi); | ||
178 | for f=1:ev.mech_frequencies_no | ||
179 | % entangling_modes should pick out down-scattered light --> should be prop. to exp(+i om t) | ||
180 | assertElementsAlmostEqual(... | ||
181 | mean_rotation_freq(ev.entangling_modes(f,:)),... | ||
182 | -ev.mech_frequencies(f), 'absolute', tol) | ||
183 | % readout modes should pick out up-scattered light --> should be prop. to exp(-i om t) | ||
184 | assertElementsAlmostEqual(... | ||
185 | mean_rotation_freq(ev.readout_modes(f,:)),... | ||
186 | +ev.mech_frequencies(f), 'absolute', tol) | ||
187 | % for some reasons it's exactly the other way round... | ||
188 | end | ||
189 | %figure; plot(phase(ev.readout_modes(1,1:100))) | ||
125 | ev = ev_setup_test(shared); | ||
126 | ev.mech_frequencies = [1, 2, 3]; | ||
127 | ev.opt_pulse_widths = ones(size(ev.mech_frequencies)); | ||
128 | ev.pulse_gammas = logspace(-1,1,2); | ||
129 | [T,ev] = evalc('ev.calculateModeVectors;'); % supress std out from fct call | ||
130 | |||
131 | % check approximate equality with mode functions as of commit e3e72443e0acce38cf9de712f32dd57dde7f069a | ||
132 | % (up to different relative signs for different mode functions) | ||
133 | tol = 1e-2; | ||
134 | relsign = assertRowsAlmostEqualUptoSign(ev.readout_modes(:,1:3),... | ||
135 | [0.1115 + 0.0070i, 0.1102 + 0.0139i, 0.1084 + 0.0207i;... | ||
136 | 0.1108 - 0.0080i, 0.1088 + 0.0060i, 0.1051 + 0.0194i;... | ||
137 | 0.1097 - 0.0119i, 0.1065 + 0.0088i, 0.0996 + 0.0282i;... | ||
138 | 0.8441 + 0.0531i, 0.4477 + 0.0566i, 0.2365 + 0.0451i;... | ||
139 | 0.0817 - 0.4438i, -0.0738 + 0.3576i, -0.1607 + 0.4920i;... | ||
140 | -0.2255 - 0.0842i, 0.4708 + 0.2149i, 0.1491 + 0.1134i],... | ||
141 | 'relative', tol); | ||
142 | relsign = assertRowsAlmostEqualUptoSign(ev.entangling_modes(:,end-2:end),... | ||
143 | [0.1084 + 0.0207i, 0.1102 + 0.0139i, 0.1115 + 0.0070i;... | ||
144 | 0.1051 + 0.0194i, 0.1088 + 0.0060i, 0.1108 - 0.0080i;... | ||
145 | 0.0996 + 0.0282i, 0.1065 + 0.0088i, 0.1097 - 0.0119i;... | ||
146 | 0.2365 + 0.0451i, 0.4477 + 0.0566i, 0.8441 + 0.0531i;... | ||
147 | -0.1607 + 0.4920i, -0.0738 + 0.3576i, 0.0817 - 0.4438i;... | ||
148 | 0.1491 + 0.1134i, 0.4708 + 0.2149i, -0.2255 - 0.0842i],... | ||
149 | 'relative', tol); | ||
150 | |||
151 | %figure; plot(real(ev.readout_modes')) | ||
152 | |||
153 | %%% check that the orthonormality test does the right thing | ||
154 | on_matrix_entangling = ev.entangling_modes*(ev.entangling_modes)'; | ||
155 | [modefct_no, samples_per_pulse] = size(ev.entangling_modes); | ||
156 | assertEqual(size(on_matrix_entangling), modefct_no*[1,1]) | ||
157 | norm_tol = inf; orthog_tol = inf; % don't care about precision here, only about checking rows vs checking columns | ||
158 | on_info = assert_orthonormality(ev.readout_modes,norm_tol, orthog_tol); | ||
159 | assertEqual(on_info.matrix_size, modefct_no*[1,1]) | ||
160 | %%%% | ||
161 | |||
162 | % check orthonormality | ||
163 | on_matrix_readout = ev.readout_modes*(ev.readout_modes)'; | ||
164 | for k=1:ev.pulse_gammas_no | ||
165 | start_mode = (k-1)*ev.mech_frequencies_no + 1; | ||
166 | stop_mode = k*ev.mech_frequencies_no; | ||
167 | assertElementsAlmostEqual(... | ||
168 | on_matrix_entangling(start_mode:stop_mode,start_mode:stop_mode),... | ||
169 | eye(ev.mech_frequencies_no), 'absolute', 1e-12) | ||
170 | assertElementsAlmostEqual(... | ||
171 | on_matrix_readout(start_mode:stop_mode,start_mode:stop_mode),... | ||
172 | eye(ev.mech_frequencies_no), 'absolute', 1e-12) | ||
173 | end | ||
174 | |||
175 | % check correct sidebands are addressed | ||
176 | tol = 1e-12; | ||
177 | mean_rotation_freq = @(vector)mean(diff(phase(vector))*shared.samplingrate)/(2*pi); | ||
178 | for f=1:ev.mech_frequencies_no | ||
179 | % entangling_modes should pick out down-scattered light --> should be prop. to exp(+i om t) | ||
180 | assertElementsAlmostEqual(... | ||
181 | mean_rotation_freq(ev.entangling_modes(f,:)),... | ||
182 | -ev.mech_frequencies(f), 'absolute', tol) | ||
183 | % readout modes should pick out up-scattered light --> should be prop. to exp(-i om t) | ||
184 | assertElementsAlmostEqual(... | ||
185 | mean_rotation_freq(ev.readout_modes(f,:)),... | ||
186 | +ev.mech_frequencies(f), 'absolute', tol) | ||
187 | % for some reasons it's exactly the other way round... | ||
188 | end | ||
189 | %figure; plot(phase(ev.readout_modes(1,1:100))) | ||
190 | 190 | ||
191 | 191 | function run_test(shared) | function run_test(shared) |
192 | ev = ev_setup_test(shared); | ||
193 | ev.mech_frequencies = shared.mech_freqs; | ||
194 | ev.opt_pulse_widths = 1e2*[1, 1]; | ||
195 | ev.pulse_gammas = logspace(-1,1,10); | ||
196 | ev.samples_per_pulse = 4*ev.samples_per_pulse; % adjust samples_per_pulse, since in commit 6dcad7dc617c9bed38f45823b049e556264b694f it has been lower by a factor of 4; | ||
197 | [T,ev] = evalc('ev.calculateModeVectors;'); % supress std out from fct call | ||
198 | [T,ev] = evalc('ev.calculatePulsedQuadratures(1);'); % supress std out from fct call | ||
199 | assertEqual(size(ev.pulse_Y{1}),... | ||
200 | [ev.pulse_pairs_per_trace, ev.mech_frequencies_no*ev.pulse_gammas_no]); | ||
201 | |||
202 | % compare to results as of datoolbox-commit 754e283187e9e9a6385b0f9a8a26f5fd2807ccd0 | ||
203 | % (after modifying mode-fct calculation to avoid numerical instabilities during orthonormalization) | ||
204 | tolerance = 1e-2; | ||
205 | relsign = assertColsAlmostEqualUptoSign(... | ||
206 | [ev.pulse_Q{1}(1:2,:); ev.pulse_P{1}(1:2,:);... | ||
207 | ev.pulse_X{1}(1:2,:); ev.pulse_Y{1}(1:2,:)],... | ||
208 | [-2.2115, -2.4141, -1.6618, -2.3063, -1.3238, -2.0629, -1.1502, -1.8850, -1.0911, -1.8164, -1.0820, -1.8055, -1.0816, -1.8051, -1.0816, -1.8051, -1.0816, -1.8051, -1.0816, -1.8051;... | ||
209 | -0.2433, -2.8269, 0.0246, -2.6458, 0.1230, -2.3094, 0.1520, -2.0811, 0.1583, -1.9958, 0.1592, -1.9824, 0.1592, -1.9819, 0.1592, -1.9819, 0.1592, -1.9819, 0.1592, -1.9819;... | ||
210 | 3.2915, -2.9633, 2.7127, -2.1359, 2.2809, -1.6272, 2.0343, -1.3764, 1.9462, -1.2934, 1.9325, -1.2808, 1.9320, -1.2803, 1.9320, -1.2803, 1.9320, -1.2803, 1.9320, -1.2803;... | ||
211 | 3.5199, -1.8524, 2.8666, -0.8733, 2.3888, -0.4121, 2.1204, -0.2318, 2.0254, -0.1800, 2.0106, -0.1725, 2.0100, -0.1722, 2.0100, -0.1722, 2.0100, -0.1722, 2.0100, -0.1722;... | ||
212 | -2.0535, -2.6901, -1.5796, -2.4139, -1.2766, -2.1129, -1.1172, -1.9160, -1.0623, -1.8423, -1.0539, -1.8307, -1.0535, -1.8302, -1.0535, -1.8302, -1.0535, -1.8302, -1.0535, -1.8302;... | ||
213 | 0.5499, -3.9050, 0.4369, -3.0405, 0.3590, -2.4789, 0.3166, -2.1801, 0.3017, -2.0765, 0.2995, -2.0605, 0.2994, -2.0599, 0.2994, -2.0599, 0.2994, -2.0599, 0.2994, -2.0599;... | ||
214 | 3.3518, -2.5439, 2.7367, -1.9035, 2.2923, -1.4906, 2.0413, -1.2802, 1.9521, -1.2093, 1.9382, -1.1984, 1.9377, -1.1980, 1.9377, -1.1980, 1.9377, -1.1980, 1.9377, -1.1980;... | ||
215 | 3.7251, 0.2762, 2.9392, 0.3040, 2.4188, 0.2777, 2.1371, 0.2534, 2.0387, 0.2436, 2.0234, 0.2420, 2.0228, 0.2420, 2.0228, 0.2420, 2.0228, 0.2420, 2.0228, 0.2420],... | ||
216 | 'relative', tolerance, 'Pulsed traces differ for first pulse width!'); | ||
217 | |||
218 | relsign = assertColsAlmostEqualUptoSign(... | ||
219 | [ev.pulse_Q{1}(end-1:end,:); ev.pulse_P{1}(end-1:end,:);... | ||
220 | ev.pulse_X{1}(end-1:end,:); ev.pulse_Y{1}(end-1:end,:)],... | ||
221 | [0.3231, -3.4203, 0.3579, -2.8694, 0.3420, -2.4087, 0.3219, -2.1409, 0.3131, -2.0453, 0.3117, -2.0304, 0.3116, -2.0298, 0.3116, -2.0298, 0.3116, -2.0298, 0.3116, -2.0298;... | ||
222 | -2.4419, -2.1727, -1.7974, -2.2153, -1.4129, -2.0225, -1.2193, -1.8607, -1.1541, -1.7963, -1.1440, -1.7860, -1.1436, -1.7856, -1.1436, -1.7856, -1.1436, -1.7856, -1.1436, -1.7856;... | ||
223 | 3.6361, -0.5743, 2.9101, -0.1286, 2.4083, 0.0519, 2.1323, 0.1114, 2.0353, 0.1263, 2.0202, 0.1284, 2.0196, 0.1285, 2.0196, 0.1285, 2.0196, 0.1285, 2.0196, 0.1285;... | ||
224 | 3.2442, -3.4832, 2.6950, -2.4389, 2.2729, -1.8160, 2.0294, -1.5161, 1.9422, -1.4180, 1.9286, -1.4032, 1.9281, -1.4026, 1.9280, -1.4026, 1.9280, -1.4026, 1.9280, -1.4026;... | ||
225 | 0.2522, -3.4073, 0.3212, -2.8737, 0.3212, -2.4156, 0.3074, -2.1473, 0.3006, -2.0514, 0.2994, -2.0364, 0.2994, -2.0358, 0.2994, -2.0358, 0.2994, -2.0358, 0.2994, -2.0358;... | ||
226 | -1.9324, -2.8926, -1.5325, -2.4818, -1.2612, -2.1386, -1.1135, -1.9293, -1.0619, -1.8525, -1.0538, -1.8405, -1.0535, -1.8400, -1.0535, -1.8400, -1.0535, -1.8400, -1.0535, -1.8400;... | ||
227 | 3.6442, -0.7709, 2.9166, -0.2367, 2.4130, -0.0109, 2.1359, 0.0676, 2.0385, 0.0881, 2.0234, 0.0910, 2.0228, 0.0911, 2.0228, 0.0911, 2.0228, 0.0911, 2.0228, 0.0911;... | ||
228 | 3.3847, -2.1179, 2.7459, -1.6835, 2.2946, -1.3732, 2.0418, -1.2046, 1.9522, -1.1460, 1.9382, -1.1370, 1.9377, -1.1366, 1.9377, -1.1366, 1.9377, -1.1366, 1.9377, -1.1366],... | ||
229 | 'relative', tolerance, 'Pulsed traces differ for last pulse width!'); | ||
230 | |||
231 | ev.calculatePulsedCMs(1); | ||
232 | [T,ev] = evalc('ev.calculatePulsedQuadratures(2);'); % supress std out from fct call | ||
233 | ev.calculatePulsedCMs(2); | ||
234 | ev.calibratePulsedCMs; | ||
235 | |||
236 | % check shotnoise entanglement values | ||
237 | assertElementsAlmostEqual([ev.logneg_corrected{1}{:}],... | ||
238 | [109.0853, 111.0687, 112.5557, 113.4168, 114.8301, 112.9490, 113.0331, 112.9725, 113.3471, 113.5596],... | ||
239 | 'absolute', 1e-3, 'Log. neg. values for shotnoise not as expected!'); | ||
240 | % before excluding shotnoise log.neg. from the dual-rail-homo-correction the values were | ||
241 | % [0.4272, 0.4583, 0.1683, 0.0973, 0.0795, 0.0771, 0.0770, 0.0770, 0.0770, 0.0770] | ||
242 | % cmnew = ev.pulse_CM_calibrated{1}{1} | ||
243 | % logneg(cmnew) | ||
244 | % cmold = 2*ev.pulse_CM_calibrated{1}{1}-eye(8)/2 | ||
245 | % logneg(cmold) | ||
246 | |||
247 | % check save and reload of ev: transient properties should not be stored | ||
248 | tmpfile = [tempname,'.mat']; | ||
249 | save(tmpfile, 'ev'); | ||
250 | assert(~isempty(ev.pulse_trace)); | ||
251 | clear('ev'); | ||
252 | |||
253 | load(tmpfile); | ||
254 | assert(isempty(ev.pulse_trace)); | ||
255 | delete(tmpfile); | ||
256 | |||
257 | % compare to results as of datoolbox-commit 997cd1260b8b222bd0b6ebf3f8567db04ace24fd | ||
258 | assertCMsEqualUptoSign(ev.pulse_CM_calibrated{2}{1},... | ||
259 | [[0.982359896462452, 0.131028168234013, -0.367189369366558, 0.880348741612935, 0.946576778024290, 0.122862699486762, -0.321838837984714, 0.783722707358365];... | ||
260 | [0.131028168234013, 0.017640103537548, -0.050517532058795, 0.120534462978138, 0.122866665973445, 0.015778083289827, -0.040175061783999, 0.098497215865329];... | ||
261 | [-0.367189369366558, -0.050517532058795, 0.151787439279659, -0.358416760477882, -0.321853066589406, -0.040175675239897, 0.094340702342072, -0.236007779549885];... | ||
262 | [0.880348741612935, 0.120534462978138, -0.358416760477882, 0.848212560720341, 0.783741799699913, 0.098496642634894, -0.236002490360790, 0.587370230126137];... | ||
263 | [0.946576778024290, 0.122866665973445, -0.321853066589406, 0.783741799699913, 0.982360871144707, 0.131024476233387, -0.367180133703403, 0.880340233793472];... | ||
264 | [0.122862699486762, 0.015778083289827, -0.040175675239897, 0.098496642634894, 0.131024476233387, 0.017639128855292, -0.050515242330064, 0.120530651668499];... | ||
265 | [-0.321838837984714, -0.040175061783999, 0.094340702342072, -0.236002490360790, -0.367180133703403, -0.050515242330064, 0.151784942728085, -0.358414152751479];... | ||
266 | [0.783722707358365, 0.098497215865329, -0.236007779549885, 0.587370230126137, 0.880340233793472, 0.120530651668499, -0.358414152751479, 0.848215057271915]]); | ||
192 | ev = ev_setup_test(shared); | ||
193 | ev.mech_frequencies = shared.mech_freqs; | ||
194 | ev.opt_pulse_widths = 1e2*[1, 1]; | ||
195 | ev.pulse_gammas = logspace(-1,1,10); | ||
196 | ev.samples_per_pulse = 4*ev.samples_per_pulse; % adjust samples_per_pulse, since in commit 6dcad7dc617c9bed38f45823b049e556264b694f it has been lower by a factor of 4; | ||
197 | [T,ev] = evalc('ev.calculateModeVectors;'); % supress std out from fct call | ||
198 | [T,ev] = evalc('ev.calculatePulsedQuadratures(1);'); % supress std out from fct call | ||
199 | assertEqual(size(ev.pulse_Y{1}),... | ||
200 | [ev.pulse_pairs_per_trace, ev.mech_frequencies_no*ev.pulse_gammas_no]); | ||
201 | |||
202 | % compare to results as of datoolbox-commit 754e283187e9e9a6385b0f9a8a26f5fd2807ccd0 | ||
203 | % (after modifying mode-fct calculation to avoid numerical instabilities during orthonormalization) | ||
204 | tolerance = 1e-2; | ||
205 | relsign = assertColsAlmostEqualUptoSign(... | ||
206 | [ev.pulse_Q{1}(1:2,:); ev.pulse_P{1}(1:2,:);... | ||
207 | ev.pulse_X{1}(1:2,:); ev.pulse_Y{1}(1:2,:)],... | ||
208 | [-2.2115, -2.4141, -1.6618, -2.3063, -1.3238, -2.0629, -1.1502, -1.8850, -1.0911, -1.8164, -1.0820, -1.8055, -1.0816, -1.8051, -1.0816, -1.8051, -1.0816, -1.8051, -1.0816, -1.8051;... | ||
209 | -0.2433, -2.8269, 0.0246, -2.6458, 0.1230, -2.3094, 0.1520, -2.0811, 0.1583, -1.9958, 0.1592, -1.9824, 0.1592, -1.9819, 0.1592, -1.9819, 0.1592, -1.9819, 0.1592, -1.9819;... | ||
210 | 3.2915, -2.9633, 2.7127, -2.1359, 2.2809, -1.6272, 2.0343, -1.3764, 1.9462, -1.2934, 1.9325, -1.2808, 1.9320, -1.2803, 1.9320, -1.2803, 1.9320, -1.2803, 1.9320, -1.2803;... | ||
211 | 3.5199, -1.8524, 2.8666, -0.8733, 2.3888, -0.4121, 2.1204, -0.2318, 2.0254, -0.1800, 2.0106, -0.1725, 2.0100, -0.1722, 2.0100, -0.1722, 2.0100, -0.1722, 2.0100, -0.1722;... | ||
212 | -2.0535, -2.6901, -1.5796, -2.4139, -1.2766, -2.1129, -1.1172, -1.9160, -1.0623, -1.8423, -1.0539, -1.8307, -1.0535, -1.8302, -1.0535, -1.8302, -1.0535, -1.8302, -1.0535, -1.8302;... | ||
213 | 0.5499, -3.9050, 0.4369, -3.0405, 0.3590, -2.4789, 0.3166, -2.1801, 0.3017, -2.0765, 0.2995, -2.0605, 0.2994, -2.0599, 0.2994, -2.0599, 0.2994, -2.0599, 0.2994, -2.0599;... | ||
214 | 3.3518, -2.5439, 2.7367, -1.9035, 2.2923, -1.4906, 2.0413, -1.2802, 1.9521, -1.2093, 1.9382, -1.1984, 1.9377, -1.1980, 1.9377, -1.1980, 1.9377, -1.1980, 1.9377, -1.1980;... | ||
215 | 3.7251, 0.2762, 2.9392, 0.3040, 2.4188, 0.2777, 2.1371, 0.2534, 2.0387, 0.2436, 2.0234, 0.2420, 2.0228, 0.2420, 2.0228, 0.2420, 2.0228, 0.2420, 2.0228, 0.2420],... | ||
216 | 'relative', tolerance, 'Pulsed traces differ for first pulse width!'); | ||
217 | |||
218 | relsign = assertColsAlmostEqualUptoSign(... | ||
219 | [ev.pulse_Q{1}(end-1:end,:); ev.pulse_P{1}(end-1:end,:);... | ||
220 | ev.pulse_X{1}(end-1:end,:); ev.pulse_Y{1}(end-1:end,:)],... | ||
221 | [0.3231, -3.4203, 0.3579, -2.8694, 0.3420, -2.4087, 0.3219, -2.1409, 0.3131, -2.0453, 0.3117, -2.0304, 0.3116, -2.0298, 0.3116, -2.0298, 0.3116, -2.0298, 0.3116, -2.0298;... | ||
222 | -2.4419, -2.1727, -1.7974, -2.2153, -1.4129, -2.0225, -1.2193, -1.8607, -1.1541, -1.7963, -1.1440, -1.7860, -1.1436, -1.7856, -1.1436, -1.7856, -1.1436, -1.7856, -1.1436, -1.7856;... | ||
223 | 3.6361, -0.5743, 2.9101, -0.1286, 2.4083, 0.0519, 2.1323, 0.1114, 2.0353, 0.1263, 2.0202, 0.1284, 2.0196, 0.1285, 2.0196, 0.1285, 2.0196, 0.1285, 2.0196, 0.1285;... | ||
224 | 3.2442, -3.4832, 2.6950, -2.4389, 2.2729, -1.8160, 2.0294, -1.5161, 1.9422, -1.4180, 1.9286, -1.4032, 1.9281, -1.4026, 1.9280, -1.4026, 1.9280, -1.4026, 1.9280, -1.4026;... | ||
225 | 0.2522, -3.4073, 0.3212, -2.8737, 0.3212, -2.4156, 0.3074, -2.1473, 0.3006, -2.0514, 0.2994, -2.0364, 0.2994, -2.0358, 0.2994, -2.0358, 0.2994, -2.0358, 0.2994, -2.0358;... | ||
226 | -1.9324, -2.8926, -1.5325, -2.4818, -1.2612, -2.1386, -1.1135, -1.9293, -1.0619, -1.8525, -1.0538, -1.8405, -1.0535, -1.8400, -1.0535, -1.8400, -1.0535, -1.8400, -1.0535, -1.8400;... | ||
227 | 3.6442, -0.7709, 2.9166, -0.2367, 2.4130, -0.0109, 2.1359, 0.0676, 2.0385, 0.0881, 2.0234, 0.0910, 2.0228, 0.0911, 2.0228, 0.0911, 2.0228, 0.0911, 2.0228, 0.0911;... | ||
228 | 3.3847, -2.1179, 2.7459, -1.6835, 2.2946, -1.3732, 2.0418, -1.2046, 1.9522, -1.1460, 1.9382, -1.1370, 1.9377, -1.1366, 1.9377, -1.1366, 1.9377, -1.1366, 1.9377, -1.1366],... | ||
229 | 'relative', tolerance, 'Pulsed traces differ for last pulse width!'); | ||
230 | |||
231 | ev.calculatePulsedCMs(1); | ||
232 | [T,ev] = evalc('ev.calculatePulsedQuadratures(2);'); % supress std out from fct call | ||
233 | ev.calculatePulsedCMs(2); | ||
234 | ev.calibratePulsedCMs; | ||
235 | |||
236 | % check shotnoise entanglement values | ||
237 | assertElementsAlmostEqual([ev.logneg_corrected{1}{:}],... | ||
238 | [109.0853, 111.0687, 112.5557, 113.4168, 114.8301, 112.9490, 113.0331, 112.9725, 113.3471, 113.5596],... | ||
239 | 'absolute', 1e-3, 'Log. neg. values for shotnoise not as expected!'); | ||
240 | % before excluding shotnoise log.neg. from the dual-rail-homo-correction the values were | ||
241 | % [0.4272, 0.4583, 0.1683, 0.0973, 0.0795, 0.0771, 0.0770, 0.0770, 0.0770, 0.0770] | ||
242 | % cmnew = ev.pulse_CM_calibrated{1}{1} | ||
243 | % logneg(cmnew) | ||
244 | % cmold = 2*ev.pulse_CM_calibrated{1}{1}-eye(8)/2 | ||
245 | % logneg(cmold) | ||
246 | |||
247 | % check save and reload of ev: transient properties should not be stored | ||
248 | tmpfile = [tempname,'.mat']; | ||
249 | save(tmpfile, 'ev'); | ||
250 | assert(~isempty(ev.pulse_trace)); | ||
251 | clear('ev'); | ||
252 | |||
253 | load(tmpfile); | ||
254 | assert(isempty(ev.pulse_trace)); | ||
255 | delete(tmpfile); | ||
256 | |||
257 | % compare to results as of datoolbox-commit 997cd1260b8b222bd0b6ebf3f8567db04ace24fd | ||
258 | assertCMsEqualUptoSign(ev.pulse_CM_calibrated{2}{1},... | ||
259 | [[0.982359896462452, 0.131028168234013, -0.367189369366558, 0.880348741612935, 0.946576778024290, 0.122862699486762, -0.321838837984714, 0.783722707358365];... | ||
260 | [0.131028168234013, 0.017640103537548, -0.050517532058795, 0.120534462978138, 0.122866665973445, 0.015778083289827, -0.040175061783999, 0.098497215865329];... | ||
261 | [-0.367189369366558, -0.050517532058795, 0.151787439279659, -0.358416760477882, -0.321853066589406, -0.040175675239897, 0.094340702342072, -0.236007779549885];... | ||
262 | [0.880348741612935, 0.120534462978138, -0.358416760477882, 0.848212560720341, 0.783741799699913, 0.098496642634894, -0.236002490360790, 0.587370230126137];... | ||
263 | [0.946576778024290, 0.122866665973445, -0.321853066589406, 0.783741799699913, 0.982360871144707, 0.131024476233387, -0.367180133703403, 0.880340233793472];... | ||
264 | [0.122862699486762, 0.015778083289827, -0.040175675239897, 0.098496642634894, 0.131024476233387, 0.017639128855292, -0.050515242330064, 0.120530651668499];... | ||
265 | [-0.321838837984714, -0.040175061783999, 0.094340702342072, -0.236002490360790, -0.367180133703403, -0.050515242330064, 0.151784942728085, -0.358414152751479];... | ||
266 | [0.783722707358365, 0.098497215865329, -0.236007779549885, 0.587370230126137, 0.880340233793472, 0.120530651668499, -0.358414152751479, 0.848215057271915]]); | ||
267 | 267 | ||
268 | 268 | function run_inverted_test(shared) | function run_inverted_test(shared) |
269 | % passes as of commit 486cf46dec3f7f6cf493f947709dc605ae44930f and its child | ||
270 | ev = ev_setup_test(shared); | ||
271 | ev.inverted_evaluation = true; | ||
272 | ev.mech_frequencies = shared.mech_freqs; | ||
273 | ev.opt_pulse_widths = 1e2*[1, 1]; | ||
274 | ev.pulse_gammas = logspace(-1,1,10); | ||
275 | ev.samples_per_pulse = 4*ev.samples_per_pulse; % adjust samples_per_pulse, since in commit 6dcad7dc617c9bed38f45823b049e556264b694f it has been lower by a factor of 4; | ||
276 | [T,ev] = evalc('ev.calculateModeVectors;'); % supress std out from fct call | ||
277 | [T,ev] = evalc('ev.calculatePulsedQuadratures(1);'); % supress std out from fct call | ||
278 | assertEqual(size(ev.pulse_Y{1}),... | ||
279 | [ev.pulse_pairs_per_trace, ev.mech_frequencies_no*ev.pulse_gammas_no]); | ||
280 | |||
281 | % compare to results as of datoolbox-commit 754e283187e9e9a6385b0f9a8a26f5fd2807ccd0 | ||
282 | % (after modifying mode-fct calculation to avoid numerical instabilities during orthonormalization) | ||
283 | tolerance = 1e-2; | ||
284 | assertColsAlmostEqualUptoSign(... | ||
285 | [ev.pulse_Q{1}(1:2,:); ev.pulse_P{1}(1:2,:);... | ||
286 | ev.pulse_X{1}(1:2,:); ev.pulse_Y{1}(1:2,:)],... | ||
287 | [-1.2735, 3.8137, -1.1123, 3.0828, -0.9634, 2.5385, -0.8707, 2.2366, -0.8365, 2.1309, -0.8312, 2.1145, -0.8310, 2.1138, -0.8310, 2.1138, -0.8310, 2.1138, -0.8310, 2.1138;... | ||
288 | 0.6946, 3.4010, 0.5740, 2.7433, 0.4834, 2.2920, 0.4315, 2.0406, 0.4129, 1.9515, 0.4100, 1.9376, 0.4099, 1.9371, 0.4099, 1.9371, 0.4099, 1.9371, 0.4099, 1.9371;... | ||
289 | -3.7667, -0.3446, -2.9840, -0.6290, -2.4559, -0.6815, -2.1689, -0.6681, -2.0685, -0.6572, -2.0529, -0.6552, -2.0523, -0.6551, -2.0523, -0.6551, -2.0523, -0.6551, -2.0523, -0.6551;... | ||
290 | -3.5383, 0.7663, -2.8301, 0.6336, -2.3480, 0.5337, -2.0827, 0.4765, -1.9893, 0.4562, -1.9748, 0.4531, -1.9742, 0.4530, -1.9742, 0.4530, -1.9742, 0.4530, -1.9742, 0.4530;... | ||
291 | -1.1052, 3.6599, -1.0267, 3.0421, -0.9149, 2.5275, -0.8371, 2.2330, -0.8073, 2.1289, -0.8026, 2.1127, -0.8024, 2.1121, -0.8024, 2.1121, -0.8024, 2.1121, -0.8024, 2.1121;... | ||
292 | 1.4981, 2.4450, 0.9898, 2.4155, 0.7207, 2.1615, 0.5968, 1.9689, 0.5568, 1.8947, 0.5508, 1.8829, 0.5505, 1.8824, 0.5505, 1.8824, 0.5505, 1.8824, 0.5505, 1.8824;... | ||
293 | -3.7514, 0.1327, -2.9832, -0.3762, -2.4578, -0.5365, -2.1710, -0.5671, -2.0706, -0.5692, -2.0551, -0.5692, -2.0544, -0.5692, -2.0544, -0.5692, -2.0544, -0.5692, -2.0544, -0.5692;... | ||
294 | -3.3781, 2.9527, -2.7808, 1.8313, -2.3313, 1.2319, -2.0753, 0.9665, -1.9841, 0.8837, -1.9699, 0.8713, -1.9693, 0.8708, -1.9693, 0.8708, -1.9693, 0.8708, -1.9693, 0.8708],... | ||
295 | 'relative', tolerance, 'Pulsed traces differ for first pulse width!'); | ||
296 | |||
297 | assertColsAlmostEqualUptoSign(... | ||
298 | [ev.pulse_Q{1}(end-1:end,:); ev.pulse_P{1}(end-1:end,:);... | ||
299 | ev.pulse_X{1}(end-1:end,:); ev.pulse_Y{1}(end-1:end,:)],... | ||
300 | [1.2610, 2.8076, 0.9074, 2.5197, 0.7024, 2.1927, 0.6014, 1.9808, 0.5677, 1.9020, 0.5625, 1.8896, 0.5623, 1.8891, 0.5623, 1.8891, 0.5623, 1.8891, 0.5623, 1.8891;... | ||
301 | -1.5040, 4.0552, -1.2480, 3.1738, -1.0525, 2.5789, -0.9398, 2.2610, -0.8995, 2.1510, -0.8932, 2.1340, -0.8930, 2.1333, -0.8930, 2.1333, -0.8930, 2.1333, -0.8930, 2.1333;... | ||
302 | -3.4221, 2.0444, -2.7866, 1.3783, -2.3285, 0.9976, -2.0708, 0.8197, -1.9794, 0.7626, -1.9652, 0.7539, -1.9646, 0.7536, -1.9646, 0.7536, -1.9646, 0.7536, -1.9646, 0.7536;... | ||
303 | -3.8140, -0.8646, -3.0017, -0.9320, -2.4639, -0.8703, -2.1737, -0.8078, -2.0725, -0.7818, -2.0568, -0.7776, -2.0562, -0.7774, -2.0562, -0.7774, -2.0562, -0.7774, -2.0562, -0.7774;... | ||
304 | 1.2005, 2.9428, 0.8741, 2.5823, 0.6829, 2.2248, 0.5876, 2.0017, 0.5556, 1.9198, 0.5507, 1.9070, 0.5505, 1.9064, 0.5505, 1.9064, 0.5505, 1.9064, 0.5505, 1.9064;... | ||
305 | -0.9841, 3.4574, -0.9796, 2.9742, -0.8995, 2.5017, -0.8333, 2.2197, -0.8068, 2.1187, -0.8025, 2.1029, -0.8024, 2.1023, -0.8024, 2.1023, -0.8024, 2.1023, -0.8024, 2.1023;... | ||
306 | -3.4590, 1.9057, -2.8033, 1.2906, -2.3371, 0.9433, -2.0765, 0.7807, -1.9842, 0.7282, -1.9699, 0.7203, -1.9693, 0.7200, -1.9693, 0.7200, -1.9693, 0.7200, -1.9693, 0.7200;... | ||
307 | -3.7185, 0.5587, -2.9740, -0.1562, -2.4555, -0.4191, -2.1705, -0.4915, -2.0706, -0.5060, -2.0551, -0.5077, -2.0544, -0.5078, -2.0544, -0.5078, -2.0544, -0.5078, -2.0544, -0.5078],... | ||
308 | 'relative', tolerance, 'Pulsed traces differ for last pulse width!'); | ||
309 | |||
310 | ev.calculatePulsedCMs(1); | ||
311 | [T,ev] = evalc('ev.calculatePulsedQuadratures(2);'); % supress std out from fct call | ||
312 | ev.calculatePulsedCMs(2); | ||
313 | ev.calibratePulsedCMs; | ||
314 | |||
315 | % check save and reload of ev: transient properties should not be stored | ||
316 | tmpfile = [tempname,'.mat']; | ||
317 | save(tmpfile, 'ev'); | ||
318 | assert(~isempty(ev.pulse_trace)); | ||
319 | clear('ev'); | ||
320 | |||
321 | load(tmpfile); | ||
322 | assert(isempty(ev.pulse_trace)); | ||
323 | delete(tmpfile); | ||
324 | |||
325 | % compare to results as of datoolbox-commit 997cd1260b8b222bd0b6ebf3f8567db04ace24fd | ||
326 | assertCMsEqualUptoSign(ev.pulse_CM_calibrated{2}{1},... | ||
327 | [[0.982359896462452, 0.131028168234013, -0.367189369366558, 0.880348741612935, 0.946576778024290, 0.122862699486762, -0.321838837984714, 0.783722707358365];... | ||
328 | [0.131028168234013, 0.017640103537548, -0.050517532058795, 0.120534462978138, 0.122866665973445, 0.015778083289827, -0.040175061783999, 0.098497215865329];... | ||
329 | [-0.367189369366558, -0.050517532058795, 0.151787439279659, -0.358416760477882, -0.321853066589406, -0.040175675239897, 0.094340702342072, -0.236007779549885];... | ||
330 | [0.880348741612935, 0.120534462978138, -0.358416760477882, 0.848212560720341, 0.783741799699913, 0.098496642634894, -0.236002490360790, 0.587370230126137];... | ||
331 | [0.946576778024290, 0.122866665973445, -0.321853066589406, 0.783741799699913, 0.982360871144707, 0.131024476233387, -0.367180133703403, 0.880340233793472];... | ||
332 | [0.122862699486762, 0.015778083289827, -0.040175675239897, 0.098496642634894, 0.131024476233387, 0.017639128855292, -0.050515242330064, 0.120530651668499];... | ||
333 | [-0.321838837984714, -0.040175061783999, 0.094340702342072, -0.236002490360790, -0.367180133703403, -0.050515242330064, 0.151784942728085, -0.358414152751479];... | ||
334 | [0.783722707358365, 0.098497215865329, -0.236007779549885, 0.587370230126137, 0.880340233793472, 0.120530651668499, -0.358414152751479, 0.848215057271915]]); | ||
269 | % passes as of commit 486cf46dec3f7f6cf493f947709dc605ae44930f and its child | ||
270 | ev = ev_setup_test(shared); | ||
271 | ev.inverted_evaluation = true; | ||
272 | ev.mech_frequencies = shared.mech_freqs; | ||
273 | ev.opt_pulse_widths = 1e2*[1, 1]; | ||
274 | ev.pulse_gammas = logspace(-1,1,10); | ||
275 | ev.samples_per_pulse = 4*ev.samples_per_pulse; % adjust samples_per_pulse, since in commit 6dcad7dc617c9bed38f45823b049e556264b694f it has been lower by a factor of 4; | ||
276 | [T,ev] = evalc('ev.calculateModeVectors;'); % supress std out from fct call | ||
277 | [T,ev] = evalc('ev.calculatePulsedQuadratures(1);'); % supress std out from fct call | ||
278 | assertEqual(size(ev.pulse_Y{1}),... | ||
279 | [ev.pulse_pairs_per_trace, ev.mech_frequencies_no*ev.pulse_gammas_no]); | ||
280 | |||
281 | % compare to results as of datoolbox-commit 754e283187e9e9a6385b0f9a8a26f5fd2807ccd0 | ||
282 | % (after modifying mode-fct calculation to avoid numerical instabilities during orthonormalization) | ||
283 | tolerance = 1e-2; | ||
284 | assertColsAlmostEqualUptoSign(... | ||
285 | [ev.pulse_Q{1}(1:2,:); ev.pulse_P{1}(1:2,:);... | ||
286 | ev.pulse_X{1}(1:2,:); ev.pulse_Y{1}(1:2,:)],... | ||
287 | [-1.2735, 3.8137, -1.1123, 3.0828, -0.9634, 2.5385, -0.8707, 2.2366, -0.8365, 2.1309, -0.8312, 2.1145, -0.8310, 2.1138, -0.8310, 2.1138, -0.8310, 2.1138, -0.8310, 2.1138;... | ||
288 | 0.6946, 3.4010, 0.5740, 2.7433, 0.4834, 2.2920, 0.4315, 2.0406, 0.4129, 1.9515, 0.4100, 1.9376, 0.4099, 1.9371, 0.4099, 1.9371, 0.4099, 1.9371, 0.4099, 1.9371;... | ||
289 | -3.7667, -0.3446, -2.9840, -0.6290, -2.4559, -0.6815, -2.1689, -0.6681, -2.0685, -0.6572, -2.0529, -0.6552, -2.0523, -0.6551, -2.0523, -0.6551, -2.0523, -0.6551, -2.0523, -0.6551;... | ||
290 | -3.5383, 0.7663, -2.8301, 0.6336, -2.3480, 0.5337, -2.0827, 0.4765, -1.9893, 0.4562, -1.9748, 0.4531, -1.9742, 0.4530, -1.9742, 0.4530, -1.9742, 0.4530, -1.9742, 0.4530;... | ||
291 | -1.1052, 3.6599, -1.0267, 3.0421, -0.9149, 2.5275, -0.8371, 2.2330, -0.8073, 2.1289, -0.8026, 2.1127, -0.8024, 2.1121, -0.8024, 2.1121, -0.8024, 2.1121, -0.8024, 2.1121;... | ||
292 | 1.4981, 2.4450, 0.9898, 2.4155, 0.7207, 2.1615, 0.5968, 1.9689, 0.5568, 1.8947, 0.5508, 1.8829, 0.5505, 1.8824, 0.5505, 1.8824, 0.5505, 1.8824, 0.5505, 1.8824;... | ||
293 | -3.7514, 0.1327, -2.9832, -0.3762, -2.4578, -0.5365, -2.1710, -0.5671, -2.0706, -0.5692, -2.0551, -0.5692, -2.0544, -0.5692, -2.0544, -0.5692, -2.0544, -0.5692, -2.0544, -0.5692;... | ||
294 | -3.3781, 2.9527, -2.7808, 1.8313, -2.3313, 1.2319, -2.0753, 0.9665, -1.9841, 0.8837, -1.9699, 0.8713, -1.9693, 0.8708, -1.9693, 0.8708, -1.9693, 0.8708, -1.9693, 0.8708],... | ||
295 | 'relative', tolerance, 'Pulsed traces differ for first pulse width!'); | ||
296 | |||
297 | assertColsAlmostEqualUptoSign(... | ||
298 | [ev.pulse_Q{1}(end-1:end,:); ev.pulse_P{1}(end-1:end,:);... | ||
299 | ev.pulse_X{1}(end-1:end,:); ev.pulse_Y{1}(end-1:end,:)],... | ||
300 | [1.2610, 2.8076, 0.9074, 2.5197, 0.7024, 2.1927, 0.6014, 1.9808, 0.5677, 1.9020, 0.5625, 1.8896, 0.5623, 1.8891, 0.5623, 1.8891, 0.5623, 1.8891, 0.5623, 1.8891;... | ||
301 | -1.5040, 4.0552, -1.2480, 3.1738, -1.0525, 2.5789, -0.9398, 2.2610, -0.8995, 2.1510, -0.8932, 2.1340, -0.8930, 2.1333, -0.8930, 2.1333, -0.8930, 2.1333, -0.8930, 2.1333;... | ||
302 | -3.4221, 2.0444, -2.7866, 1.3783, -2.3285, 0.9976, -2.0708, 0.8197, -1.9794, 0.7626, -1.9652, 0.7539, -1.9646, 0.7536, -1.9646, 0.7536, -1.9646, 0.7536, -1.9646, 0.7536;... | ||
303 | -3.8140, -0.8646, -3.0017, -0.9320, -2.4639, -0.8703, -2.1737, -0.8078, -2.0725, -0.7818, -2.0568, -0.7776, -2.0562, -0.7774, -2.0562, -0.7774, -2.0562, -0.7774, -2.0562, -0.7774;... | ||
304 | 1.2005, 2.9428, 0.8741, 2.5823, 0.6829, 2.2248, 0.5876, 2.0017, 0.5556, 1.9198, 0.5507, 1.9070, 0.5505, 1.9064, 0.5505, 1.9064, 0.5505, 1.9064, 0.5505, 1.9064;... | ||
305 | -0.9841, 3.4574, -0.9796, 2.9742, -0.8995, 2.5017, -0.8333, 2.2197, -0.8068, 2.1187, -0.8025, 2.1029, -0.8024, 2.1023, -0.8024, 2.1023, -0.8024, 2.1023, -0.8024, 2.1023;... | ||
306 | -3.4590, 1.9057, -2.8033, 1.2906, -2.3371, 0.9433, -2.0765, 0.7807, -1.9842, 0.7282, -1.9699, 0.7203, -1.9693, 0.7200, -1.9693, 0.7200, -1.9693, 0.7200, -1.9693, 0.7200;... | ||
307 | -3.7185, 0.5587, -2.9740, -0.1562, -2.4555, -0.4191, -2.1705, -0.4915, -2.0706, -0.5060, -2.0551, -0.5077, -2.0544, -0.5078, -2.0544, -0.5078, -2.0544, -0.5078, -2.0544, -0.5078],... | ||
308 | 'relative', tolerance, 'Pulsed traces differ for last pulse width!'); | ||
309 | |||
310 | ev.calculatePulsedCMs(1); | ||
311 | [T,ev] = evalc('ev.calculatePulsedQuadratures(2);'); % supress std out from fct call | ||
312 | ev.calculatePulsedCMs(2); | ||
313 | ev.calibratePulsedCMs; | ||
314 | |||
315 | % check save and reload of ev: transient properties should not be stored | ||
316 | tmpfile = [tempname,'.mat']; | ||
317 | save(tmpfile, 'ev'); | ||
318 | assert(~isempty(ev.pulse_trace)); | ||
319 | clear('ev'); | ||
320 | |||
321 | load(tmpfile); | ||
322 | assert(isempty(ev.pulse_trace)); | ||
323 | delete(tmpfile); | ||
324 | |||
325 | % compare to results as of datoolbox-commit 997cd1260b8b222bd0b6ebf3f8567db04ace24fd | ||
326 | assertCMsEqualUptoSign(ev.pulse_CM_calibrated{2}{1},... | ||
327 | [[0.982359896462452, 0.131028168234013, -0.367189369366558, 0.880348741612935, 0.946576778024290, 0.122862699486762, -0.321838837984714, 0.783722707358365];... | ||
328 | [0.131028168234013, 0.017640103537548, -0.050517532058795, 0.120534462978138, 0.122866665973445, 0.015778083289827, -0.040175061783999, 0.098497215865329];... | ||
329 | [-0.367189369366558, -0.050517532058795, 0.151787439279659, -0.358416760477882, -0.321853066589406, -0.040175675239897, 0.094340702342072, -0.236007779549885];... | ||
330 | [0.880348741612935, 0.120534462978138, -0.358416760477882, 0.848212560720341, 0.783741799699913, 0.098496642634894, -0.236002490360790, 0.587370230126137];... | ||
331 | [0.946576778024290, 0.122866665973445, -0.321853066589406, 0.783741799699913, 0.982360871144707, 0.131024476233387, -0.367180133703403, 0.880340233793472];... | ||
332 | [0.122862699486762, 0.015778083289827, -0.040175675239897, 0.098496642634894, 0.131024476233387, 0.017639128855292, -0.050515242330064, 0.120530651668499];... | ||
333 | [-0.321838837984714, -0.040175061783999, 0.094340702342072, -0.236002490360790, -0.367180133703403, -0.050515242330064, 0.151784942728085, -0.358414152751479];... | ||
334 | [0.783722707358365, 0.098497215865329, -0.236007779549885, 0.587370230126137, 0.880340233793472, 0.120530651668499, -0.358414152751479, 0.848215057271915]]); | ||
335 | 335 | ||
336 | 336 | function pulse_pairs_coverage_test(shared) | function pulse_pairs_coverage_test(shared) |
337 | ev = ev_setup_test(shared); | ||
338 | ev.mech_frequencies = shared.mech_freqs; | ||
339 | ev.opt_pulse_widths = 1e2*[1, 1]; | ||
340 | ev.pulse_gammas = logspace(-1,1,10); | ||
341 | ev.samples_per_pulse = 4*ev.samples_per_pulse; % adjust samples_per_pulse, since in commit 6dcad7dc617c9bed38f45823b049e556264b694f it has been lower by a factor of 4; | ||
342 | |||
343 | ev.pulse_pairs_coverage = 0.1; | ||
344 | |||
345 | % check that pulse_pairs_per_trace depends on pulse_pairs_coverage | ||
346 | assertEqual(ev.pulse_pairs_per_trace,2) | ||
347 | ev.pulse_pairs_coverage = 0.2; | ||
348 | assertEqual(ev.pulse_pairs_per_trace,5) | ||
349 | |||
350 | |||
351 | [T,ev] = evalc('ev.calculateModeVectors;'); % supress std out from fct call | ||
352 | [T,ev] = evalc('ev.calculatePulsedQuadratures(1);'); % supress std out from fct call | ||
353 | assertEqual(size(ev.pulse_Y{1}),... | ||
354 | [ev.pulse_pairs_per_trace, ev.mech_frequencies_no*ev.pulse_gammas_no]); | ||
355 | |||
356 | % first pulse is the same as in run_test (as expected) | ||
357 | tolerance = 1e-2; | ||
358 | % assertElementsAlmostEqual(... | ||
359 | % [ev.pulse_Q{1}(1,:); ev.pulse_P{1}(1,:);... | ||
360 | % ev.pulse_X{1}(1,:); ev.pulse_Y{1}(1,:)],... | ||
361 | % [-2.2115, -2.4141, -1.6618, -2.3063, -1.3238, -2.0629, -1.1502, -1.8850, -1.0911, -1.8164, -1.0820, -1.8055, -1.0816, -1.8051, -1.0816, -1.8051, -1.0816, -1.8051, -1.0816, -1.8051;... | ||
362 | % 3.2915, -2.9633, 2.7127, -2.1359, 2.2809, -1.6272, 2.0343, -1.3764, 1.9462, -1.2934, 1.9325, -1.2808, 1.9320, -1.2803, 1.9320, -1.2803, 1.9320, -1.2803, 1.9320, -1.2803;... | ||
363 | % -2.0535, -2.6901, -1.5796, -2.4139, -1.2766, -2.1129, -1.1172, -1.9160, -1.0623, -1.8423, -1.0539, -1.8307, -1.0535, -1.8302, -1.0535, -1.8302, -1.0535, -1.8302, -1.0535, -1.8302;... | ||
364 | % 3.3518, -2.5439, 2.7367, -1.9035, 2.2923, -1.4906, 2.0413, -1.2802, 1.9521, -1.2093, 1.9382, -1.1984, 1.9377, -1.1980, 1.9377, -1.1980, 1.9377, -1.1980, 1.9377, -1.1980],... | ||
365 | % 'relative', tolerance, 'Pulsed traces differ for first pulse width!'); | ||
366 | |||
367 | % last pulse is different from run_test (as expected) and equals: | ||
368 | assertColsAlmostEqualUptoSign(... | ||
369 | [ev.pulse_Q{1}(end,:); ev.pulse_P{1}(end,:);... | ||
370 | ev.pulse_X{1}(end,:); ev.pulse_Y{1}(end,:)],... | ||
371 | [-0.2815, -3.2285, -0.1393, -2.7479, -0.0754, -2.3291, -0.0500, -2.0802, -0.0426, -1.9905, -0.0415, -1.9765 -0.0415, -1.9759, -0.0415, -1.9759, -0.0415, -1.9759, -0.0415, -1.9759;... | ||
372 | 3.5591, -1.0467, 2.8629, -0.5686, 2.3768, -0.3370, 2.1076, -0.2420, 2.0127, -0.2138, 1.9980, -0.2096 1.9974, -0.2094, 1.9974, -0.2094, 1.9974, -0.2094, 1.9974, -0.2094;... | ||
373 | -0.4042, -3.1501, -0.2029, -2.7287, -0.1116, -2.3262, -0.0753, -2.0811, -0.0645, -1.9921, -0.0630, -1.9782 -0.0629, -1.9776, -0.0629, -1.9776, -0.0629, -1.9776, -0.0629, -1.9776;... | ||
374 | 3.5553, -1.3827, 2.8655, -0.7538, 2.3799, -0.4449, 2.1104, -0.3176, 2.0154, -0.2796, 2.0006, -0.2740 2.0000, -0.2738, 2.0000, -0.2738, 2.0000, -0.2738, 2.0000, -0.2738],... | ||
375 | 'relative', tolerance, 'Pulsed traces differ for last pulse width!'); | ||
337 | ev = ev_setup_test(shared); | ||
338 | ev.mech_frequencies = shared.mech_freqs; | ||
339 | ev.opt_pulse_widths = 1e2*[1, 1]; | ||
340 | ev.pulse_gammas = logspace(-1,1,10); | ||
341 | ev.samples_per_pulse = 4*ev.samples_per_pulse; % adjust samples_per_pulse, since in commit 6dcad7dc617c9bed38f45823b049e556264b694f it has been lower by a factor of 4; | ||
342 | |||
343 | ev.pulse_pairs_coverage = 0.1; | ||
344 | |||
345 | % check that pulse_pairs_per_trace depends on pulse_pairs_coverage | ||
346 | assertEqual(ev.pulse_pairs_per_trace,2) | ||
347 | ev.pulse_pairs_coverage = 0.2; | ||
348 | assertEqual(ev.pulse_pairs_per_trace,5) | ||
349 | |||
350 | |||
351 | [T,ev] = evalc('ev.calculateModeVectors;'); % supress std out from fct call | ||
352 | [T,ev] = evalc('ev.calculatePulsedQuadratures(1);'); % supress std out from fct call | ||
353 | assertEqual(size(ev.pulse_Y{1}),... | ||
354 | [ev.pulse_pairs_per_trace, ev.mech_frequencies_no*ev.pulse_gammas_no]); | ||
355 | |||
356 | % first pulse is the same as in run_test (as expected) | ||
357 | tolerance = 1e-2; | ||
358 | % assertElementsAlmostEqual(... | ||
359 | % [ev.pulse_Q{1}(1,:); ev.pulse_P{1}(1,:);... | ||
360 | % ev.pulse_X{1}(1,:); ev.pulse_Y{1}(1,:)],... | ||
361 | % [-2.2115, -2.4141, -1.6618, -2.3063, -1.3238, -2.0629, -1.1502, -1.8850, -1.0911, -1.8164, -1.0820, -1.8055, -1.0816, -1.8051, -1.0816, -1.8051, -1.0816, -1.8051, -1.0816, -1.8051;... | ||
362 | % 3.2915, -2.9633, 2.7127, -2.1359, 2.2809, -1.6272, 2.0343, -1.3764, 1.9462, -1.2934, 1.9325, -1.2808, 1.9320, -1.2803, 1.9320, -1.2803, 1.9320, -1.2803, 1.9320, -1.2803;... | ||
363 | % -2.0535, -2.6901, -1.5796, -2.4139, -1.2766, -2.1129, -1.1172, -1.9160, -1.0623, -1.8423, -1.0539, -1.8307, -1.0535, -1.8302, -1.0535, -1.8302, -1.0535, -1.8302, -1.0535, -1.8302;... | ||
364 | % 3.3518, -2.5439, 2.7367, -1.9035, 2.2923, -1.4906, 2.0413, -1.2802, 1.9521, -1.2093, 1.9382, -1.1984, 1.9377, -1.1980, 1.9377, -1.1980, 1.9377, -1.1980, 1.9377, -1.1980],... | ||
365 | % 'relative', tolerance, 'Pulsed traces differ for first pulse width!'); | ||
366 | |||
367 | % last pulse is different from run_test (as expected) and equals: | ||
368 | assertColsAlmostEqualUptoSign(... | ||
369 | [ev.pulse_Q{1}(end,:); ev.pulse_P{1}(end,:);... | ||
370 | ev.pulse_X{1}(end,:); ev.pulse_Y{1}(end,:)],... | ||
371 | [-0.2815, -3.2285, -0.1393, -2.7479, -0.0754, -2.3291, -0.0500, -2.0802, -0.0426, -1.9905, -0.0415, -1.9765 -0.0415, -1.9759, -0.0415, -1.9759, -0.0415, -1.9759, -0.0415, -1.9759;... | ||
372 | 3.5591, -1.0467, 2.8629, -0.5686, 2.3768, -0.3370, 2.1076, -0.2420, 2.0127, -0.2138, 1.9980, -0.2096 1.9974, -0.2094, 1.9974, -0.2094, 1.9974, -0.2094, 1.9974, -0.2094;... | ||
373 | -0.4042, -3.1501, -0.2029, -2.7287, -0.1116, -2.3262, -0.0753, -2.0811, -0.0645, -1.9921, -0.0630, -1.9782 -0.0629, -1.9776, -0.0629, -1.9776, -0.0629, -1.9776, -0.0629, -1.9776;... | ||
374 | 3.5553, -1.3827, 2.8655, -0.7538, 2.3799, -0.4449, 2.1104, -0.3176, 2.0154, -0.2796, 2.0006, -0.2740 2.0000, -0.2738, 2.0000, -0.2738, 2.0000, -0.2738, 2.0000, -0.2738],... | ||
375 | 'relative', tolerance, 'Pulsed traces differ for last pulse width!'); | ||
376 | 376 | ||
377 | 377 | function set_samples_per_pulse_test(shared) | function set_samples_per_pulse_test(shared) |
378 | ev = ev_setup_test(shared); | ||
378 | ev = ev_setup_test(shared); | ||
379 | 379 | ||
380 | % information is insufficient ==> samples_per_pulse should default to 0 | ||
381 | assertEqual(ev.samples_per_pulse, 0) | ||
380 | % information is insufficient ==> samples_per_pulse should default to 0 | ||
381 | assertEqual(ev.samples_per_pulse, 0) | ||
382 | 382 | ||
383 | % check default setting with adequate information | ||
384 | ev.mech_frequencies = shared.mech_freqs; | ||
385 | ev.opt_pulse_widths = 1e2*[1, 1]; | ||
386 | ev.pulse_gammas = logspace(-1,1,10); | ||
383 | % check default setting with adequate information | ||
384 | ev.mech_frequencies = shared.mech_freqs; | ||
385 | ev.opt_pulse_widths = 1e2*[1, 1]; | ||
386 | ev.pulse_gammas = logspace(-1,1,10); | ||
387 | 387 | ||
388 | samples_per_pulse = 50; % default for evaluation specifed above | ||
389 | assertEqual(ev.samples_per_pulse, samples_per_pulse) | ||
390 | [T,ev] = evalc('ev.calculateModeVectors;'); % supress std out from fct call | ||
391 | assertEqual(size(ev.entangling_modes,2), samples_per_pulse) | ||
388 | samples_per_pulse = 50; % default for evaluation specifed above | ||
389 | assertEqual(ev.samples_per_pulse, samples_per_pulse) | ||
390 | [T,ev] = evalc('ev.calculateModeVectors;'); % supress std out from fct call | ||
391 | assertEqual(size(ev.entangling_modes,2), samples_per_pulse) | ||
392 | 392 | ||
393 | % check explicit setting of samples_per_pulse | ||
394 | samples_per_pulse = 30; | ||
395 | ev.samples_per_pulse = samples_per_pulse; | ||
396 | assertEqual(ev.samples_per_pulse, samples_per_pulse) | ||
397 | [T,ev] = evalc('ev.calculateModeVectors;'); % supress std out from fct call | ||
398 | assertEqual(size(ev.entangling_modes,2), samples_per_pulse) | ||
393 | % check explicit setting of samples_per_pulse | ||
394 | samples_per_pulse = 30; | ||
395 | ev.samples_per_pulse = samples_per_pulse; | ||
396 | assertEqual(ev.samples_per_pulse, samples_per_pulse) | ||
397 | [T,ev] = evalc('ev.calculateModeVectors;'); % supress std out from fct call | ||
398 | assertEqual(size(ev.entangling_modes,2), samples_per_pulse) | ||
399 | 399 | ||
400 | 400 | function ev = run_quick_test(shared) | function ev = run_quick_test(shared) |
401 | ev = ev_setup_test(shared); | ||
402 | ev.mech_frequencies = [1, 2]; | ||
403 | ev.opt_pulse_widths = 1e2*[1, 1]; | ||
404 | ev.pulse_gammas = logspace(-1,1,10); | ||
405 | |||
406 | [T,ev] = evalc('ev.calculateModeVectors;'); % supress std out from fct call | ||
407 | pulsepairs_no = 100; | ||
408 | [T,ev] = evalc('ev.calculatePulsedQuadratures(1, ''pulsepairs'', pulsepairs_no);'); | ||
409 | [T,ev] = evalc('ev.calculatePulsedQuadratures(2, ''pulsepairs'', pulsepairs_no);'); | ||
410 | assertEqual(size(ev.pulse_Q{1}),... | ||
411 | [pulsepairs_no, ev.mech_frequencies_no*ev.pulse_gammas_no]); | ||
412 | ev.exportResults('software_version', false); | ||
413 | %type(fullfile(ev.evaluation_folder, 'evaluation_parameters.txt')) | ||
414 | |||
415 | ev.calculatePulsedCMs; | ||
416 | |||
417 | % test calibratePulsedCMs with wrong shotnoise_ind | ||
418 | % manipulate data to create a difference between the two sets of pulsed CMs | ||
419 | ev.pulse_CM{2}{1}=eye(size(ev.pulse_CM{2}{1})); | ||
420 | % calibrate with the wrong data --> non-shotnoise-data should now look like shotnoise | ||
421 | ev.calibratePulsedCMs('shotnoise_ind', 2); | ||
422 | assertElementsAlmostEqual(ev.pulse_CM_calibrated{2}{1}, eye(size(ev.pulse_CM{2}{1}))/2) | ||
423 | ev.calibratePulsedCMs; | ||
424 | assertElementsAlmostEqual(ev.pulse_CM_calibrated{1}{1}, ... | ||
425 | calibrate_cm(ev.pulse_CM{1}{1}, ev.pulse_CM{1}{1})) | ||
401 | ev = ev_setup_test(shared); | ||
402 | ev.mech_frequencies = [1, 2]; | ||
403 | ev.opt_pulse_widths = 1e2*[1, 1]; | ||
404 | ev.pulse_gammas = logspace(-1,1,10); | ||
405 | |||
406 | [T,ev] = evalc('ev.calculateModeVectors;'); % supress std out from fct call | ||
407 | pulsepairs_no = 100; | ||
408 | [T,ev] = evalc('ev.calculatePulsedQuadratures(1, ''pulsepairs'', pulsepairs_no);'); | ||
409 | [T,ev] = evalc('ev.calculatePulsedQuadratures(2, ''pulsepairs'', pulsepairs_no);'); | ||
410 | assertEqual(size(ev.pulse_Q{1}),... | ||
411 | [pulsepairs_no, ev.mech_frequencies_no*ev.pulse_gammas_no]); | ||
412 | ev.exportResults('software_version', false); | ||
413 | %type(fullfile(ev.evaluation_folder, 'evaluation_parameters.txt')) | ||
414 | |||
415 | ev.calculatePulsedCMs; | ||
416 | |||
417 | % test calibratePulsedCMs with wrong shotnoise_ind | ||
418 | % manipulate data to create a difference between the two sets of pulsed CMs | ||
419 | ev.pulse_CM{2}{1}=eye(size(ev.pulse_CM{2}{1})); | ||
420 | % calibrate with the wrong data --> non-shotnoise-data should now look like shotnoise | ||
421 | ev.calibratePulsedCMs('shotnoise_ind', 2); | ||
422 | assertElementsAlmostEqual(ev.pulse_CM_calibrated{2}{1}, eye(size(ev.pulse_CM{2}{1}))/2) | ||
423 | ev.calibratePulsedCMs; | ||
424 | assertElementsAlmostEqual(ev.pulse_CM_calibrated{1}{1}, ... | ||
425 | calibrate_cm(ev.pulse_CM{1}{1}, ev.pulse_CM{1}{1})) | ||
426 | 426 | ||
427 | 427 | function ev = run_quicker_test(shared) | function ev = run_quicker_test(shared) |
428 | ev = ev_setup_test(shared); | ||
429 | ev.mech_frequencies = [1.2, 2.3, 4.1,5.7]; | ||
430 | ev.opt_pulse_widths = 1e2*ones(size(ev.mech_frequencies)); | ||
431 | ev.pulse_gammas = logspace(-1,1,10); | ||
428 | ev = ev_setup_test(shared); | ||
429 | ev.mech_frequencies = [1.2, 2.3, 4.1,5.7]; | ||
430 | ev.opt_pulse_widths = 1e2*ones(size(ev.mech_frequencies)); | ||
431 | ev.pulse_gammas = logspace(-1,1,10); | ||
432 | 432 | ||
433 | [T,ev] = evalc('ev.calculateModeVectors;'); % supress std out from fct call | ||
434 | pulsepairs_no = 100; | ||
435 | [T,ev] = evalc('ev.calculatePulsedQuadratures(1, ''pulsepairs'', pulsepairs_no);'); | ||
436 | [T,ev] = evalc('ev.calculatePulsedQuadratures(2, ''pulsepairs'', pulsepairs_no);'); | ||
437 | [T,ev] = evalc('ev.calibratePulsedCMs;'); | ||
433 | [T,ev] = evalc('ev.calculateModeVectors;'); % supress std out from fct call | ||
434 | pulsepairs_no = 100; | ||
435 | [T,ev] = evalc('ev.calculatePulsedQuadratures(1, ''pulsepairs'', pulsepairs_no);'); | ||
436 | [T,ev] = evalc('ev.calculatePulsedQuadratures(2, ''pulsepairs'', pulsepairs_no);'); | ||
437 | [T,ev] = evalc('ev.calibratePulsedCMs;'); | ||
438 | 438 | ||
439 | 439 | function getters_with_missing_properties_test(shared) | function getters_with_missing_properties_test(shared) |
440 | %% check that the fallback options provided for the getters for | ||
441 | %% mech_frequencies_no, pulse_gammas_no, and tracepairs_no | ||
442 | %% are defined correctly | ||
443 | %% (fallback means: if mech_frequencies, pulse_gammas, or tracepairs are undefined) | ||
444 | |||
445 | % do quick eval to generate data | ||
446 | ev = run_quick_test(shared); | ||
447 | ev.exportResults; | ||
448 | |||
449 | % reimport traces to a blank eval-object to get | ||
450 | % values with measurement-object, mech_frequencies, pulse_gammas removed | ||
451 | ev_traced = entanglement_evaluation; | ||
452 | ev_traced.evaluation_folder = ev.evaluation_folder; | ||
453 | ev_traced.import_traces; | ||
454 | |||
455 | % values without measurement-object | ||
456 | assertEqual(ev_traced.tracepairs_no, ev.tracepairs_no,... | ||
457 | ['tracepairs_no does not match']); | ||
458 | assertEqual(ev_traced.mech_frequencies_no, ev.mech_frequencies_no,... | ||
459 | ['mech_frequencies_no does not match']); | ||
460 | assertEqual(ev_traced.pulse_gammas_no, ev.pulse_gammas_no,... | ||
461 | ['pulse_gammas_no does not match']); | ||
462 | |||
463 | % reimport CMs to a blank eval-object to get | ||
464 | % values with measurement-object, mech_frequencies, pulse_gammas removed | ||
465 | ev3 = entanglement_evaluation; | ||
466 | ev3.evaluation_folder = ev.evaluation_folder; | ||
467 | ev3.import_CMs; | ||
468 | |||
469 | % values without measurement-object | ||
470 | assertEqual(ev3.tracepairs_no, ev.tracepairs_no,... | ||
471 | ['tracepairs_no does not match']); | ||
472 | assertEqual(ev3.mech_frequencies_no, ev.mech_frequencies_no,... | ||
473 | ['mech_frequencies_no does not match']); | ||
474 | assertEqual(ev3.pulse_gammas_no, ev.pulse_gammas_no,... | ||
475 | ['pulse_gammas_no does not match']); | ||
440 | %% check that the fallback options provided for the getters for | ||
441 | %% mech_frequencies_no, pulse_gammas_no, and tracepairs_no | ||
442 | %% are defined correctly | ||
443 | %% (fallback means: if mech_frequencies, pulse_gammas, or tracepairs are undefined) | ||
444 | |||
445 | % do quick eval to generate data | ||
446 | ev = run_quick_test(shared); | ||
447 | ev.exportResults; | ||
448 | |||
449 | % reimport traces to a blank eval-object to get | ||
450 | % values with measurement-object, mech_frequencies, pulse_gammas removed | ||
451 | ev_traced = entanglement_evaluation; | ||
452 | ev_traced.evaluation_folder = ev.evaluation_folder; | ||
453 | ev_traced.import_traces; | ||
454 | |||
455 | % values without measurement-object | ||
456 | assertEqual(ev_traced.tracepairs_no, ev.tracepairs_no,... | ||
457 | ['tracepairs_no does not match']); | ||
458 | assertEqual(ev_traced.mech_frequencies_no, ev.mech_frequencies_no,... | ||
459 | ['mech_frequencies_no does not match']); | ||
460 | assertEqual(ev_traced.pulse_gammas_no, ev.pulse_gammas_no,... | ||
461 | ['pulse_gammas_no does not match']); | ||
462 | |||
463 | % reimport CMs to a blank eval-object to get | ||
464 | % values with measurement-object, mech_frequencies, pulse_gammas removed | ||
465 | ev3 = entanglement_evaluation; | ||
466 | ev3.evaluation_folder = ev.evaluation_folder; | ||
467 | ev3.import_CMs; | ||
468 | |||
469 | % values without measurement-object | ||
470 | assertEqual(ev3.tracepairs_no, ev.tracepairs_no,... | ||
471 | ['tracepairs_no does not match']); | ||
472 | assertEqual(ev3.mech_frequencies_no, ev.mech_frequencies_no,... | ||
473 | ['mech_frequencies_no does not match']); | ||
474 | assertEqual(ev3.pulse_gammas_no, ev.pulse_gammas_no,... | ||
475 | ['pulse_gammas_no does not match']); | ||
476 | 476 | ||
477 | 477 | function export_import_test(shared) | function export_import_test(shared) |
478 | ev = ev_setup_test(shared); | ||
479 | |||
480 | mech_freqs_no = 2; | ||
481 | pulse_gammas_no = 3; | ||
482 | pulse_pairs_no = 100; | ||
483 | |||
484 | ev.mech_frequencies = ones(mech_freqs_no, 1); | ||
485 | ev.opt_pulse_widths = ones(mech_freqs_no, 1); | ||
486 | ev.pulse_gammas = ones(pulse_gammas_no, 1); | ||
487 | |||
488 | %%%% NEW EXPORT/IMPORT TEST | ||
489 | % mock data | ||
490 | Q_before = repmat([11, 12, 21, 22, 31, 32],pulse_pairs_no,1); | ||
491 | Q = {}; P = {}; X = {}; Y = {}; | ||
492 | Q{1} = Q_before; P{1} = 10*Q{1}; X{1} = 100*Q{1}; Y{1} = 1000*Q{1}; | ||
493 | Q{2} = Q_before+1; P{2} = 10*Q{2}; X{2} = 100*Q{2}; Y{2} = 1000*Q{2}; | ||
494 | |||
495 | % reorder mock data into pulse_trace{tracepair_ind}{gam_ind} | ||
496 | for pow_ind=1:ev.tracepairs_no | ||
497 | for gam_ind=1:ev.pulse_gammas_no | ||
498 | %reorder into Q1, Q2,.., P1, P2,.., X1, X2,.., Y1, Y2,... | ||
499 | first_mode_ind = (gam_ind-1)*ev.mech_frequencies_no + 1; | ||
500 | last_mode_ind = gam_ind*ev.mech_frequencies_no; | ||
501 | |||
502 | q = Q{pow_ind}(:, first_mode_ind:last_mode_ind); | ||
503 | p = P{pow_ind}(:, first_mode_ind:last_mode_ind); | ||
504 | x = X{pow_ind}(:, first_mode_ind:last_mode_ind); | ||
505 | y = Y{pow_ind}(:, first_mode_ind:last_mode_ind); | ||
506 | |||
507 | % reorder into Q1, P1, Q2, P2,..., X1, Y1, X2, Y2,... | ||
508 | pulse_trace = permute_data([q, p, x, y]); | ||
509 | ev.pulse_trace{pow_ind}{gam_ind} = pulse_trace; | ||
510 | ev.pulse_CM{pow_ind}{gam_ind} = cov(pulse_trace); | ||
511 | end | ||
512 | end | ||
513 | |||
514 | % check export from ev-object | ||
515 | ev.exportResults('software_version', false); | ||
516 | |||
517 | import = load(fullfile(ev.evaluation_folder, 'pulsed_traces.mat')); | ||
518 | assertEqual(import.pulsed_traces, ev.pulse_trace) | ||
519 | ev.pulse_trace{1}{1}=2; | ||
520 | assert(~isequal(import.pulsed_traces, ev.pulse_trace)) | ||
521 | |||
522 | % check (re-)import into ev-object | ||
523 | ev.pulse_trace = {}; | ||
524 | assert(~isequal(import.pulsed_traces, ev.pulse_trace)) | ||
525 | ev.import_traces(); | ||
526 | assertEqual(import.pulsed_traces, ev.pulse_trace) | ||
527 | |||
528 | % import via import_data_and_CM | ||
529 | % CAUTION: DON'T USE just ev_original = ev; | ||
530 | % since entanglement_evaluation is a handle object, we need a proper copy-method | ||
531 | % (as provided by the abstract handle superclass Copyable) to make the following tests run | ||
532 | ev_original = copy(ev); | ||
533 | testval_original = ev.pulse_Q{2}(1,2); | ||
534 | ev.pulse_trace = {[]}; % empty the pulse_trace property | ||
535 | % ---> also gets rid of the dependent pulse_Q, pulse_P,... properties | ||
536 | assert(~isequal(ev_original.pulse_Q, ev.pulse_Q), 'They should not be equal!') | ||
537 | |||
538 | ev.import_traces(); | ||
539 | assertEqual(testval_original, ev.pulse_Q{2}(1,2)) | ||
540 | assertEqual(ev_original.pulse_Q{1}, ev.pulse_Q{1}) | ||
541 | assertEqual(ev_original.pulse_P{1}, ev.pulse_P{1}) | ||
542 | assertEqual(ev_original.pulse_X{1}, ev.pulse_X{1}) | ||
543 | assertEqual(ev_original.pulse_Y{1}, ev.pulse_Y{1}) | ||
544 | |||
545 | assertEqual(ev_original.pulse_Q{2}, ev.pulse_Q{2}) | ||
546 | assertEqual(ev_original.pulse_P{2}, ev.pulse_P{2}) | ||
547 | assertEqual(ev_original.pulse_X{2}, ev.pulse_X{2}) | ||
548 | assertEqual(ev_original.pulse_Y{2}, ev.pulse_Y{2}) | ||
549 | |||
550 | % check that saving the evaluation-object via method exportResults works as expected | ||
551 | ev.exportResults('software_version', false); | ||
552 | |||
553 | assert(~isempty(ev.pulse_trace)); | ||
554 | clear('ev') | ||
555 | load(fullfile(shared.evaluation_folder, 'ev.mat')) | ||
556 | assert(isempty(ev.pulse_trace)); | ||
478 | ev = ev_setup_test(shared); | ||
479 | |||
480 | mech_freqs_no = 2; | ||
481 | pulse_gammas_no = 3; | ||
482 | pulse_pairs_no = 100; | ||
483 | |||
484 | ev.mech_frequencies = ones(mech_freqs_no, 1); | ||
485 | ev.opt_pulse_widths = ones(mech_freqs_no, 1); | ||
486 | ev.pulse_gammas = ones(pulse_gammas_no, 1); | ||
487 | |||
488 | %%%% NEW EXPORT/IMPORT TEST | ||
489 | % mock data | ||
490 | Q_before = repmat([11, 12, 21, 22, 31, 32],pulse_pairs_no,1); | ||
491 | Q = {}; P = {}; X = {}; Y = {}; | ||
492 | Q{1} = Q_before; P{1} = 10*Q{1}; X{1} = 100*Q{1}; Y{1} = 1000*Q{1}; | ||
493 | Q{2} = Q_before+1; P{2} = 10*Q{2}; X{2} = 100*Q{2}; Y{2} = 1000*Q{2}; | ||
494 | |||
495 | % reorder mock data into pulse_trace{tracepair_ind}{gam_ind} | ||
496 | for pow_ind=1:ev.tracepairs_no | ||
497 | for gam_ind=1:ev.pulse_gammas_no | ||
498 | %reorder into Q1, Q2,.., P1, P2,.., X1, X2,.., Y1, Y2,... | ||
499 | first_mode_ind = (gam_ind-1)*ev.mech_frequencies_no + 1; | ||
500 | last_mode_ind = gam_ind*ev.mech_frequencies_no; | ||
501 | |||
502 | q = Q{pow_ind}(:, first_mode_ind:last_mode_ind); | ||
503 | p = P{pow_ind}(:, first_mode_ind:last_mode_ind); | ||
504 | x = X{pow_ind}(:, first_mode_ind:last_mode_ind); | ||
505 | y = Y{pow_ind}(:, first_mode_ind:last_mode_ind); | ||
506 | |||
507 | % reorder into Q1, P1, Q2, P2,..., X1, Y1, X2, Y2,... | ||
508 | pulse_trace = permute_data([q, p, x, y]); | ||
509 | ev.pulse_trace{pow_ind}{gam_ind} = pulse_trace; | ||
510 | ev.pulse_CM{pow_ind}{gam_ind} = cov(pulse_trace); | ||
511 | end | ||
512 | end | ||
513 | |||
514 | % check export from ev-object | ||
515 | ev.exportResults('software_version', false); | ||
516 | |||
517 | import = load(fullfile(ev.evaluation_folder, 'pulsed_traces.mat')); | ||
518 | assertEqual(import.pulsed_traces, ev.pulse_trace) | ||
519 | ev.pulse_trace{1}{1}=2; | ||
520 | assert(~isequal(import.pulsed_traces, ev.pulse_trace)) | ||
521 | |||
522 | % check (re-)import into ev-object | ||
523 | ev.pulse_trace = {}; | ||
524 | assert(~isequal(import.pulsed_traces, ev.pulse_trace)) | ||
525 | ev.import_traces(); | ||
526 | assertEqual(import.pulsed_traces, ev.pulse_trace) | ||
527 | |||
528 | % import via import_data_and_CM | ||
529 | % CAUTION: DON'T USE just ev_original = ev; | ||
530 | % since entanglement_evaluation is a handle object, we need a proper copy-method | ||
531 | % (as provided by the abstract handle superclass Copyable) to make the following tests run | ||
532 | ev_original = copy(ev); | ||
533 | testval_original = ev.pulse_Q{2}(1,2); | ||
534 | ev.pulse_trace = {[]}; % empty the pulse_trace property | ||
535 | % ---> also gets rid of the dependent pulse_Q, pulse_P,... properties | ||
536 | assert(~isequal(ev_original.pulse_Q, ev.pulse_Q), 'They should not be equal!') | ||
537 | |||
538 | ev.import_traces(); | ||
539 | assertEqual(testval_original, ev.pulse_Q{2}(1,2)) | ||
540 | assertEqual(ev_original.pulse_Q{1}, ev.pulse_Q{1}) | ||
541 | assertEqual(ev_original.pulse_P{1}, ev.pulse_P{1}) | ||
542 | assertEqual(ev_original.pulse_X{1}, ev.pulse_X{1}) | ||
543 | assertEqual(ev_original.pulse_Y{1}, ev.pulse_Y{1}) | ||
544 | |||
545 | assertEqual(ev_original.pulse_Q{2}, ev.pulse_Q{2}) | ||
546 | assertEqual(ev_original.pulse_P{2}, ev.pulse_P{2}) | ||
547 | assertEqual(ev_original.pulse_X{2}, ev.pulse_X{2}) | ||
548 | assertEqual(ev_original.pulse_Y{2}, ev.pulse_Y{2}) | ||
549 | |||
550 | % check that saving the evaluation-object via method exportResults works as expected | ||
551 | ev.exportResults('software_version', false); | ||
552 | |||
553 | assert(~isempty(ev.pulse_trace)); | ||
554 | clear('ev') | ||
555 | load(fullfile(shared.evaluation_folder, 'ev.mat')) | ||
556 | assert(isempty(ev.pulse_trace)); | ||
557 | 557 | ||
558 | 558 | function corrfct_test(shared) | function corrfct_test(shared) |
559 | ev = ev_setup_test(shared); | ||
560 | |||
561 | max_lags = 10; | ||
562 | [T,ev] = evalc('ev.blocked_cross_correlation(''blocksize'', max_lags);'); % supress std out from fct call | ||
563 | xx = ev.correlation_functions{1}{1,1}; | ||
564 | pp = ev.correlation_functions{1}{2,2}; | ||
565 | xp = ev.correlation_functions{1}{1,2}; | ||
566 | px = ev.correlation_functions{1}{2,1}; | ||
567 | assertElementsAlmostEqual(xx, flipud(xx)); | ||
568 | assertElementsAlmostEqual(pp, flipud(pp)); | ||
569 | assertElementsAlmostEqual(xp, flipud(px)); | ||
570 | |||
571 | xx_ = xcorr(shared.x.data, shared.x.data, max_lags); | ||
572 | xp_ = xcorr(shared.x.data, shared.p.data, max_lags); | ||
573 | assertElementsAlmostEqual(xx, xx_); | ||
574 | |||
575 | rel_tol = 1e-12; | ||
576 | assertElementsAlmostEqual(xp, xp_, 'relative', rel_tol); | ||
577 | |||
578 | % test export and import | ||
579 | corrfct_old = ev.correlation_functions; | ||
580 | ev.exportCrossCorrelationFunctions; | ||
581 | ev.correlation_functions = {[]}; | ||
582 | ev.importCrossCorrelationFunctions(ev.evaluation_folder); | ||
583 | for k=1:2 | ||
584 | for l=1:2 | ||
585 | for m=1:2 | ||
586 | assertEqual(ev.correlation_functions{k}{l,m},... | ||
587 | corrfct_old{k}{l,m}) | ||
588 | end | ||
589 | end | ||
590 | end | ||
559 | ev = ev_setup_test(shared); | ||
560 | |||
561 | max_lags = 10; | ||
562 | [T,ev] = evalc('ev.blocked_cross_correlation(''blocksize'', max_lags);'); % supress std out from fct call | ||
563 | xx = ev.correlation_functions{1}{1,1}; | ||
564 | pp = ev.correlation_functions{1}{2,2}; | ||
565 | xp = ev.correlation_functions{1}{1,2}; | ||
566 | px = ev.correlation_functions{1}{2,1}; | ||
567 | assertElementsAlmostEqual(xx, flipud(xx)); | ||
568 | assertElementsAlmostEqual(pp, flipud(pp)); | ||
569 | assertElementsAlmostEqual(xp, flipud(px)); | ||
570 | |||
571 | xx_ = xcorr(shared.x.data, shared.x.data, max_lags); | ||
572 | xp_ = xcorr(shared.x.data, shared.p.data, max_lags); | ||
573 | assertElementsAlmostEqual(xx, xx_); | ||
574 | |||
575 | rel_tol = 1e-12; | ||
576 | assertElementsAlmostEqual(xp, xp_, 'relative', rel_tol); | ||
577 | |||
578 | % test export and import | ||
579 | corrfct_old = ev.correlation_functions; | ||
580 | ev.exportCrossCorrelationFunctions; | ||
581 | ev.correlation_functions = {[]}; | ||
582 | ev.importCrossCorrelationFunctions(ev.evaluation_folder); | ||
583 | for k=1:2 | ||
584 | for l=1:2 | ||
585 | for m=1:2 | ||
586 | assertEqual(ev.correlation_functions{k}{l,m},... | ||
587 | corrfct_old{k}{l,m}) | ||
588 | end | ||
589 | end | ||
590 | end | ||
591 | 591 | ||
592 | 592 | function efficiency_visibility_simple_test(shared) | function efficiency_visibility_simple_test(shared) |
593 | ev = ev_setup_test(shared); | ||
594 | ev.mech_frequencies = shared.mech_freqs; | ||
595 | |||
596 | %% check for correct default values | ||
597 | assertEqual(ev.homodyne_visibility, 1) | ||
598 | assertEqual(ev.detection_efficiency, 1) | ||
599 | |||
600 | %% checK: calibration works for trivial case | ||
601 | quad_no = 8; | ||
602 | shot_CM = eye(quad_no)/2; | ||
603 | sig_CM = 2*shot_CM; | ||
604 | ev.pulse_CM{1}{1} = shot_CM; | ||
605 | ev.pulse_CM{2}{1} = sig_CM; | ||
606 | ev.calibratePulsedCMs('shotnoise_ind', 1); | ||
607 | tolerance = 1E-6; | ||
608 | assertElementsAlmostEqual(ev.pulse_CM_calibrated{1}{1}, shot_CM, 'absolute', tolerance); | ||
609 | assertElementsAlmostEqual(ev.pulse_CM_calibrated{2}{1}, sig_CM, 'absolute', tolerance); | ||
610 | |||
611 | %% check: calibration works for (almost) trivial case | ||
612 | ev.detection_efficiency = 0.999999; | ||
613 | ev.homodyne_visibility = 0.99999999; | ||
614 | quad_no = 8; | ||
615 | shot_CM = eye(quad_no)/2; | ||
616 | sig_CM = 2*shot_CM; | ||
617 | ev.pulse_CM{1}{1} = shot_CM; | ||
618 | ev.pulse_CM{2}{1} = sig_CM; | ||
619 | ev.calibratePulsedCMs('shotnoise_ind', 1); | ||
620 | tolerance = 1E-6; | ||
621 | assertElementsAlmostEqual(ev.pulse_CM_calibrated{1}{1}, shot_CM, 'absolute', tolerance); | ||
622 | assertElementsAlmostEqual(ev.pulse_CM_calibrated{2}{1}, sig_CM, 'absolute', tolerance); | ||
593 | ev = ev_setup_test(shared); | ||
594 | ev.mech_frequencies = shared.mech_freqs; | ||
595 | |||
596 | %% check for correct default values | ||
597 | assertEqual(ev.homodyne_visibility, 1) | ||
598 | assertEqual(ev.detection_efficiency, 1) | ||
599 | |||
600 | %% checK: calibration works for trivial case | ||
601 | quad_no = 8; | ||
602 | shot_CM = eye(quad_no)/2; | ||
603 | sig_CM = 2*shot_CM; | ||
604 | ev.pulse_CM{1}{1} = shot_CM; | ||
605 | ev.pulse_CM{2}{1} = sig_CM; | ||
606 | ev.calibratePulsedCMs('shotnoise_ind', 1); | ||
607 | tolerance = 1E-6; | ||
608 | assertElementsAlmostEqual(ev.pulse_CM_calibrated{1}{1}, shot_CM, 'absolute', tolerance); | ||
609 | assertElementsAlmostEqual(ev.pulse_CM_calibrated{2}{1}, sig_CM, 'absolute', tolerance); | ||
610 | |||
611 | %% check: calibration works for (almost) trivial case | ||
612 | ev.detection_efficiency = 0.999999; | ||
613 | ev.homodyne_visibility = 0.99999999; | ||
614 | quad_no = 8; | ||
615 | shot_CM = eye(quad_no)/2; | ||
616 | sig_CM = 2*shot_CM; | ||
617 | ev.pulse_CM{1}{1} = shot_CM; | ||
618 | ev.pulse_CM{2}{1} = sig_CM; | ||
619 | ev.calibratePulsedCMs('shotnoise_ind', 1); | ||
620 | tolerance = 1E-6; | ||
621 | assertElementsAlmostEqual(ev.pulse_CM_calibrated{1}{1}, shot_CM, 'absolute', tolerance); | ||
622 | assertElementsAlmostEqual(ev.pulse_CM_calibrated{2}{1}, sig_CM, 'absolute', tolerance); | ||
623 | 623 | ||
624 | 624 | function efficiency_visibility_test(shared) | function efficiency_visibility_test(shared) |
625 | ev = ev_setup_test(shared); | ||
626 | ev.mech_frequencies = shared.mech_freqs; | ||
627 | |||
628 | %% check calibration with visibility and efficiency = 1; passes | ||
629 | nu = 1; % homodyne visibility | ||
630 | eta = 1; % detector efficiency | ||
631 | efficiency_visibility_test_sub(ev, nu, eta) | ||
632 | |||
633 | %% check calibration with suboptimal efficiency; shotnoise passes | ||
634 | nu = 1; % homodyne visibility | ||
635 | eta = rand(1); % detector efficiency | ||
636 | efficiency_visibility_test_sub(ev, nu, eta) | ||
637 | |||
638 | %% check calibration with suboptimal visibility; shotnoise passes | ||
639 | nu = rand(1); % homodyne visibility | ||
640 | eta = 1; % detector efficiency | ||
641 | efficiency_visibility_test_sub(ev, nu, eta) | ||
642 | |||
643 | %% check calibration with suboptimal visibility and efficiency; shotnoise passes | ||
644 | nu = rand(1); % homodyne visibility | ||
645 | eta = rand(1); % detector efficiency | ||
646 | efficiency_visibility_test_sub(ev, nu, eta) | ||
625 | ev = ev_setup_test(shared); | ||
626 | ev.mech_frequencies = shared.mech_freqs; | ||
627 | |||
628 | %% check calibration with visibility and efficiency = 1; passes | ||
629 | nu = 1; % homodyne visibility | ||
630 | eta = 1; % detector efficiency | ||
631 | efficiency_visibility_test_sub(ev, nu, eta) | ||
632 | |||
633 | %% check calibration with suboptimal efficiency; shotnoise passes | ||
634 | nu = 1; % homodyne visibility | ||
635 | eta = rand(1); % detector efficiency | ||
636 | efficiency_visibility_test_sub(ev, nu, eta) | ||
637 | |||
638 | %% check calibration with suboptimal visibility; shotnoise passes | ||
639 | nu = rand(1); % homodyne visibility | ||
640 | eta = 1; % detector efficiency | ||
641 | efficiency_visibility_test_sub(ev, nu, eta) | ||
642 | |||
643 | %% check calibration with suboptimal visibility and efficiency; shotnoise passes | ||
644 | nu = rand(1); % homodyne visibility | ||
645 | eta = rand(1); % detector efficiency | ||
646 | efficiency_visibility_test_sub(ev, nu, eta) | ||
647 | 647 | ||
648 | 648 | function efficiency_visibility_test_sub(ev, nu, eta) | function efficiency_visibility_test_sub(ev, nu, eta) |
649 | amp = 0.1; % fake conversion factor from units of vacua to Volt | ||
650 | prefix = ['nu=',num2str(nu),'; eta=', num2str(eta), '. ', 10]; | ||
651 | |||
652 | %% create fake idealized data | ||
653 | sample_no = 1E5; quad_no = 8; | ||
654 | shot_CM_ideal = eye(quad_no)/2; | ||
655 | sig_CM_ideal = 3*2*shot_CM_ideal + 0.1*ones(quad_no); | ||
656 | [shot_ideal, sig_ideal] = get_uncorr_rand_nums_from_sample_covs(... | ||
657 | sample_no, shot_CM_ideal, sig_CM_ideal); | ||
658 | |||
659 | %% check: correct CMs? | ||
660 | assertElementsAlmostEqual(cov(shot_ideal), shot_CM_ideal,... | ||
661 | [prefix, 'CM for fake ideal shotnoise not as expected.']) | ||
662 | assertElementsAlmostEqual(cov(sig_ideal), sig_CM_ideal,... | ||
663 | [prefix, 'CM for fake ideal signal not as expected.']) | ||
664 | |||
665 | %% check: shotnoise and signal uncorrelated? | ||
666 | assertElementsAlmostEqual(corr(shot_ideal, sig_ideal), zeros(quad_no),... | ||
667 | [prefix, 'Correlations between fake signal and shotnoise not as expected.']) | ||
668 | |||
669 | % disp([10, 10, '***************',10, prefix, 'fake ideal data as expected!',10]) | ||
670 | |||
671 | %% convert to fake measured data | ||
672 | shot_measured = sqrt(eta)*shot_ideal; | ||
673 | sig_measured = eta*nu*sig_ideal + sqrt(eta*(1 - eta*(nu^2)))*shot_ideal; | ||
674 | |||
675 | shot_measured = amp*shot_measured; | ||
676 | sig_measured = amp*sig_measured; | ||
677 | |||
678 | %% check that fake measured data satisfies expected relations | ||
679 | tolerance = 1E-2; | ||
680 | CM_shot_expected = (amp^2)*eta*shot_CM_ideal; | ||
681 | % reldiff (CM_shot_expected, cov(shot_measured)) | ||
682 | assertElementsAlmostEqual(cov(shot_measured), CM_shot_expected, 'absolute', tolerance,... | ||
683 | [prefix, 'CM for fake measured shotnoise not as expected!']) | ||
684 | |||
685 | CM_sig_expected = (amp^2)*((eta^2)*(nu^2)*sig_CM_ideal + eta*(1 - eta*(nu^2))*shot_CM_ideal); | ||
686 | assertElementsAlmostEqual(cov(sig_measured), CM_sig_expected, 'absolute', tolerance,... | ||
687 | [prefix, 'CM for fake measured signal not as expected!']) | ||
688 | |||
689 | % disp([10, 10, '***************',10, prefix, 'fake measurement data as expected!',10]) | ||
690 | |||
691 | %% evaluate fake data | ||
692 | ev.homodyne_visibility = nu; | ||
693 | ev.detection_efficiency = eta; | ||
694 | |||
695 | ev.pulse_trace{1}{1} = shot_measured; | ||
696 | ev.pulse_trace{2}{1} = sig_measured; | ||
697 | |||
698 | ev.calculatePulsedCMs; | ||
699 | assertEqual(cov(shot_measured), ev.pulse_CM{1}{1}) | ||
700 | assertEqual(cov(sig_measured), ev.pulse_CM{2}{1}) | ||
701 | ev.calibratePulsedCMs('shotnoise_ind', 1); | ||
702 | |||
703 | % expect to recover specified sample CMs | ||
704 | tolerance = 1E-2; | ||
705 | assertElementsAlmostEqual(ev.pulse_CM_calibrated{1}{1}, shot_CM_ideal, 'absolute', tolerance,... | ||
706 | [prefix, 'Efficiency- and visibility-corrected CM for shotnoise not as expected!']); | ||
707 | assertElementsAlmostEqual(ev.pulse_CM_calibrated{2}{1}, sig_CM_ideal, 'absolute', tolerance,... | ||
708 | [prefix, 'Efficiency- and visibility-corrected CM for signal not as expected!']); | ||
709 | % disp([10, 10, '***************',10, prefix, 'correction performed as expected!',10]) | ||
649 | amp = 0.1; % fake conversion factor from units of vacua to Volt | ||
650 | prefix = ['nu=',num2str(nu),'; eta=', num2str(eta), '. ', 10]; | ||
651 | |||
652 | %% create fake idealized data | ||
653 | sample_no = 1E5; quad_no = 8; | ||
654 | shot_CM_ideal = eye(quad_no)/2; | ||
655 | sig_CM_ideal = 3*2*shot_CM_ideal + 0.1*ones(quad_no); | ||
656 | [shot_ideal, sig_ideal] = get_uncorr_rand_nums_from_sample_covs(... | ||
657 | sample_no, shot_CM_ideal, sig_CM_ideal); | ||
658 | |||
659 | %% check: correct CMs? | ||
660 | assertElementsAlmostEqual(cov(shot_ideal), shot_CM_ideal,... | ||
661 | [prefix, 'CM for fake ideal shotnoise not as expected.']) | ||
662 | assertElementsAlmostEqual(cov(sig_ideal), sig_CM_ideal,... | ||
663 | [prefix, 'CM for fake ideal signal not as expected.']) | ||
664 | |||
665 | %% check: shotnoise and signal uncorrelated? | ||
666 | assertElementsAlmostEqual(corr(shot_ideal, sig_ideal), zeros(quad_no),... | ||
667 | [prefix, 'Correlations between fake signal and shotnoise not as expected.']) | ||
668 | |||
669 | % disp([10, 10, '***************',10, prefix, 'fake ideal data as expected!',10]) | ||
670 | |||
671 | %% convert to fake measured data | ||
672 | shot_measured = sqrt(eta)*shot_ideal; | ||
673 | sig_measured = eta*nu*sig_ideal + sqrt(eta*(1 - eta*(nu^2)))*shot_ideal; | ||
674 | |||
675 | shot_measured = amp*shot_measured; | ||
676 | sig_measured = amp*sig_measured; | ||
677 | |||
678 | %% check that fake measured data satisfies expected relations | ||
679 | tolerance = 1E-2; | ||
680 | CM_shot_expected = (amp^2)*eta*shot_CM_ideal; | ||
681 | % reldiff (CM_shot_expected, cov(shot_measured)) | ||
682 | assertElementsAlmostEqual(cov(shot_measured), CM_shot_expected, 'absolute', tolerance,... | ||
683 | [prefix, 'CM for fake measured shotnoise not as expected!']) | ||
684 | |||
685 | CM_sig_expected = (amp^2)*((eta^2)*(nu^2)*sig_CM_ideal + eta*(1 - eta*(nu^2))*shot_CM_ideal); | ||
686 | assertElementsAlmostEqual(cov(sig_measured), CM_sig_expected, 'absolute', tolerance,... | ||
687 | [prefix, 'CM for fake measured signal not as expected!']) | ||
688 | |||
689 | % disp([10, 10, '***************',10, prefix, 'fake measurement data as expected!',10]) | ||
690 | |||
691 | %% evaluate fake data | ||
692 | ev.homodyne_visibility = nu; | ||
693 | ev.detection_efficiency = eta; | ||
694 | |||
695 | ev.pulse_trace{1}{1} = shot_measured; | ||
696 | ev.pulse_trace{2}{1} = sig_measured; | ||
697 | |||
698 | ev.calculatePulsedCMs; | ||
699 | assertEqual(cov(shot_measured), ev.pulse_CM{1}{1}) | ||
700 | assertEqual(cov(sig_measured), ev.pulse_CM{2}{1}) | ||
701 | ev.calibratePulsedCMs('shotnoise_ind', 1); | ||
702 | |||
703 | % expect to recover specified sample CMs | ||
704 | tolerance = 1E-2; | ||
705 | assertElementsAlmostEqual(ev.pulse_CM_calibrated{1}{1}, shot_CM_ideal, 'absolute', tolerance,... | ||
706 | [prefix, 'Efficiency- and visibility-corrected CM for shotnoise not as expected!']); | ||
707 | assertElementsAlmostEqual(ev.pulse_CM_calibrated{2}{1}, sig_CM_ideal, 'absolute', tolerance,... | ||
708 | [prefix, 'Efficiency- and visibility-corrected CM for signal not as expected!']); | ||
709 | % disp([10, 10, '***************',10, prefix, 'correction performed as expected!',10]) | ||
710 | 710 | ||
711 | 711 | function traceout_test(shared) | function traceout_test(shared) |
712 | ev = run_quicker_test(shared); | ||
713 | % ev.mech_frequencies = [1.2, 2.3, 4.1,5.7]; | ||
712 | ev = run_quicker_test(shared); | ||
713 | % ev.mech_frequencies = [1.2, 2.3, 4.1,5.7]; | ||
714 | 714 | ||
715 | %% check: an error is thrown if modes to trace out are not legit | ||
716 | modes_to_trace = [2,3,5]; | ||
717 | test_call = @()ev.trace_out(modes_to_trace); | ||
718 | assertExceptionThrown(test_call,... | ||
719 | 'entanglement_evaluation:trace_out:modes_illegit') | ||
715 | %% check: an error is thrown if modes to trace out are not legit | ||
716 | modes_to_trace = [2,3,5]; | ||
717 | test_call = @()ev.trace_out(modes_to_trace); | ||
718 | assertExceptionThrown(test_call,... | ||
719 | 'entanglement_evaluation:trace_out:modes_illegit') | ||
720 | 720 | ||
721 | %% now the actual tests | ||
722 | modes_to_trace = [1,3]; | ||
723 | ev_traced = ev.trace_out(modes_to_trace); | ||
724 | mech_frequencies_old = ev.mech_frequencies; | ||
721 | %% now the actual tests | ||
722 | modes_to_trace = [1,3]; | ||
723 | ev_traced = ev.trace_out(modes_to_trace); | ||
724 | mech_frequencies_old = ev.mech_frequencies; | ||
725 | 725 | ||
726 | assertEqual(ev_traced.mech_frequencies_no,... | ||
727 | length(mech_frequencies_old)-length(modes_to_trace),... | ||
728 | 'traced out evaluation does not have expected number of mechanical modes') | ||
729 | |||
730 | assertEqual(ev_traced.mech_frequencies,[2.3,5.7],... | ||
731 | 'traced out evaluation does not have expected mechanical modes') | ||
726 | assertEqual(ev_traced.mech_frequencies_no,... | ||
727 | length(mech_frequencies_old)-length(modes_to_trace),... | ||
728 | 'traced out evaluation does not have expected number of mechanical modes') | ||
732 | 729 | ||
733 | assertEqual(size(ev_traced.pulse_trace{2}{2}),... | ||
734 | [size(ev.pulse_trace{2}{2},1), 4*ev_traced.mech_frequencies_no],... | ||
735 | 'pulsed traces of traced out evaluation does not have the expected form') | ||
730 | assertEqual(ev_traced.mech_frequencies,[2.3,5.7],... | ||
731 | 'traced out evaluation does not have expected mechanical modes') | ||
736 | 732 | ||
737 | assertEqual(size(ev_traced.pulse_CM_calibrated{2}{2}),... | ||
738 | 4*ev_traced.mech_frequencies_no*[1,1],... | ||
739 | 'calibrated CMs of the traced out evaluation do not have the expected form') | ||
733 | assertEqual(size(ev_traced.pulse_trace{2}{2}),... | ||
734 | [size(ev.pulse_trace{2}{2},1), 4*ev_traced.mech_frequencies_no],... | ||
735 | 'pulsed traces of traced out evaluation does not have the expected form') | ||
740 | 736 | ||
741 | assert(~isequal(... | ||
742 | [ev_traced.logneg_corrected{2}{:}],... | ||
743 | [ev.logneg_corrected{2}{:}]),... | ||
744 | 'log.neg. values should have changed due to the tracing out but they have not') | ||
737 | assertEqual(size(ev_traced.pulse_CM_calibrated{2}{2}),... | ||
738 | 4*ev_traced.mech_frequencies_no*[1,1],... | ||
739 | 'calibrated CMs of the traced out evaluation do not have the expected form') | ||
745 | 740 | ||
741 | assert(~isequal(... | ||
742 | [ev_traced.logneg_corrected{2}{:}],... | ||
743 | [ev.logneg_corrected{2}{:}]),... | ||
744 | 'log.neg. values should have changed due to the tracing out but they have not') | ||
746 | 745 | ||
747 | % %% test different edge cases regarding the modes to trace out | ||
748 | % disp('light_quad_inds_new expected to be [1, 2, 9, 10]') | ||
749 | % ev_traced = ev.trace_out([2:4]); | ||
750 | |||
751 | % disp('light_quad_inds_new expected to be [3, 4, 5, 6, 7, 8, 11, 12, 13, 14, 15, 16]') | ||
752 | 746 | ||
753 | % ev_traced = ev.trace_out([1]); | ||
747 | % %% test different edge cases regarding the modes to trace out | ||
748 | % disp('light_quad_inds_new expected to be [1, 2, 9, 10]') | ||
749 | % ev_traced = ev.trace_out([2:4]); | ||
750 | |||
751 | % disp('light_quad_inds_new expected to be [3, 4, 5, 6, 7, 8, 11, 12, 13, 14, 15, 16]') | ||
752 | |||
753 | % ev_traced = ev.trace_out([1]); | ||
754 | 754 | ||
755 | 755 | ||
756 | 756 | %%% OTHER AUX FUNCTIONS %%% | %%% OTHER AUX FUNCTIONS %%% |
757 | 757 | function data = get_rand_nums_from_sample_cov(sample_no, sample_CM) | function data = get_rand_nums_from_sample_cov(sample_no, sample_CM) |
758 | dim = size(sample_CM,1); | ||
759 | assertEqual(dim, size(sample_CM,2)); | ||
760 | % see https://stats.stackexchange.com/questions/120179/generating-data-with-a-given-sample-covariance-matrix | ||
761 | data = randn(sample_no, dim); | ||
762 | data = bsxfun(@minus, data, mean(data)); % ensure zero mean | ||
763 | data = data * inv(chol(cov(data))); % remove existing correlations and standardize | ||
764 | data = data * chol(sample_CM); % transform to match given sample CM | ||
758 | dim = size(sample_CM,1); | ||
759 | assertEqual(dim, size(sample_CM,2)); | ||
760 | % see https://stats.stackexchange.com/questions/120179/generating-data-with-a-given-sample-covariance-matrix | ||
761 | data = randn(sample_no, dim); | ||
762 | data = bsxfun(@minus, data, mean(data)); % ensure zero mean | ||
763 | data = data * inv(chol(cov(data))); % remove existing correlations and standardize | ||
764 | data = data * chol(sample_CM); % transform to match given sample CM | ||
765 | 765 | ||
766 | 766 | function [data1, data2] = get_uncorr_rand_nums_from_sample_covs(sample_no, sampleCM1, sampleCM2) | function [data1, data2] = get_uncorr_rand_nums_from_sample_covs(sample_no, sampleCM1, sampleCM2) |
767 | dim1 = size(sampleCM1,1); | ||
768 | assertEqual(dim1, size(sampleCM1,2)); | ||
769 | |||
770 | sample_CM = blkdiag(sampleCM1, sampleCM2); | ||
771 | data = get_rand_nums_from_sample_cov(sample_no, sample_CM); | ||
767 | dim1 = size(sampleCM1,1); | ||
768 | assertEqual(dim1, size(sampleCM1,2)); | ||
769 | |||
770 | sample_CM = blkdiag(sampleCM1, sampleCM2); | ||
771 | data = get_rand_nums_from_sample_cov(sample_no, sample_CM); | ||
772 | 772 | ||
773 | data1 = data(:,1:dim1); | ||
774 | data2 = data(:,dim1+1:end); | ||
773 | data1 = data(:,1:dim1); | ||
774 | data2 = data(:,dim1+1:end); | ||
775 | 775 | ||
776 | 776 | function reldiff_mat = reldiff(mat1, mat2) % can be useful for spotting mistakes | function reldiff_mat = reldiff(mat1, mat2) % can be useful for spotting mistakes |
777 | reldiff_mat = (mat1-mat2)./(abs(mat1)+abs(mat2)); | ||
777 | reldiff_mat = (mat1-mat2)./(abs(mat1)+abs(mat2)); | ||
778 | 778 | ||
779 | 779 | ||
780 | 780 | function relsign = assertRowsAlmostEqualUptoSign(mat1, mat2, varargin) | function relsign = assertRowsAlmostEqualUptoSign(mat1, mat2, varargin) |
781 | assertEqual(size(mat1), size(mat2)) | ||
782 | rows_no = size(mat2,1); | ||
783 | relsign = zeros(1,rows_no); | ||
784 | for row_no=1:rows_no | ||
785 | relsign(row_no) = sign(real(mat1(row_no,1)))*sign(real(mat2(row_no,1))); | ||
786 | end | ||
787 | assertElementsAlmostEqual(mat1, diag(relsign)*mat2,varargin{:}) | ||
781 | assertEqual(size(mat1), size(mat2)) | ||
782 | rows_no = size(mat2,1); | ||
783 | relsign = zeros(1,rows_no); | ||
784 | for row_no=1:rows_no | ||
785 | relsign(row_no) = sign(real(mat1(row_no,1)))*sign(real(mat2(row_no,1))); | ||
786 | end | ||
787 | assertElementsAlmostEqual(mat1, diag(relsign)*mat2,varargin{:}) | ||
788 | 788 | ||
789 | 789 | function relsign = assertColsAlmostEqualUptoSign(mat1, mat2, varargin) | function relsign = assertColsAlmostEqualUptoSign(mat1, mat2, varargin) |
790 | assertEqual(size(mat1), size(mat2)) | ||
791 | cols_no = size(mat2,2); | ||
792 | relsign = zeros(1,cols_no); | ||
793 | for col_no=1:cols_no | ||
794 | relsign(col_no) = sign(real(mat1(1,col_no)))*sign(real(mat2(1,col_no))); | ||
795 | end | ||
796 | assertElementsAlmostEqual(mat1, mat2*diag(relsign),varargin{:}) | ||
790 | assertEqual(size(mat1), size(mat2)) | ||
791 | cols_no = size(mat2,2); | ||
792 | relsign = zeros(1,cols_no); | ||
793 | for col_no=1:cols_no | ||
794 | relsign(col_no) = sign(real(mat1(1,col_no)))*sign(real(mat2(1,col_no))); | ||
795 | end | ||
796 | assertElementsAlmostEqual(mat1, mat2*diag(relsign),varargin{:}) | ||
797 | 797 | ||
798 | 798 | function relsign = assertCMsEqualUptoSign(mat1,mat2, varargin) | function relsign = assertCMsEqualUptoSign(mat1,mat2, varargin) |
799 | assertEqual(size(mat1), size(mat2)) | ||
800 | cols_no = size(mat2,2); | ||
801 | relsign = zeros(1,cols_no); | ||
802 | for col_no=1:cols_no | ||
803 | relsign(col_no) = sign(real(mat1(1,col_no)))*sign(real(mat2(1,col_no))); | ||
804 | end | ||
805 | assertElementsAlmostEqual(mat1, diag(relsign)*mat2*diag(relsign),varargin{:}) | ||
799 | assertEqual(size(mat1), size(mat2)) | ||
800 | cols_no = size(mat2,2); | ||
801 | relsign = zeros(1,cols_no); | ||
802 | for col_no=1:cols_no | ||
803 | relsign(col_no) = sign(real(mat1(1,col_no)))*sign(real(mat2(1,col_no))); | ||
804 | end | ||
805 | assertElementsAlmostEqual(mat1, diag(relsign)*mat2*diag(relsign),varargin{:}) |
File data_analysis/unittests/homo_measurement_test.m changed (mode: 100644) (index 7d788da..54187e1) | |||
1 | 1 | function test_suite = homo_measurement_test %#ok<STOUT> | function test_suite = homo_measurement_test %#ok<STOUT> |
2 | localFunctionHandles = cellfun(@str2func,... | ||
3 | which('-subfun', mfilename('fullpath')), 'UniformOutput', false); | ||
4 | test_suite = buildFunctionHandleTestSuite(localFunctionHandles); | ||
2 | localFunctionHandles = cellfun(@str2func,... | ||
3 | which('-subfun', mfilename('fullpath')), 'UniformOutput', false); | ||
4 | test_suite = buildFunctionHandleTestSuite(localFunctionHandles); | ||
5 | 5 | ||
6 | 6 | function shared = setup | function shared = setup |
7 | shared.evaluation_folder = tempname; | ||
8 | assert(~(exist(shared.evaluation_folder)==7),... | ||
9 | [shared.evaluation_folder, ' exists already.']); | ||
10 | mkdir(shared.evaluation_folder) | ||
7 | shared.evaluation_folder = tempname; | ||
8 | assert(~(exist(shared.evaluation_folder)==7),... | ||
9 | [shared.evaluation_folder, ' exists already.']); | ||
10 | mkdir(shared.evaluation_folder) | ||
11 | 11 | ||
12 | shared.samplingrate = 100; | ||
13 | shared.sampleno = 1e4; | ||
12 | shared.samplingrate = 100; | ||
13 | shared.sampleno = 1e4; | ||
14 | 14 | ||
15 | shared.mech_freqs = [1, 1.345]; | ||
16 | shared.timevec = (0:shared.sampleno-1)'/shared.samplingrate; | ||
15 | shared.mech_freqs = [1, 1.345]; | ||
16 | shared.timevec = (0:shared.sampleno-1)'/shared.samplingrate; | ||
17 | 17 | ||
18 | shared.x.data = sin(2*pi*shared.mech_freqs(1)*shared.timevec) + sin(2*pi*shared.mech_freqs(2)*shared.timevec); | ||
19 | shared.p.data = cos(2*pi*shared.mech_freqs(1)*shared.timevec) + cos(2*pi*shared.mech_freqs(1)*shared.timevec); | ||
18 | shared.x.data = sin(2*pi*shared.mech_freqs(1)*shared.timevec) + sin(2*pi*shared.mech_freqs(2)*shared.timevec); | ||
19 | shared.p.data = cos(2*pi*shared.mech_freqs(1)*shared.timevec) + cos(2*pi*shared.mech_freqs(1)*shared.timevec); | ||
20 | 20 | ||
21 | shared.precision = 'double'; | ||
21 | shared.precision = 'double'; | ||
22 | 22 | ||
23 | shared.x.file = fullfile(shared.evaluation_folder, '.x.dat'); | ||
24 | shared.p.file = fullfile(shared.evaluation_folder, '.p.dat'); | ||
23 | shared.x.file = fullfile(shared.evaluation_folder, '.x.dat'); | ||
24 | shared.p.file = fullfile(shared.evaluation_folder, '.p.dat'); | ||
25 | 25 | ||
26 | for mytrace = {shared.x, shared.p} | ||
27 | mytrace = mytrace{:}; | ||
28 | fid = fopen(mytrace.file,'w'); | ||
29 | fwrite(fid, mytrace.data, shared.precision); | ||
30 | fclose(fid); | ||
31 | end | ||
26 | for mytrace = {shared.x, shared.p} | ||
27 | mytrace = mytrace{:}; | ||
28 | fid = fopen(mytrace.file,'w'); | ||
29 | fwrite(fid, mytrace.data, shared.precision); | ||
30 | fclose(fid); | ||
31 | end | ||
32 | 32 | ||
33 | 33 | function teardown(shared) | function teardown(shared) |
34 | for mytrace = {shared.x, shared.p} | ||
35 | mytrace = mytrace{:}; | ||
36 | delete(mytrace.file); | ||
37 | end | ||
38 | rmdir(shared.evaluation_folder, 's'); | ||
39 | clear('shared'); | ||
34 | for mytrace = {shared.x, shared.p} | ||
35 | mytrace = mytrace{:}; | ||
36 | delete(mytrace.file); | ||
37 | end | ||
38 | rmdir(shared.evaluation_folder, 's'); | ||
39 | clear('shared'); | ||
40 | 40 | ||
41 | 41 | function meas = dhm_setup_test(shared) | function meas = dhm_setup_test(shared) |
42 | meas = dual_homo_measurement('samplingrate', shared.samplingrate); | ||
43 | meas.add_trace_pair(... | ||
44 | shared.x.file,... | ||
45 | shared.p.file,... | ||
46 | 'precision',shared.precision,... | ||
47 | 'DAQrange', 0,... | ||
48 | 'amplification', 1,... | ||
49 | 'signal_power_muW', 0); | ||
50 | meas.add_trace_pair(... | ||
51 | shared.x.file,... | ||
52 | shared.p.file,... | ||
53 | 'precision',shared.precision,... | ||
54 | 'DAQrange', 0,... | ||
55 | 'amplification', 1,... | ||
56 | 'signal_power_muW', 100); | ||
42 | meas = dual_homo_measurement('samplingrate', shared.samplingrate); | ||
43 | meas.add_trace_pair(... | ||
44 | shared.x.file,... | ||
45 | shared.p.file,... | ||
46 | 'precision',shared.precision,... | ||
47 | 'DAQrange', 0,... | ||
48 | 'amplification', 1,... | ||
49 | 'signal_power_muW', 0); | ||
50 | meas.add_trace_pair(... | ||
51 | shared.x.file,... | ||
52 | shared.p.file,... | ||
53 | 'precision',shared.precision,... | ||
54 | 'DAQrange', 0,... | ||
55 | 'amplification', 1,... | ||
56 | 'signal_power_muW', 100); | ||
57 | 57 | ||
58 | 58 | function meas = properties_test(shared) | function meas = properties_test(shared) |
59 | meas = dhm_setup_test(shared); | ||
60 | for k=1:2 | ||
61 | mytrace = meas.homotraces(1,k); | ||
62 | mytrace.fopen(); | ||
63 | if k==1 | ||
64 | data = shared.x.data; | ||
65 | elseif k==2 | ||
66 | data = shared.p.data; | ||
67 | end | ||
68 | assertEqual(data, mytrace.fread(shared.sampleno)); | ||
69 | mytrace.fclose(); | ||
70 | end | ||
71 | assertEqual(meas.samplingrate, shared.samplingrate); | ||
59 | meas = dhm_setup_test(shared); | ||
60 | for k=1:2 | ||
61 | mytrace = meas.homotraces(1,k); | ||
62 | mytrace.fopen(); | ||
63 | if k==1 | ||
64 | data = shared.x.data; | ||
65 | elseif k==2 | ||
66 | data = shared.p.data; | ||
67 | end | ||
68 | assertEqual(data, mytrace.fread(shared.sampleno)); | ||
69 | mytrace.fclose(); | ||
70 | end | ||
71 | assertEqual(meas.samplingrate, shared.samplingrate); | ||
72 | 72 | ||
73 | 73 | function meas = dummy_test(shared) | function meas = dummy_test(shared) |
74 | meas = dual_homo_measurement('samplingrate', 10, 'dummy', true); | ||
74 | meas = dual_homo_measurement('samplingrate', 10, 'dummy', true); | ||
75 | 75 | assertEqual(meas.dummy, true) | assertEqual(meas.dummy, true) |
76 | add_trace_pair_test = @()meas.add_trace_pair(... | ||
77 | shared.x.file,... | ||
78 | shared.p.file,... | ||
79 | 'precision',shared.precision,... | ||
80 | 'DAQrange', 0,... | ||
81 | 'amplification', 1,... | ||
82 | 'signal_power_muW', 0); | ||
83 | assertExceptionThrown(add_trace_pair_test, 'PXItrace:FileExists') | ||
84 | |||
85 | meas = dual_homo_measurement('samplingrate', 10, 'dummy', true); | ||
86 | meas.add_trace_pair(... | ||
87 | '.x_dummy.dat',... | ||
88 | '.p_dummy.dat',... | ||
89 | 'precision',shared.precision,... | ||
90 | 'DAQrange', 0,... | ||
91 | 'amplification', 1,... | ||
92 | 'signal_power_muW', 0); | ||
76 | add_trace_pair_test = @()meas.add_trace_pair(... | ||
77 | shared.x.file,... | ||
78 | shared.p.file,... | ||
79 | 'precision',shared.precision,... | ||
80 | 'DAQrange', 0,... | ||
81 | 'amplification', 1,... | ||
82 | 'signal_power_muW', 0); | ||
83 | assertExceptionThrown(add_trace_pair_test, 'PXItrace:FileExists') | ||
84 | |||
85 | meas = dual_homo_measurement('samplingrate', 10, 'dummy', true); | ||
86 | meas.add_trace_pair(... | ||
87 | '.x_dummy.dat',... | ||
88 | '.p_dummy.dat',... | ||
89 | 'precision',shared.precision,... | ||
90 | 'DAQrange', 0,... | ||
91 | 'amplification', 1,... | ||
92 | 'signal_power_muW', 0); | ||
93 | 93 | assertEqual(all([meas.homotraces.dummy]), true) | assertEqual(all([meas.homotraces.dummy]), true) |
94 | % dummy-files are automatically deleted upon destruction of the corresponding PXItrace-object | ||
94 | % dummy-files are automatically deleted upon destruction of the corresponding PXItrace-object |
File data_analysis/unittests/homotrace_test.m changed (mode: 100644) (index 2c294e2..f09843e) | |||
1 | 1 | function test_suite = homotrace_test %#ok<STOUT> | function test_suite = homotrace_test %#ok<STOUT> |
2 | localFunctionHandles = cellfun(@str2func,... | ||
3 | which('-subfun', mfilename('fullpath')), 'UniformOutput', false); | ||
4 | test_suite = buildFunctionHandleTestSuite(localFunctionHandles); | ||
2 | localFunctionHandles = cellfun(@str2func,... | ||
3 | which('-subfun', mfilename('fullpath')), 'UniformOutput', false); | ||
4 | test_suite = buildFunctionHandleTestSuite(localFunctionHandles); | ||
5 | 5 | ||
6 | 6 | function shared = setup | function shared = setup |
7 | shared.samplingrate = 100; | ||
8 | shared.sample_no = 1e4; | ||
7 | shared.samplingrate = 100; | ||
8 | shared.sample_no = 1e4; | ||
9 | 9 | ||
10 | shared.mech_freq = 1; | ||
11 | shared.timevec = (0:shared.sample_no-1)'/shared.samplingrate; | ||
12 | shared.signal_power_muW = 10; | ||
13 | shared.quadrature = 'amplitude'; | ||
14 | shared.DAQrange = 0; | ||
15 | shared.amplification = 10; | ||
10 | shared.mech_freq = 1; | ||
11 | shared.timevec = (0:shared.sample_no-1)'/shared.samplingrate; | ||
12 | shared.signal_power_muW = 10; | ||
13 | shared.quadrature = 'amplitude'; | ||
14 | shared.DAQrange = 0; | ||
15 | shared.amplification = 10; | ||
16 | 16 | ||
17 | shared.data = sin(2*pi*shared.mech_freq*shared.timevec); | ||
18 | shared.precision = 'double'; | ||
17 | shared.data = sin(2*pi*shared.mech_freq*shared.timevec); | ||
18 | shared.precision = 'double'; | ||
19 | 19 | ||
20 | shared.folder = tempname; | ||
21 | assert(~(exist(shared.folder)==7),... | ||
22 | [shared.folder, ' exists already.']); | ||
23 | mkdir(shared.folder) | ||
24 | shared.file = fullfile(shared.folder, '.x.dat'); | ||
20 | shared.folder = tempname; | ||
21 | assert(~(exist(shared.folder)==7),... | ||
22 | [shared.folder, ' exists already.']); | ||
23 | mkdir(shared.folder) | ||
24 | shared.file = fullfile(shared.folder, '.x.dat'); | ||
25 | 25 | ||
26 | fid = fopen(shared.file,'w'); | ||
27 | fwrite(fid, shared.data, shared.precision); | ||
28 | fclose(fid); | ||
26 | fid = fopen(shared.file,'w'); | ||
27 | fwrite(fid, shared.data, shared.precision); | ||
28 | fclose(fid); | ||
29 | 29 | ||
30 | 30 | function teardown(shared) | function teardown(shared) |
31 | delete(shared.file); | ||
32 | rmdir(shared.folder); | ||
31 | delete(shared.file); | ||
32 | rmdir(shared.folder); | ||
33 | 33 | ||
34 | 34 | function ht = ht_setup_test(shared) | function ht = ht_setup_test(shared) |
35 | ht = homotrace(shared.file,... | ||
36 | 'samplingrate', shared.samplingrate,... | ||
37 | 'signal_power_muW', shared.signal_power_muW,... | ||
38 | 'quadrature', shared.quadrature,... | ||
39 | 'precision', shared.precision,... | ||
40 | 'DAQrange', shared.DAQrange,... | ||
41 | 'amplification', shared.amplification); | ||
35 | ht = homotrace(shared.file,... | ||
36 | 'samplingrate', shared.samplingrate,... | ||
37 | 'signal_power_muW', shared.signal_power_muW,... | ||
38 | 'quadrature', shared.quadrature,... | ||
39 | 'precision', shared.precision,... | ||
40 | 'DAQrange', shared.DAQrange,... | ||
41 | 'amplification', shared.amplification); | ||
42 | 42 | ||
43 | 43 | function ht = read_data_test(shared) | function ht = read_data_test(shared) |
44 | ht = ht_setup_test(shared); | ||
45 | ht.fopen(); | ||
46 | assertEqual(ht.fread(shared.sample_no), shared.data/shared.amplification); | ||
47 | ht.fclose(); | ||
44 | ht = ht_setup_test(shared); | ||
45 | ht.fopen(); | ||
46 | assertEqual(ht.fread(shared.sample_no), shared.data/shared.amplification); | ||
47 | ht.fclose(); | ||
48 | 48 | ||
49 | 49 | function ht = properties_test(shared) | function ht = properties_test(shared) |
50 | ht = ht_setup_test(shared); | ||
51 | assertEqual(ht.samplingrate, shared.samplingrate) | ||
52 | assertEqual(ht.sample_no, shared.sample_no) | ||
53 | assertEqual(ht.precision, shared.precision) | ||
54 | |||
55 | assertEqual(ht.quadrature, shared.quadrature) | ||
56 | assertEqual(ht.signal_power_muW, shared.signal_power_muW) | ||
57 | assertEqual(ht.dataset_label,... | ||
58 | [shared.quadrature, ' quad., ',... | ||
59 | num2str(shared.signal_power_muW),'muW signal.']) | ||
60 | |||
61 | assertEqual(ht.DAQrange, shared.DAQrange) | ||
62 | assertEqual(ht.amplification, shared.amplification) | ||
50 | ht = ht_setup_test(shared); | ||
51 | assertEqual(ht.samplingrate, shared.samplingrate) | ||
52 | assertEqual(ht.sample_no, shared.sample_no) | ||
53 | assertEqual(ht.precision, shared.precision) | ||
54 | |||
55 | assertEqual(ht.quadrature, shared.quadrature) | ||
56 | assertEqual(ht.signal_power_muW, shared.signal_power_muW) | ||
57 | assertEqual(ht.dataset_label,... | ||
58 | [shared.quadrature, ' quad., ',... | ||
59 | num2str(shared.signal_power_muW),'muW signal.']) | ||
60 | |||
61 | assertEqual(ht.DAQrange, shared.DAQrange) | ||
62 | assertEqual(ht.amplification, shared.amplification) |
File data_analysis/unittests/meta_ev_test.m changed (mode: 100644) (index b04401b..3861a83) | |||
1 | 1 | function test_suite = meta_ev_test %#ok<STOUT> | function test_suite = meta_ev_test %#ok<STOUT> |
2 | localFunctionHandles = cellfun(@str2func,... | ||
3 | which('-subfun', mfilename('fullpath')), 'UniformOutput', false); | ||
4 | test_suite = buildFunctionHandleTestSuite(localFunctionHandles); | ||
2 | localFunctionHandles = cellfun(@str2func,... | ||
3 | which('-subfun', mfilename('fullpath')), 'UniformOutput', false); | ||
4 | test_suite = buildFunctionHandleTestSuite(localFunctionHandles); | ||
5 | 5 | ||
6 | 6 | function shared = setup | function shared = setup |
7 | % shared.evaluation_folder = tempname; | ||
8 | % assert(~(exist(shared.evaluation_folder)==7),... | ||
9 | % [shared.evaluation_folder, ' exists already.']); | ||
10 | % mkdir(shared.evaluation_folder) | ||
11 | test_dir = fileparts(mfilename('fullpath')); | ||
12 | get_meta_data_file = @(ind)fullfile(test_dir, 'test_meta_ev/',['metadata', num2str(ind),'.tsv.test']); | ||
13 | shared.meta_data_files = arrayfun(get_meta_data_file, 1:5, 'UniformOutput', false); | ||
7 | % shared.evaluation_folder = tempname; | ||
8 | % assert(~(exist(shared.evaluation_folder)==7),... | ||
9 | % [shared.evaluation_folder, ' exists already.']); | ||
10 | % mkdir(shared.evaluation_folder) | ||
11 | test_dir = fileparts(mfilename('fullpath')); | ||
12 | get_meta_data_file = @(ind)fullfile(test_dir, 'test_meta_ev/',['metadata', num2str(ind),'.tsv.test']); | ||
13 | shared.meta_data_files = arrayfun(get_meta_data_file, 1:5, 'UniformOutput', false); | ||
14 | 14 | ||
15 | 15 | function teardown(shared) | function teardown(shared) |
16 | % rmdir(shared.evaluation_folder, 's'); | ||
17 | clear('shared'); | ||
16 | % rmdir(shared.evaluation_folder, 's'); | ||
17 | clear('shared'); | ||
18 | 18 | ||
19 | 19 | function get_meta_data1_test(shared) | function get_meta_data1_test(shared) |
20 | meta = meta_ev(); | ||
21 | meta.get_meta_data(shared.meta_data_files{1}); | ||
20 | meta = meta_ev(); | ||
21 | meta.get_meta_data(shared.meta_data_files{1}); | ||
22 | 22 | ||
23 | 23 | function get_meta_data2_test(shared) | function get_meta_data2_test(shared) |
24 | meta = meta_ev(); | ||
25 | meta.get_meta_data(shared.meta_data_files{2}); | ||
24 | meta = meta_ev(); | ||
25 | meta.get_meta_data(shared.meta_data_files{2}); | ||
26 | 26 | ||
27 | 27 | function get_meta_data3_test(shared) | function get_meta_data3_test(shared) |
28 | meta = meta_ev(); | ||
29 | meta.get_meta_data(shared.meta_data_files{3}); | ||
28 | meta = meta_ev(); | ||
29 | meta.get_meta_data(shared.meta_data_files{3}); | ||
30 | 30 | ||
31 | 31 | function get_meta_data4_test(shared) | function get_meta_data4_test(shared) |
32 | meta = meta_ev(); | ||
33 | meta.get_meta_data(shared.meta_data_files{4}); | ||
32 | meta = meta_ev(); | ||
33 | meta.get_meta_data(shared.meta_data_files{4}); | ||
34 | 34 | ||
35 | 35 | function get_meta_data5_test(shared) | function get_meta_data5_test(shared) |
36 | meta = meta_ev(); | ||
37 | load_error_test = @() meta.get_meta_data(shared.meta_data_files{5}); | ||
38 | assertExceptionThrown(load_error_test, 'meta_ev:get_meta_data:empty_params') | ||
36 | meta = meta_ev(); | ||
37 | load_error_test = @() meta.get_meta_data(shared.meta_data_files{5}); | ||
38 | assertExceptionThrown(load_error_test, 'meta_ev:get_meta_data:empty_params') | ||
39 | 39 | ||
40 | 40 | function load_meta1_test(shared) | function load_meta1_test(shared) |
41 | meta = meta_ev(shared.meta_data_files{1}); | ||
41 | meta = meta_ev(shared.meta_data_files{1}); | ||
42 | 42 | ||
43 | 43 | function load_meta2_test(shared) | function load_meta2_test(shared) |
44 | meta = meta_ev(shared.meta_data_files{2}); | ||
44 | meta = meta_ev(shared.meta_data_files{2}); | ||
45 | 45 | ||
46 | 46 | function load_meta3_test(shared) | function load_meta3_test(shared) |
47 | unsupported_dims_test = @()meta_ev(shared.meta_data_files{3}); | ||
48 | assertExceptionThrown(unsupported_dims_test, 'meta_ev:gridtype:unsupported') | ||
47 | unsupported_dims_test = @()meta_ev(shared.meta_data_files{3}); | ||
48 | assertExceptionThrown(unsupported_dims_test, 'meta_ev:gridtype:unsupported') | ||
49 | 49 | ||
50 | 50 | function load_meta4_test(shared) | function load_meta4_test(shared) |
51 | meta = meta_ev(shared.meta_data_files{4}); | ||
51 | meta = meta_ev(shared.meta_data_files{4}); | ||
52 | 52 | ||
53 | 53 | function load_meta5_test(shared) | function load_meta5_test(shared) |
54 | load_error_test = @() meta_ev(shared.meta_data_files{5}); | ||
55 | assertExceptionThrown(load_error_test, 'meta_ev:get_meta_data:empty_params') | ||
54 | load_error_test = @() meta_ev(shared.meta_data_files{5}); | ||
55 | assertExceptionThrown(load_error_test, 'meta_ev:get_meta_data:empty_params') | ||
56 | 56 | ||
57 | 57 | function cut_plot_test(shared) | function cut_plot_test(shared) |
58 | fig = figure; set(fig,'visible','off') | ||
59 | meta = meta_ev(shared.meta_data_files{1}); | ||
60 | meta.meta_label = 'test'; | ||
61 | param_ind = 2; | ||
62 | % meta.plot_cuts('logneg', 2, param_ind, unique(meta.params{param_ind})); | ||
63 | [T] = evalc(... | ||
64 | 'meta.plot_cuts(''logneg'',2, param_ind, [2.5,10,50], ''x_scale'',''log'', ''fig'', fig);'); | ||
65 | [T] = evalc('meta.save_figs;'); | ||
66 | % meta.plot_cuts('logneg', 2, param_ind, 'all'); | ||
67 | % try | ||
68 | % system(['ls ', meta.common_path]); | ||
69 | % end | ||
70 | % try | ||
71 | % system(['mupdf ' fullfile(meta.common_path,'lnopt_cut__test.pdf')]); | ||
72 | % end | ||
58 | fig = figure; set(fig,'visible','off') | ||
59 | meta = meta_ev(shared.meta_data_files{1}); | ||
60 | meta.meta_label = 'test'; | ||
61 | param_ind = 2; | ||
62 | % meta.plot_cuts('logneg', 2, param_ind, unique(meta.params{param_ind})); | ||
63 | [T] = evalc(... | ||
64 | 'meta.plot_cuts(''logneg'',2, param_ind, [2.5,10,50], ''x_scale'',''log'', ''fig'', fig);'); | ||
65 | [T] = evalc('meta.save_figs;'); | ||
66 | % meta.plot_cuts('logneg', 2, param_ind, 'all'); | ||
67 | % try | ||
68 | % system(['ls ', meta.common_path]); | ||
69 | % end | ||
70 | % try | ||
71 | % system(['mupdf ' fullfile(meta.common_path,'lnopt_cut__test.pdf')]); | ||
72 | % end | ||
73 | 73 | ||
74 | 74 | function contour_plot_test(shared) | function contour_plot_test(shared) |
75 | fig = figure; set(fig,'visible','off') | ||
76 | meta = meta_ev(shared.meta_data_files{1}); | ||
77 | meta.meta_label = 'test'; | ||
78 | [T] = evalc(... | ||
79 | 'meta.contour_plot(''logneg'',2, ''x_scale'',''log'', ''fig'', fig);'); | ||
80 | [T] = evalc('meta.save_figs;'); | ||
81 | % try | ||
82 | % system(['ls ', meta.common_path]); | ||
83 | % end | ||
84 | % try | ||
85 | % system(['mupdf ', fullfile(meta.common_path, 'lnopt__test.pdf')]); | ||
86 | % end | ||
75 | fig = figure; set(fig,'visible','off') | ||
76 | meta = meta_ev(shared.meta_data_files{1}); | ||
77 | meta.meta_label = 'test'; | ||
78 | [T] = evalc(... | ||
79 | 'meta.contour_plot(''logneg'',2, ''x_scale'',''log'', ''fig'', fig);'); | ||
80 | [T] = evalc('meta.save_figs;'); | ||
81 | % try | ||
82 | % system(['ls ', meta.common_path]); | ||
83 | % end | ||
84 | % try | ||
85 | % system(['mupdf ', fullfile(meta.common_path, 'lnopt__test.pdf')]); | ||
86 | % end | ||
87 | 87 | ||
88 | 88 | function plot_logneg_versus_gamma_test(shared) | function plot_logneg_versus_gamma_test(shared) |
89 | fig = figure; set(fig,'visible','off') | ||
90 | meta = meta_ev(shared.meta_data_files{1}); | ||
91 | meta.meta_label = 'test'; | ||
92 | meta = meta.filter_params(1, [5E5,5E7]); | ||
93 | cmap = [cbrewer('seq','RdPu',9);... | ||
94 | cbrewer('seq','GnBu',9)]; | ||
95 | [T] = evalc(... | ||
96 | 'meta.plot_logneg_versus_gamma(2, ''colors'', cmap, ''x_scale'',''log'',''y_lims'', [-1,0.5],''fig'', fig);'); | ||
97 | [T] = evalc('meta.save_figs;'); | ||
98 | % try | ||
99 | % system(['ls ', meta.common_path]); | ||
100 | % end | ||
101 | % try | ||
102 | % system(['mupdf ', fullfile(meta.common_path, 'ln_versus_gamma__test.pdf')]); | ||
103 | % end | ||
89 | fig = figure; set(fig,'visible','off') | ||
90 | meta = meta_ev(shared.meta_data_files{1}); | ||
91 | meta.meta_label = 'test'; | ||
92 | meta = meta.filter_params(1, [5E5,5E7]); | ||
93 | cmap = [cbrewer('seq','RdPu',9);... | ||
94 | cbrewer('seq','GnBu',9)]; | ||
95 | [T] = evalc(... | ||
96 | 'meta.plot_logneg_versus_gamma(2, ''colors'', cmap, ''x_scale'',''log'',''y_lims'', [-1,0.5],''fig'', fig);'); | ||
97 | [T] = evalc('meta.save_figs;'); | ||
98 | % try | ||
99 | % system(['ls ', meta.common_path]); | ||
100 | % end | ||
101 | % try | ||
102 | % system(['mupdf ', fullfile(meta.common_path, 'ln_versus_gamma__test.pdf')]); | ||
103 | % end | ||
104 | 104 | ||
105 | 105 | ||
106 | 106 | function filter_params_test(shared) | function filter_params_test(shared) |
107 | meta = meta_ev(shared.meta_data_files{1}); | ||
108 | meta.load_models; | ||
109 | |||
110 | %% if only one parameter is selected expect ... | ||
111 | param_ind = 1; | ||
112 | target = meta.params{param_ind}(1,1); | ||
113 | meta_filtered = meta.filter_params(param_ind, target); | ||
114 | % ... new dimensions 1xN | ||
115 | assertEqual(meta_filtered.dimensions(2),1,... | ||
116 | 'expected single entry for parameter 1') | ||
117 | assertEqual(meta_filtered.dimensions(1),meta.dimensions(1),... | ||
118 | 'expected unchanged dimensions of parameter 2') | ||
119 | % ... one-dim. evaluation | ||
120 | assertEqual(meta_filtered.gridtype, 'vector',... | ||
121 | 'expected gridtype "vector"') | ||
122 | % ... only selected param survives | ||
123 | assertEqual(unique(meta_filtered.params{1}), target,... | ||
124 | 'expected only value of parameter 1 equal to input') | ||
125 | % ... along other dimension all params survive | ||
126 | assertEqual(unique(meta_filtered.params{2}),... | ||
127 | unique(meta.params{2}),... | ||
128 | 'expected values of parameter 2 to remain unchanged') | ||
129 | % ... old evaluation to remain unchanged | ||
130 | meta2 = meta_ev(shared.meta_data_files{1}); | ||
131 | meta2.load_models; | ||
132 | assertEqual(meta, meta2); | ||
133 | % assert(isequal(meta, meta2)) | ||
134 | meta2.ev_files{1,1} = 'somechangedpath'; | ||
135 | assert(~isequal(meta, meta2)); | ||
136 | |||
137 | %% if only one parameter is selected INEXACTLY expect ... | ||
138 | param_ind = 1; | ||
139 | target = meta.params{param_ind}(1,1) + 1; | ||
140 | meta_filtered = meta.filter_params(param_ind, target); | ||
141 | % ... new dimensions 1xN | ||
142 | assertEqual(meta_filtered.dimensions(2),1,... | ||
143 | 'expected single entry for parameter 1') | ||
144 | assertEqual(meta_filtered.dimensions(1),meta.dimensions(1),... | ||
145 | 'expected unchanged dimensions of parameter 2') | ||
146 | % ... one-dim. evaluation | ||
147 | assertEqual(meta_filtered.gridtype, 'vector',... | ||
148 | 'expected gridtype "vector"') | ||
149 | % ... only selected param survives | ||
150 | assertEqual(unique(meta_filtered.params{1}), target -1,... | ||
151 | 'expected only value of parameter 1 almost equal to input') | ||
152 | % ... along other dimension all params survive | ||
153 | assertEqual(unique(meta_filtered.params{2}),... | ||
154 | unique(meta.params{2}),... | ||
155 | 'expected values of parameter 2 to remain unchanged') | ||
156 | % ... old evaluation to remain unchanged | ||
157 | meta2 = meta_ev(shared.meta_data_files{1}); | ||
158 | meta2.load_models; | ||
159 | assertEqual(meta, meta2); | ||
160 | % assert(isequal(meta, meta2)) | ||
161 | meta2.ev_files{1,1} = 'somechangedpath'; | ||
162 | assert(~isequal(meta, meta2)); | ||
163 | |||
164 | %% if two parameter are selected INEXACTLY expect ... | ||
165 | param_ind = 1; | ||
166 | target = meta.params{param_ind}(1,[1,4]) + 1; | ||
167 | meta_filtered = meta.filter_params(param_ind, target); | ||
168 | % ... new dimensions 2xN | ||
169 | assertEqual(meta_filtered.dimensions(2),2,... | ||
170 | 'expected two entries for parameter 1') | ||
171 | assertEqual(meta_filtered.dimensions(1),meta.dimensions(1),... | ||
172 | 'expected unchanged dimensions of parameter 2') | ||
173 | % ... one-dim. evaluation | ||
174 | assertEqual(meta_filtered.gridtype, 'matrix',... | ||
175 | 'expected gridtype "matrix"') | ||
176 | % ... only selected param survives | ||
177 | assertEqual(unique(meta_filtered.params{1})', target -1,... | ||
178 | 'expected two values of parameter 1 almost equal to input') | ||
179 | % ... along other dimension all params survive | ||
180 | assertEqual(unique(meta_filtered.params{2}),... | ||
181 | unique(meta.params{2}),... | ||
182 | 'expected values of parameter 2 to remain unchanged') | ||
183 | % ... old evaluation to remain unchanged | ||
184 | meta2 = meta_ev(shared.meta_data_files{1}); | ||
185 | meta2.load_models; | ||
186 | assertEqual(meta, meta2); | ||
187 | % assert(isequal(meta, meta2)) | ||
188 | meta2.ev_files{1,1} = 'somechangedpath'; | ||
189 | assert(~isequal(meta, meta2)); | ||
190 | |||
191 | %% if two parameters of param2 are selected INEXACTLY expect ... | ||
192 | param_ind = 2; | ||
193 | target = meta.params{param_ind}([1,4],1) + 0.01; | ||
194 | meta_filtered = meta.filter_params(param_ind, target); | ||
195 | % ... new dimensions 2xN | ||
196 | assertEqual(meta_filtered.dimensions(1),2,... | ||
197 | 'expected two entries for parameter 2') | ||
198 | assertEqual(meta_filtered.dimensions(2),meta.dimensions(2),... | ||
199 | 'expected unchanged dimensions of parameter 1') | ||
200 | % ... one-dim. evaluation | ||
201 | assertEqual(meta_filtered.gridtype, 'matrix',... | ||
202 | 'expected gridtype "matrix"') | ||
203 | % ... only selected param survives | ||
204 | assertEqual(unique(meta_filtered.params{2}), target - 0.01,... | ||
205 | 'expected two values of parameter 2 almost equal to input') | ||
206 | % ... along other dimension all params survive | ||
207 | assertEqual(unique(meta_filtered.params{1}),... | ||
208 | unique(meta.params{1}),... | ||
209 | 'expected values of parameter 1 to remain unchanged') | ||
210 | % ... old evaluation to remain unchanged | ||
211 | meta2 = meta_ev(shared.meta_data_files{1}); | ||
212 | meta2.load_models; | ||
213 | assertEqual(meta, meta2); | ||
214 | % assert(isequal(meta, meta2)) | ||
215 | meta2.ev_files{ 1 ,1}='somechangedpath'; | ||
216 | assert(~isequal(meta, meta2)); | ||
217 | |||
218 | %% REPEATED FILTERING | ||
219 | %% if two parameters of param2 and 3 params of param1are selected INEXACTLY expect ... | ||
220 | param_ind = 2; | ||
221 | target2 = meta.params{param_ind}([1,4],1) + 0.01; | ||
222 | meta_filtered = meta.filter_params(param_ind, target2); | ||
223 | param_ind = 1; | ||
224 | target1 = meta_filtered.params{param_ind}(1,[1,3,5]) + 0.01; | ||
225 | meta_filtered = meta_filtered.filter_params(param_ind, target1); | ||
226 | % ... new dimensions 2xN | ||
227 | assertEqual(meta_filtered.dimensions(1),2,... | ||
228 | 'expected two entries for parameter 2') | ||
229 | assertEqual(meta_filtered.dimensions(2),3,... | ||
230 | 'expected three entries for parameter 1') | ||
231 | % ... one-dim. evaluation | ||
232 | assertEqual(meta_filtered.gridtype, 'matrix',... | ||
233 | 'expected gridtype "matrix"') | ||
234 | % ... only selected params survive for param2 | ||
235 | assertEqual(unique(meta_filtered.params{2}), target2 - 0.01,... | ||
236 | 'expected two values of parameter 2 almost equal to input') | ||
237 | % ... only selected params survive for param1 | ||
238 | assertEqual(unique(meta_filtered.params{1})', target1 - 0.01,... | ||
239 | 'expected three values of parameter 3 almost equal to input') | ||
240 | |||
241 | % ... old evaluation to remain unchanged | ||
242 | meta2 = meta_ev(shared.meta_data_files{1}); | ||
243 | meta2.load_models; | ||
244 | assertEqual(meta, meta2); | ||
245 | % assert(isequal(meta, meta2)) | ||
246 | meta2.ev_files{ 1 ,1}='somechangedpath'; | ||
247 | assert(~isequal(meta, meta2)); | ||
107 | meta = meta_ev(shared.meta_data_files{1}); | ||
108 | meta.load_models; | ||
109 | |||
110 | %% if only one parameter is selected expect ... | ||
111 | param_ind = 1; | ||
112 | target = meta.params{param_ind}(1,1); | ||
113 | meta_filtered = meta.filter_params(param_ind, target); | ||
114 | % ... new dimensions 1xN | ||
115 | assertEqual(meta_filtered.dimensions(2),1,... | ||
116 | 'expected single entry for parameter 1') | ||
117 | assertEqual(meta_filtered.dimensions(1),meta.dimensions(1),... | ||
118 | 'expected unchanged dimensions of parameter 2') | ||
119 | % ... one-dim. evaluation | ||
120 | assertEqual(meta_filtered.gridtype, 'vector',... | ||
121 | 'expected gridtype "vector"') | ||
122 | % ... only selected param survives | ||
123 | assertEqual(unique(meta_filtered.params{1}), target,... | ||
124 | 'expected only value of parameter 1 equal to input') | ||
125 | % ... along other dimension all params survive | ||
126 | assertEqual(unique(meta_filtered.params{2}),... | ||
127 | unique(meta.params{2}),... | ||
128 | 'expected values of parameter 2 to remain unchanged') | ||
129 | % ... old evaluation to remain unchanged | ||
130 | meta2 = meta_ev(shared.meta_data_files{1}); | ||
131 | meta2.load_models; | ||
132 | assertEqual(meta, meta2); | ||
133 | % assert(isequal(meta, meta2)) | ||
134 | meta2.ev_files{1,1} = 'somechangedpath'; | ||
135 | assert(~isequal(meta, meta2)); | ||
136 | |||
137 | %% if only one parameter is selected INEXACTLY expect ... | ||
138 | param_ind = 1; | ||
139 | target = meta.params{param_ind}(1,1) + 1; | ||
140 | meta_filtered = meta.filter_params(param_ind, target); | ||
141 | % ... new dimensions 1xN | ||
142 | assertEqual(meta_filtered.dimensions(2),1,... | ||
143 | 'expected single entry for parameter 1') | ||
144 | assertEqual(meta_filtered.dimensions(1),meta.dimensions(1),... | ||
145 | 'expected unchanged dimensions of parameter 2') | ||
146 | % ... one-dim. evaluation | ||
147 | assertEqual(meta_filtered.gridtype, 'vector',... | ||
148 | 'expected gridtype "vector"') | ||
149 | % ... only selected param survives | ||
150 | assertEqual(unique(meta_filtered.params{1}), target -1,... | ||
151 | 'expected only value of parameter 1 almost equal to input') | ||
152 | % ... along other dimension all params survive | ||
153 | assertEqual(unique(meta_filtered.params{2}),... | ||
154 | unique(meta.params{2}),... | ||
155 | 'expected values of parameter 2 to remain unchanged') | ||
156 | % ... old evaluation to remain unchanged | ||
157 | meta2 = meta_ev(shared.meta_data_files{1}); | ||
158 | meta2.load_models; | ||
159 | assertEqual(meta, meta2); | ||
160 | % assert(isequal(meta, meta2)) | ||
161 | meta2.ev_files{1,1} = 'somechangedpath'; | ||
162 | assert(~isequal(meta, meta2)); | ||
163 | |||
164 | %% if two parameter are selected INEXACTLY expect ... | ||
165 | param_ind = 1; | ||
166 | target = meta.params{param_ind}(1,[1,4]) + 1; | ||
167 | meta_filtered = meta.filter_params(param_ind, target); | ||
168 | % ... new dimensions 2xN | ||
169 | assertEqual(meta_filtered.dimensions(2),2,... | ||
170 | 'expected two entries for parameter 1') | ||
171 | assertEqual(meta_filtered.dimensions(1),meta.dimensions(1),... | ||
172 | 'expected unchanged dimensions of parameter 2') | ||
173 | % ... one-dim. evaluation | ||
174 | assertEqual(meta_filtered.gridtype, 'matrix',... | ||
175 | 'expected gridtype "matrix"') | ||
176 | % ... only selected param survives | ||
177 | assertEqual(unique(meta_filtered.params{1})', target -1,... | ||
178 | 'expected two values of parameter 1 almost equal to input') | ||
179 | % ... along other dimension all params survive | ||
180 | assertEqual(unique(meta_filtered.params{2}),... | ||
181 | unique(meta.params{2}),... | ||
182 | 'expected values of parameter 2 to remain unchanged') | ||
183 | % ... old evaluation to remain unchanged | ||
184 | meta2 = meta_ev(shared.meta_data_files{1}); | ||
185 | meta2.load_models; | ||
186 | assertEqual(meta, meta2); | ||
187 | % assert(isequal(meta, meta2)) | ||
188 | meta2.ev_files{1,1} = 'somechangedpath'; | ||
189 | assert(~isequal(meta, meta2)); | ||
190 | |||
191 | %% if two parameters of param2 are selected INEXACTLY expect ... | ||
192 | param_ind = 2; | ||
193 | target = meta.params{param_ind}([1,4],1) + 0.01; | ||
194 | meta_filtered = meta.filter_params(param_ind, target); | ||
195 | % ... new dimensions 2xN | ||
196 | assertEqual(meta_filtered.dimensions(1),2,... | ||
197 | 'expected two entries for parameter 2') | ||
198 | assertEqual(meta_filtered.dimensions(2),meta.dimensions(2),... | ||
199 | 'expected unchanged dimensions of parameter 1') | ||
200 | % ... one-dim. evaluation | ||
201 | assertEqual(meta_filtered.gridtype, 'matrix',... | ||
202 | 'expected gridtype "matrix"') | ||
203 | % ... only selected param survives | ||
204 | assertEqual(unique(meta_filtered.params{2}), target - 0.01,... | ||
205 | 'expected two values of parameter 2 almost equal to input') | ||
206 | % ... along other dimension all params survive | ||
207 | assertEqual(unique(meta_filtered.params{1}),... | ||
208 | unique(meta.params{1}),... | ||
209 | 'expected values of parameter 1 to remain unchanged') | ||
210 | % ... old evaluation to remain unchanged | ||
211 | meta2 = meta_ev(shared.meta_data_files{1}); | ||
212 | meta2.load_models; | ||
213 | assertEqual(meta, meta2); | ||
214 | % assert(isequal(meta, meta2)) | ||
215 | meta2.ev_files{ 1 ,1}='somechangedpath'; | ||
216 | assert(~isequal(meta, meta2)); | ||
217 | |||
218 | %% REPEATED FILTERING | ||
219 | %% if two parameters of param2 and 3 params of param1are selected INEXACTLY expect ... | ||
220 | param_ind = 2; | ||
221 | target2 = meta.params{param_ind}([1,4],1) + 0.01; | ||
222 | meta_filtered = meta.filter_params(param_ind, target2); | ||
223 | param_ind = 1; | ||
224 | target1 = meta_filtered.params{param_ind}(1,[1,3,5]) + 0.01; | ||
225 | meta_filtered = meta_filtered.filter_params(param_ind, target1); | ||
226 | % ... new dimensions 2xN | ||
227 | assertEqual(meta_filtered.dimensions(1),2,... | ||
228 | 'expected two entries for parameter 2') | ||
229 | assertEqual(meta_filtered.dimensions(2),3,... | ||
230 | 'expected three entries for parameter 1') | ||
231 | % ... one-dim. evaluation | ||
232 | assertEqual(meta_filtered.gridtype, 'matrix',... | ||
233 | 'expected gridtype "matrix"') | ||
234 | % ... only selected params survive for param2 | ||
235 | assertEqual(unique(meta_filtered.params{2}), target2 - 0.01,... | ||
236 | 'expected two values of parameter 2 almost equal to input') | ||
237 | % ... only selected params survive for param1 | ||
238 | assertEqual(unique(meta_filtered.params{1})', target1 - 0.01,... | ||
239 | 'expected three values of parameter 3 almost equal to input') | ||
240 | |||
241 | % ... old evaluation to remain unchanged | ||
242 | meta2 = meta_ev(shared.meta_data_files{1}); | ||
243 | meta2.load_models; | ||
244 | assertEqual(meta, meta2); | ||
245 | % assert(isequal(meta, meta2)) | ||
246 | meta2.ev_files{ 1 ,1}='somechangedpath'; | ||
247 | assert(~isequal(meta, meta2)); |
File data_analysis/unittests/old/gausseof_test.m changed (mode: 100644) (index f396afd..cf79a37) | |||
... | ... | for r = 0:0.01:1 | |
11 | 11 | ||
12 | 12 | % teststate: | % teststate: |
13 | 13 | symtmgs = tmss(r)+n*eye(4); %thermal two-mode squeezed state | symtmgs = tmss(r)+n*eye(4); %thermal two-mode squeezed state |
14 | |||
14 | |||
15 | 15 | %%% 'brute force' (source: 10.1103/PhysRevLett.101.220403)... | %%% 'brute force' (source: 10.1103/PhysRevLett.101.220403)... |
16 | 16 | sfparams = gausssfparams(symtmgs); | sfparams = gausssfparams(symtmgs); |
17 | 17 | b = sfparams(1); | b = sfparams(1); |
... | ... | for r = 0:0.01:1 | |
20 | 20 | ||
21 | 21 | sympeval = sqrt((b - c)*(b-abs(d))); | sympeval = sqrt((b - c)*(b-abs(d))); |
22 | 22 | xm = (sympeval^2 + 1/4)/(2*sympeval); | xm = (sympeval^2 + 1/4)/(2*sympeval); |
23 | |||
23 | |||
24 | 24 | rarr(i,j)=r; | rarr(i,j)=r; |
25 | 25 | narr(i,j)=n; | narr(i,j)=n; |
26 | 26 | ||
27 | 27 | eof_test(i,j) = (xm+1/2)*log(xm+1/2) - (xm-1/2)*log(xm-1/2); | eof_test(i,j) = (xm+1/2)*log(xm+1/2) - (xm-1/2)*log(xm-1/2); |
28 | |||
28 | |||
29 | 29 | %%% ... vs the general method implemented by gausseof.m (source: 10.1103/PhysRevLett.101.220403) | %%% ... vs the general method implemented by gausseof.m (source: 10.1103/PhysRevLett.101.220403) |
30 | 30 | eof(i,j) = gausseof(symtmgs); | eof(i,j) = gausseof(symtmgs); |
31 | 31 | end | end |
File data_analysis/unittests/old/gausssfparams_test.m changed (mode: 100644) (index 059ec67..6a1f4ce) | |||
... | ... | testcm{4} = testcm{3} + 1/2*(noise + noise'); | |
10 | 10 | ||
11 | 11 | %% test the standard forms | %% test the standard forms |
12 | 12 | for i=1:4 | for i=1:4 |
13 | disp('***********************************************************'); | ||
13 | disp('***********************************************************'); | ||
14 | 14 | disp([10,'Testing CM number ', num2str(i)]); | disp([10,'Testing CM number ', num2str(i)]); |
15 | 15 | disp([10,'Standard form 1 ']); | disp([10,'Standard form 1 ']); |
16 | 16 | testsfparams = gausssfparams(testcm{i}) | testsfparams = gausssfparams(testcm{i}) |
17 | 17 | gausssfcm(testsfparams)-testcm{i} | gausssfcm(testsfparams)-testcm{i} |
18 | 18 | disp([10,'Standard form 1 ']); | disp([10,'Standard form 1 ']); |
19 | testsfparams2 = gausssfparams2(testcm{i}) | ||
19 | testsfparams2 = gausssfparams2(testcm{i}) | ||
20 | 20 | gausssfcm2(testsfparams2)-testcm{i} | gausssfcm2(testsfparams2)-testcm{i} |
21 | 21 | end | end |
File data_analysis/unittests/other/estimated_time_of_arrival_test.m changed (mode: 100644) (index cd3e23f..f9307ae) | |||
1 | 1 | function test_suite = estimated_time_of_arrival_test%#ok<STOUT> | function test_suite = estimated_time_of_arrival_test%#ok<STOUT> |
2 | clc; | ||
3 | initTestSuite; | ||
2 | clc; | ||
3 | initTestSuite; | ||
4 | 4 | ||
5 | 5 | function shared = setup | function shared = setup |
6 | shared.pause_time = 0.2; | ||
7 | shared.print_output = false; | ||
6 | shared.pause_time = 0.2; | ||
7 | shared.print_output = false; | ||
8 | 8 | ||
9 | 9 | function teardown(shared) | function teardown(shared) |
10 | clear shared | ||
10 | clear shared | ||
11 | 11 | ||
12 | 12 | function estimated_time_of_arrival_minutes_test(shared) | function estimated_time_of_arrival_minutes_test(shared) |
13 | print_eta = estimated_time_of_arrival; | ||
14 | pause(shared.pause_time); | ||
15 | |||
16 | %minutes, output expected | ||
17 | iteration = 10; iteration_no = 60*1e3; | ||
18 | expected_duration_mins = shared.pause_time*(iteration_no/iteration)/60; | ||
19 | output = evalc('print_eta(iteration, iteration_no)'); | ||
20 | assertEqual(... | ||
21 | floor(find_time_number(output, '[minutes]: ')),... | ||
22 | expected_duration_mins) | ||
23 | if shared.print_output | ||
24 | disp(expected_duration_mins); | ||
25 | disp(output); | ||
26 | end | ||
27 | |||
28 | %seconds, no output expected | ||
29 | iteration = 10; iteration_no = 1e3; | ||
30 | expected_duration_sec = shared.pause_time*iteration_no/iteration; | ||
31 | output = evalc('print_eta(iteration, iteration_no)'); | ||
32 | assertEqual(output,''); | ||
33 | if shared.print_output | ||
34 | disp(expected_duration_sec); | ||
35 | disp(output); | ||
36 | end | ||
37 | |||
38 | %days, output expected | ||
39 | iteration = 10; iteration_no = 60*60*24*1e3; | ||
40 | expected_duration_days = shared.pause_time*(iteration_no/iteration)/(60*60*24); | ||
41 | output = evalc('print_eta(iteration, iteration_no)'); | ||
42 | assertEqual(... | ||
43 | floor(find_time_number(output, '[days]: ')),... | ||
44 | expected_duration_days); | ||
45 | if shared.print_output | ||
46 | disp(expected_duration_days); | ||
47 | disp(output); | ||
48 | end | ||
49 | |||
13 | print_eta = estimated_time_of_arrival; | ||
14 | pause(shared.pause_time); | ||
15 | |||
16 | %minutes, output expected | ||
17 | iteration = 10; iteration_no = 60*1e3; | ||
18 | expected_duration_mins = shared.pause_time*(iteration_no/iteration)/60; | ||
19 | output = evalc('print_eta(iteration, iteration_no)'); | ||
20 | assertEqual(... | ||
21 | floor(find_time_number(output, '[minutes]: ')),... | ||
22 | expected_duration_mins) | ||
23 | if shared.print_output | ||
24 | disp(expected_duration_mins); | ||
25 | disp(output); | ||
26 | end | ||
27 | |||
28 | %seconds, no output expected | ||
29 | iteration = 10; iteration_no = 1e3; | ||
30 | expected_duration_sec = shared.pause_time*iteration_no/iteration; | ||
31 | output = evalc('print_eta(iteration, iteration_no)'); | ||
32 | assertEqual(output,''); | ||
33 | if shared.print_output | ||
34 | disp(expected_duration_sec); | ||
35 | disp(output); | ||
36 | end | ||
37 | |||
38 | %days, output expected | ||
39 | iteration = 10; iteration_no = 60*60*24*1e3; | ||
40 | expected_duration_days = shared.pause_time*(iteration_no/iteration)/(60*60*24); | ||
41 | output = evalc('print_eta(iteration, iteration_no)'); | ||
42 | assertEqual(... | ||
43 | floor(find_time_number(output, '[days]: ')),... | ||
44 | expected_duration_days); | ||
45 | if shared.print_output | ||
46 | disp(expected_duration_days); | ||
47 | disp(output); | ||
48 | end | ||
50 | 49 | ||
51 | function time_num = find_time_number(string, pattern) | ||
52 | startind = strfind(string, pattern) + length(pattern); | ||
53 | time_num = str2num(string(startind:startind+3)); | ||
54 | 50 | ||
51 | function time_num = find_time_number(string, pattern) | ||
52 | startind = strfind(string, pattern) + length(pattern); | ||
53 | time_num = str2num(string(startind:startind+3)); |
File data_analysis/unittests/permute_data_test.m changed (mode: 100644) (index e50ef92..0ef4b81) | |||
1 | 1 | function test_suite = permute_data_test %#ok<STOUT> | function test_suite = permute_data_test %#ok<STOUT> |
2 | localFunctionHandles = cellfun(@str2func,... | ||
3 | which('-subfun', mfilename('fullpath')), 'UniformOutput', false); | ||
4 | test_suite = buildFunctionHandleTestSuite(localFunctionHandles); | ||
2 | localFunctionHandles = cellfun(@str2func,... | ||
3 | which('-subfun', mfilename('fullpath')), 'UniformOutput', false); | ||
4 | test_suite = buildFunctionHandleTestSuite(localFunctionHandles); | ||
5 | 5 | ||
6 | 6 | function shared = setup | function shared = setup |
7 | sample_no = 2; | ||
8 | mode_no = 3; | ||
9 | qdata = repmat([1:mode_no], sample_no, 1); | ||
10 | pdata = repmat([1:mode_no]*10, sample_no, 1); | ||
11 | xdata = repmat([1:mode_no]*100, sample_no, 1); | ||
12 | ydata = repmat([1:mode_no]*1000, sample_no, 1); | ||
13 | |||
14 | shared.data = [qdata, pdata, xdata, ydata]; | ||
15 | shared.data_ordered = [ qdata(:,1), pdata(:,1),... | ||
16 | qdata(:,2), pdata(:,2),... | ||
17 | qdata(:,3), pdata(:,3),... | ||
18 | xdata(:,1), ydata(:,1),... | ||
19 | xdata(:,2), ydata(:,2),... | ||
20 | xdata(:,3), ydata(:,3) ]; | ||
21 | |||
22 | shared.data_singlemode = repmat([1,2,3,4], sample_no, 1); | ||
7 | sample_no = 2; | ||
8 | mode_no = 3; | ||
9 | qdata = repmat([1:mode_no], sample_no, 1); | ||
10 | pdata = repmat([1:mode_no]*10, sample_no, 1); | ||
11 | xdata = repmat([1:mode_no]*100, sample_no, 1); | ||
12 | ydata = repmat([1:mode_no]*1000, sample_no, 1); | ||
13 | |||
14 | shared.data = [qdata, pdata, xdata, ydata]; | ||
15 | shared.data_ordered = [ qdata(:,1), pdata(:,1),... | ||
16 | qdata(:,2), pdata(:,2),... | ||
17 | qdata(:,3), pdata(:,3),... | ||
18 | xdata(:,1), ydata(:,1),... | ||
19 | xdata(:,2), ydata(:,2),... | ||
20 | xdata(:,3), ydata(:,3) ]; | ||
21 | |||
22 | shared.data_singlemode = repmat([1,2,3,4], sample_no, 1); | ||
23 | 23 | ||
24 | 24 | function teardown(shared) | function teardown(shared) |
25 | 25 | ||
26 | 26 | function permute_data_labels_test(shared) | function permute_data_labels_test(shared) |
27 | labels_before = {'q1', 'q2', 'p1', 'p2', 'x1', 'x2', 'y1', 'y2'}; | ||
28 | labels_after = {'q1', 'p1', 'q2', 'p2', 'x1', 'y1', 'x2', 'y2'}; | ||
29 | assertEqual(labels_after, permute_data(labels_before)); | ||
27 | labels_before = {'q1', 'q2', 'p1', 'p2', 'x1', 'x2', 'y1', 'y2'}; | ||
28 | labels_after = {'q1', 'p1', 'q2', 'p2', 'x1', 'y1', 'x2', 'y2'}; | ||
29 | assertEqual(labels_after, permute_data(labels_before)); | ||
30 | 30 | ||
31 | 31 | function permute_data_2modes_test(shared) | function permute_data_2modes_test(shared) |
32 | %q->1, p->2, x->3, y->4; hence: q1->11, q2->12,... | ||
33 | %[q1, q2, p1, p2, x1, x2, y1, y2] | ||
34 | modes_before = [11, 12, 21, 22, 31, 32, 41, 42]; | ||
35 | %[q1, p1, q2, p2, x1, y1, x2, y2] | ||
36 | modes_after = [11, 21, 12, 22, 31, 41, 32, 42]; | ||
37 | assertEqual(modes_after, permute_data(modes_before)); | ||
32 | %q->1, p->2, x->3, y->4; hence: q1->11, q2->12,... | ||
33 | %[q1, q2, p1, p2, x1, x2, y1, y2] | ||
34 | modes_before = [11, 12, 21, 22, 31, 32, 41, 42]; | ||
35 | %[q1, p1, q2, p2, x1, y1, x2, y2] | ||
36 | modes_after = [11, 21, 12, 22, 31, 41, 32, 42]; | ||
37 | assertEqual(modes_after, permute_data(modes_before)); | ||
38 | 38 | ||
39 | 39 | function permute_data_3modes_test(shared) | function permute_data_3modes_test(shared) |
40 | data_ordered = permute_data(shared.data); | ||
41 | assertEqual(data_ordered, shared.data_ordered); | ||
40 | data_ordered = permute_data(shared.data); | ||
41 | assertEqual(data_ordered, shared.data_ordered); | ||
42 | 42 | ||
43 | 43 | function permute_data_twice_test(shared) | function permute_data_twice_test(shared) |
44 | data = permute_data(... | ||
45 | permute_data(shared.data),... | ||
46 | 'inverse', true); | ||
47 | assertEqual(data, shared.data); | ||
44 | data = permute_data(... | ||
45 | permute_data(shared.data),... | ||
46 | 'inverse', true); | ||
47 | assertEqual(data, shared.data); | ||
48 | 48 | ||
49 | 49 | function permute_data_twice_random_test(shared) | function permute_data_twice_random_test(shared) |
50 | randdata = randn(48,48); | ||
51 | data = permute_data(... | ||
52 | permute_data(randdata),... | ||
53 | 'inverse', true); | ||
54 | assertEqual(data, randdata); | ||
50 | randdata = randn(48,48); | ||
51 | data = permute_data(... | ||
52 | permute_data(randdata),... | ||
53 | 'inverse', true); | ||
54 | assertEqual(data, randdata); | ||
55 | 55 | ||
56 | 56 | function permute_data_1mode_test(shared) | function permute_data_1mode_test(shared) |
57 | invariant_data = shared.data_singlemode(1,:); | ||
58 | assertEqual(permute_data(invariant_data), invariant_data); | ||
57 | invariant_data = shared.data_singlemode(1,:); | ||
58 | assertEqual(permute_data(invariant_data), invariant_data); | ||
59 | 59 | ||
60 | invariant_data = shared.data_singlemode; | ||
61 | assertEqual(permute_data(invariant_data), invariant_data); | ||
60 | invariant_data = shared.data_singlemode; | ||
61 | assertEqual(permute_data(invariant_data), invariant_data); |
File data_analysis/unittests/pseudo_hash_test.m changed (mode: 100644) (index de5e52f..06608d3) | |||
1 | 1 | function test_suite = pseudo_hash_test %#ok<STOUT> | function test_suite = pseudo_hash_test %#ok<STOUT> |
2 | localFunctionHandles = cellfun(@str2func,... | ||
3 | which('-subfun', mfilename('fullpath')), 'UniformOutput', false); | ||
4 | test_suite = buildFunctionHandleTestSuite(localFunctionHandles); | ||
5 | |||
2 | localFunctionHandles = cellfun(@str2func,... | ||
3 | which('-subfun', mfilename('fullpath')), 'UniformOutput', false); | ||
4 | test_suite = buildFunctionHandleTestSuite(localFunctionHandles); | ||
5 | |||
6 | 6 | function shared = setup | function shared = setup |
7 | shared.sample_no = 1e3; | ||
8 | shared.data = randn(shared.sample_no, 1); | ||
9 | shared.precision = 'double'; | ||
10 | shared.DAQrange = 0; | ||
11 | shared.amplification = 1; | ||
12 | |||
13 | shared.bytes_for_test = 1e2; | ||
14 | shared.shafunction = @(filename) pseudo_hash(filename, 'bytes', shared.bytes_for_test); | ||
15 | |||
16 | shared.folder = tempname; | ||
17 | assert(~(exist(shared.folder)==7),... | ||
18 | [shared.folder, ' exists already.']); | ||
19 | mkdir(shared.folder) | ||
20 | |||
21 | shared.file = fullfile(shared.folder, '.test.dat'); | ||
22 | assert_file_nonexistent(shared.file); | ||
23 | fid = fopen(shared.file,'w+'); | ||
24 | fwrite(fid, shared.data, shared.precision); | ||
25 | fclose(fid); | ||
26 | |||
27 | shared.copy.file = fullfile(shared.folder, '.test_copy.dat'); | ||
28 | assert_file_nonexistent(shared.copy.file); | ||
29 | copyfile(shared.file, shared.copy.file); | ||
30 | |||
31 | shared.empty.file = fullfile(shared.folder, '.test_empty.dat'); | ||
32 | assert_file_nonexistent(shared.empty.file); | ||
33 | |||
34 | exist_not_empty = @(folder)(exist(folder)==7)&&(~isempty(ls(folder))); | ||
35 | if exist_not_empty('/media/schatzkammer/RAID1') | ||
36 | shared.ext.folder = '/media/schatzkammer/RAID1'; | ||
37 | elseif exist_not_empty('~/Downloads') | ||
38 | shared.ext.folder = '~/Downloads'; | ||
39 | else | ||
40 | error(['No suitable folder for tests involving copying files found.',... | ||
41 | 'Modify test accordingly!']); | ||
42 | end | ||
43 | shared.ext.file = fullfile(shared.ext.folder, '.test_copy.dat'); | ||
44 | assert_file_nonexistent(shared.ext.file); | ||
45 | copyfile(shared.file, shared.ext.file); | ||
46 | |||
47 | shared.minifile1 = fullfile(shared.folder, '.minitest.dat'); | ||
48 | shared.minifile2 = fullfile(shared.folder, '.minitest2.dat'); | ||
49 | assert_file_nonexistent(shared.minifile1); | ||
50 | assert_file_nonexistent(shared.minifile2); | ||
51 | dlmwrite(shared.minifile1, [1, 2, 3], 'delimiter', '\t'); | ||
52 | dlmwrite(shared.minifile2, [1, 2, 4], 'delimiter', '\t'); | ||
7 | shared.sample_no = 1e3; | ||
8 | shared.data = randn(shared.sample_no, 1); | ||
9 | shared.precision = 'double'; | ||
10 | shared.DAQrange = 0; | ||
11 | shared.amplification = 1; | ||
12 | |||
13 | shared.bytes_for_test = 1e2; | ||
14 | shared.shafunction = @(filename) pseudo_hash(filename, 'bytes', shared.bytes_for_test); | ||
15 | |||
16 | shared.folder = tempname; | ||
17 | assert(~(exist(shared.folder)==7),... | ||
18 | [shared.folder, ' exists already.']); | ||
19 | mkdir(shared.folder) | ||
20 | |||
21 | shared.file = fullfile(shared.folder, '.test.dat'); | ||
22 | assert_file_nonexistent(shared.file); | ||
23 | fid = fopen(shared.file,'w+'); | ||
24 | fwrite(fid, shared.data, shared.precision); | ||
25 | fclose(fid); | ||
26 | |||
27 | shared.copy.file = fullfile(shared.folder, '.test_copy.dat'); | ||
28 | assert_file_nonexistent(shared.copy.file); | ||
29 | copyfile(shared.file, shared.copy.file); | ||
30 | |||
31 | shared.empty.file = fullfile(shared.folder, '.test_empty.dat'); | ||
32 | assert_file_nonexistent(shared.empty.file); | ||
33 | |||
34 | exist_not_empty = @(folder)(exist(folder)==7)&&(~isempty(ls(folder))); | ||
35 | if exist_not_empty('/media/schatzkammer/RAID1') | ||
36 | shared.ext.folder = '/media/schatzkammer/RAID1'; | ||
37 | elseif exist_not_empty('~/Downloads') | ||
38 | shared.ext.folder = '~/Downloads'; | ||
39 | else | ||
40 | error(['No suitable folder for tests involving copying files found.',... | ||
41 | 'Modify test accordingly!']); | ||
42 | end | ||
43 | shared.ext.file = fullfile(shared.ext.folder, '.test_copy.dat'); | ||
44 | assert_file_nonexistent(shared.ext.file); | ||
45 | copyfile(shared.file, shared.ext.file); | ||
46 | |||
47 | shared.minifile1 = fullfile(shared.folder, '.minitest.dat'); | ||
48 | shared.minifile2 = fullfile(shared.folder, '.minitest2.dat'); | ||
49 | assert_file_nonexistent(shared.minifile1); | ||
50 | assert_file_nonexistent(shared.minifile2); | ||
51 | dlmwrite(shared.minifile1, [1, 2, 3], 'delimiter', '\t'); | ||
52 | dlmwrite(shared.minifile2, [1, 2, 4], 'delimiter', '\t'); | ||
53 | 53 | ||
54 | 54 | function teardown(shared) | function teardown(shared) |
55 | delete(shared.file); | ||
56 | delete(shared.copy.file); | ||
57 | delete(shared.ext.file); | ||
58 | delete(shared.minifile1); | ||
59 | delete(shared.minifile2); | ||
60 | rmdir(shared.folder); | ||
55 | delete(shared.file); | ||
56 | delete(shared.copy.file); | ||
57 | delete(shared.ext.file); | ||
58 | delete(shared.minifile1); | ||
59 | delete(shared.minifile2); | ||
60 | rmdir(shared.folder); | ||
61 | 61 | ||
62 | 62 | function function_handle_test(shared) | function function_handle_test(shared) |
63 | assertEqual(shared.shafunction(shared.file),... | ||
64 | pseudo_hash(shared.file, 'bytes', shared.bytes_for_test)); | ||
63 | assertEqual(shared.shafunction(shared.file),... | ||
64 | pseudo_hash(shared.file, 'bytes', shared.bytes_for_test)); | ||
65 | 65 | ||
66 | 66 | function bytes_sensitive_test(shared) | function bytes_sensitive_test(shared) |
67 | assertFalse(... | ||
68 | isequal(... | ||
69 | shared.shafunction(shared.file),... | ||
70 | pseudo_hash(shared.file, 'bytes', 1+shared.bytes_for_test))); | ||
67 | assertFalse(... | ||
68 | isequal(... | ||
69 | shared.shafunction(shared.file),... | ||
70 | pseudo_hash(shared.file, 'bytes', 1+shared.bytes_for_test))); | ||
71 | 71 | ||
72 | 72 | function default_bytes_test(shared) | function default_bytes_test(shared) |
73 | assertEqual(pseudo_hash(shared.file),... | ||
74 | pseudo_hash(shared.file, 'bytes', 1e6)); | ||
73 | assertEqual(pseudo_hash(shared.file),... | ||
74 | pseudo_hash(shared.file, 'bytes', 1e6)); | ||
75 | 75 | ||
76 | 76 | function filename_filepath_test(shared) | function filename_filepath_test(shared) |
77 | assertEqual(shared.shafunction(shared.file),... | ||
78 | shared.shafunction(GetFullPath(shared.file))); | ||
77 | assertEqual(shared.shafunction(shared.file),... | ||
78 | shared.shafunction(GetFullPath(shared.file))); | ||
79 | 79 | ||
80 | 80 | function open_close_forread_test(shared) | function open_close_forread_test(shared) |
81 | before = shared.shafunction(shared.file); | ||
82 | fid = fopen(shared.file, 'r'); | ||
83 | fclose(fid); | ||
84 | after = shared.shafunction(shared.file); | ||
85 | assertEqual(before, after); | ||
81 | before = shared.shafunction(shared.file); | ||
82 | fid = fopen(shared.file, 'r'); | ||
83 | fclose(fid); | ||
84 | after = shared.shafunction(shared.file); | ||
85 | assertEqual(before, after); | ||
86 | 86 | ||
87 | 87 | % function open_close_forwrite_test(shared) | % function open_close_forwrite_test(shared) |
88 | 88 | % before = shared.shafunction(shared.file); | % before = shared.shafunction(shared.file); |
... | ... | function open_close_forread_test(shared) | |
92 | 92 | % assertEqual(before, after); | % assertEqual(before, after); |
93 | 93 | ||
94 | 94 | function copy_test(shared) | function copy_test(shared) |
95 | assertEqual(shared.shafunction(shared.file),... | ||
96 | shared.shafunction(shared.copy.file)); | ||
95 | assertEqual(shared.shafunction(shared.file),... | ||
96 | shared.shafunction(shared.copy.file)); | ||
97 | 97 | ||
98 | 98 | function modify_begin_test(shared) | function modify_begin_test(shared) |
99 | fid = fopen(shared.copy.file, 'w'); | ||
100 | fseek(fid, 10, 'bof'); | ||
101 | fwrite(fid, randn(1)); | ||
102 | fclose(fid); | ||
103 | assertFalse(... | ||
104 | isequal(shared.shafunction(shared.file),... | ||
105 | shared.shafunction(shared.copy.file))); | ||
99 | fid = fopen(shared.copy.file, 'w'); | ||
100 | fseek(fid, 10, 'bof'); | ||
101 | fwrite(fid, randn(1)); | ||
102 | fclose(fid); | ||
103 | assertFalse(... | ||
104 | isequal(shared.shafunction(shared.file),... | ||
105 | shared.shafunction(shared.copy.file))); | ||
106 | 106 | ||
107 | 107 | function modify_end_test(shared) | function modify_end_test(shared) |
108 | assertEqual(shared.shafunction(shared.file),... | ||
109 | shared.shafunction(shared.copy.file)); | ||
110 | fid = fopen(shared.copy.file, 'w'); | ||
111 | fseek(fid, -10, 'eof'); | ||
112 | fwrite(fid, randn(1)); | ||
113 | fclose(fid); | ||
114 | assertFalse(... | ||
115 | isequal(shared.shafunction(shared.file),... | ||
116 | shared.shafunction(shared.copy.file))); | ||
108 | assertEqual(shared.shafunction(shared.file),... | ||
109 | shared.shafunction(shared.copy.file)); | ||
110 | fid = fopen(shared.copy.file, 'w'); | ||
111 | fseek(fid, -10, 'eof'); | ||
112 | fwrite(fid, randn(1)); | ||
113 | fclose(fid); | ||
114 | assertFalse(... | ||
115 | isequal(shared.shafunction(shared.file),... | ||
116 | shared.shafunction(shared.copy.file))); | ||
117 | 117 | ||
118 | 118 | function modify_length_test(shared) | function modify_length_test(shared) |
119 | fid = fopen(shared.empty.file, 'w+'); | ||
120 | fwrite(fid, shared.data, shared.precision); | ||
121 | %write same data twice to get file with same beginning and end, but different length | ||
122 | fwrite(fid, shared.data, shared.precision); | ||
123 | fclose(fid); | ||
119 | fid = fopen(shared.empty.file, 'w+'); | ||
120 | fwrite(fid, shared.data, shared.precision); | ||
121 | %write same data twice to get file with same beginning and end, but different length | ||
122 | fwrite(fid, shared.data, shared.precision); | ||
123 | fclose(fid); | ||
124 | 124 | ||
125 | hash_original = shared.shafunction(shared.file); | ||
126 | hash_doublesize = shared.shafunction(shared.empty.file); | ||
127 | delete(shared.empty.file) | ||
128 | assertFalse( isequal( hash_original, hash_doublesize)); | ||
125 | hash_original = shared.shafunction(shared.file); | ||
126 | hash_doublesize = shared.shafunction(shared.empty.file); | ||
127 | delete(shared.empty.file) | ||
128 | assertFalse( isequal( hash_original, hash_doublesize)); | ||
129 | 129 | ||
130 | 130 | function minifile_test(shared) | function minifile_test(shared) |
131 | assertFalse(... | ||
132 | isequal(... | ||
133 | shared.shafunction(shared.minifile1),... | ||
134 | shared.shafunction(shared.minifile2))); | ||
131 | assertFalse(... | ||
132 | isequal(... | ||
133 | shared.shafunction(shared.minifile1),... | ||
134 | shared.shafunction(shared.minifile2))); | ||
135 | 135 | ||
136 | 136 | function external_filesystem_test(shared) | function external_filesystem_test(shared) |
137 | assertEqual(... | ||
138 | shared.shafunction(shared.file),... | ||
139 | shared.shafunction(shared.ext.file)); | ||
137 | assertEqual(... | ||
138 | shared.shafunction(shared.file),... | ||
139 | shared.shafunction(shared.ext.file)); | ||
140 | 140 | ||
141 | 141 | %% aux functions | %% aux functions |
142 | 142 | function assert_file_nonexistent(filename) | function assert_file_nonexistent(filename) |
143 | assertFalse(exist(filename)==2,... | ||
144 | [GetFullPath(filename), ' already exists!']); | ||
143 | assertFalse(exist(filename)==2,... | ||
144 | [GetFullPath(filename), ' already exists!']); |
File data_analysis/unittests/read_permute_write_data_test.m changed (mode: 100644) (index 5322ed6..e4937e5) | |||
1 | 1 | function test_suite = read_permute_write_data_test %#ok<STOUT> | function test_suite = read_permute_write_data_test %#ok<STOUT> |
2 | localFunctionHandles = cellfun(@str2func,... | ||
3 | which('-subfun', mfilename('fullpath')), 'UniformOutput', false); | ||
4 | test_suite = buildFunctionHandleTestSuite(localFunctionHandles); | ||
2 | localFunctionHandles = cellfun(@str2func,... | ||
3 | which('-subfun', mfilename('fullpath')), 'UniformOutput', false); | ||
4 | test_suite = buildFunctionHandleTestSuite(localFunctionHandles); | ||
5 | 5 | ||
6 | 6 | function shared = setup | function shared = setup |
7 | shared.folder = tempname; | ||
8 | assert(~(exist(shared.folder)==7),... | ||
9 | [shared.folder, ' exists already.']); | ||
10 | mkdir(shared.folder) | ||
11 | shared.file = fullfile(shared.folder, 'read_permute_write_data_test.tsv'); | ||
12 | assert(~(exist(shared.file)==2),... | ||
13 | [shared.file, ' exists already.']); | ||
14 | |||
15 | sample_no = 2; | ||
16 | mode_no = 3; | ||
17 | |||
18 | shared.precision = 1e4; | ||
19 | myround = @(float_num) round(float_num*shared.precision)/shared.precision; | ||
20 | |||
21 | qdata = myround(randn(sample_no, mode_no)); | ||
22 | pdata = myround(randn(sample_no, mode_no)); | ||
23 | xdata = myround(randn(sample_no, mode_no)); | ||
24 | ydata = myround(randn(sample_no, mode_no)); | ||
25 | |||
26 | shared.data = [qdata, pdata, xdata, ydata]; | ||
27 | shared.data_ordered = [ qdata(:,1), pdata(:,1),... | ||
28 | qdata(:,2), pdata(:,2),... | ||
29 | qdata(:,3), pdata(:,3),... | ||
30 | xdata(:,1), ydata(:,1),... | ||
31 | xdata(:,2), ydata(:,2),... | ||
32 | xdata(:,3), ydata(:,3) ]; | ||
33 | dlmwrite(shared.file, shared.data, '\t'); | ||
7 | shared.folder = tempname; | ||
8 | assert(~(exist(shared.folder)==7),... | ||
9 | [shared.folder, ' exists already.']); | ||
10 | mkdir(shared.folder) | ||
11 | shared.file = fullfile(shared.folder, 'read_permute_write_data_test.tsv'); | ||
12 | assert(~(exist(shared.file)==2),... | ||
13 | [shared.file, ' exists already.']); | ||
14 | |||
15 | sample_no = 2; | ||
16 | mode_no = 3; | ||
17 | |||
18 | shared.precision = 1e4; | ||
19 | myround = @(float_num) round(float_num*shared.precision)/shared.precision; | ||
20 | |||
21 | qdata = myround(randn(sample_no, mode_no)); | ||
22 | pdata = myround(randn(sample_no, mode_no)); | ||
23 | xdata = myround(randn(sample_no, mode_no)); | ||
24 | ydata = myround(randn(sample_no, mode_no)); | ||
25 | |||
26 | shared.data = [qdata, pdata, xdata, ydata]; | ||
27 | shared.data_ordered = [ qdata(:,1), pdata(:,1),... | ||
28 | qdata(:,2), pdata(:,2),... | ||
29 | qdata(:,3), pdata(:,3),... | ||
30 | xdata(:,1), ydata(:,1),... | ||
31 | xdata(:,2), ydata(:,2),... | ||
32 | xdata(:,3), ydata(:,3) ]; | ||
33 | dlmwrite(shared.file, shared.data, '\t'); | ||
34 | 34 | ||
35 | 35 | function teardown(shared) | function teardown(shared) |
36 | delete(shared.file); | ||
37 | rmdir(shared.folder); | ||
36 | delete(shared.file); | ||
37 | rmdir(shared.folder); | ||
38 | 38 | ||
39 | 39 | function read_permute_write_data_3modes_test(shared) | function read_permute_write_data_3modes_test(shared) |
40 | [permuted_data_file, permuted_data_CM_file] = read_permute_write_data(shared.file); | ||
41 | assertEqual(permuted_data_file, shared.file) | ||
42 | data_ordered = dlmread(shared.file, '\t'); | ||
43 | assertEqual(data_ordered, shared.data_ordered); | ||
44 | delete(permuted_data_CM_file); | ||
40 | [permuted_data_file, permuted_data_CM_file] = read_permute_write_data(shared.file); | ||
41 | assertEqual(permuted_data_file, shared.file) | ||
42 | data_ordered = dlmread(shared.file, '\t'); | ||
43 | assertEqual(data_ordered, shared.data_ordered); | ||
44 | delete(permuted_data_CM_file); | ||
45 | 45 | ||
46 | 46 | function read_permute_write_data_3modes_CM_test(shared) | function read_permute_write_data_3modes_CM_test(shared) |
47 | [permuted_data_file, permuted_data_CM_file] = read_permute_write_data(shared.file); | ||
48 | CM_ordered = dlmread(permuted_data_CM_file, '\t'); | ||
49 | % CM_ordered(1:2,1:2) | ||
50 | % cm2 = cov(shared.data_ordered); | ||
51 | % cm2(1:2,1:2) | ||
52 | assertElementsAlmostEqual(CM_ordered, cov(shared.data_ordered), 'absolute', shared.precision); | ||
53 | delete(permuted_data_CM_file) | ||
47 | [permuted_data_file, permuted_data_CM_file] = read_permute_write_data(shared.file); | ||
48 | CM_ordered = dlmread(permuted_data_CM_file, '\t'); | ||
49 | % CM_ordered(1:2,1:2) | ||
50 | % cm2 = cov(shared.data_ordered); | ||
51 | % cm2(1:2,1:2) | ||
52 | assertElementsAlmostEqual(CM_ordered, cov(shared.data_ordered), 'absolute', shared.precision); | ||
53 | delete(permuted_data_CM_file) |
File data_analysis/unittests/test_cf-based_evaluation/calculate_cf_test_data.m changed (mode: 100644) (index 8bac799..a82e3b3) | |||
1 | 1 | %% calculate blocked cross-correlation %%% | %% calculate blocked cross-correlation %%% |
2 | %% setup | ||
2 | %% setup | ||
3 | 3 | clear all; rehash; clc | clear all; rehash; clc |
4 | 4 | addpath(genpath('/home/membrane/Documents/MATLAB')) | addpath(genpath('/home/membrane/Documents/MATLAB')) |
5 | 5 | cd('/home/membrane/Documents/MATLAB/datoolbox/data_analysis/unittests/test_cf-based_evaluation') | cd('/home/membrane/Documents/MATLAB/datoolbox/data_analysis/unittests/test_cf-based_evaluation') |
... | ... | title('covariances') | |
154 | 154 | %% | %% |
155 | 155 | k=1; | k=1; |
156 | 156 | l=4; | l=4; |
157 | figure; | ||
157 | figure; | ||
158 | 158 | lower = myCIs(:,1,k,l); | lower = myCIs(:,1,k,l); |
159 | 159 | upper = myCIs(:,2,k,l); | upper = myCIs(:,2,k,l); |
160 | 160 | lower = lower./(lower+upper); | lower = lower./(lower+upper); |
... | ... | refline(0,cf_CM_signal(k,l)) | |
165 | 165 | % set(gca, 'yscale','log') | % set(gca, 'yscale','log') |
166 | 166 | title(['covariances: ',num2str(k),num2str(l)]) | title(['covariances: ',num2str(k),num2str(l)]) |
167 | 167 | ||
168 | %% plot | ||
168 | %% plot | ||
169 | 169 | close all | close all |
170 | 170 | figure; | figure; |
171 | 171 | subplot(1,2,1) | subplot(1,2,1) |
... | ... | end | |
180 | 180 | set(gca, 'yscale', 'log') | set(gca, 'yscale', 'log') |
181 | 181 | title('Diagonal elements') | title('Diagonal elements') |
182 | 182 | legend({'pulse based'; 'corr. fct. based'}, 'Location', 'SouthOutside') | legend({'pulse based'; 'corr. fct. based'}, 'Location', 'SouthOutside') |
183 | set(gca,'xticklabel',[]) | ||
183 | set(gca,'xticklabel',[]) | ||
184 | 184 | ||
185 | 185 | subplot(1,2,2) | subplot(1,2,2) |
186 | 186 | hold all | hold all |
... | ... | for k=1:4 | |
197 | 197 | end | end |
198 | 198 | title('Offdiagonal elements') | title('Offdiagonal elements') |
199 | 199 | legend({'pulse based'; 'corr. fct. based'}, 'Location', 'SouthOutside') | legend({'pulse based'; 'corr. fct. based'}, 'Location', 'SouthOutside') |
200 | set(gca,'xticklabel',[]) | ||
200 | set(gca,'xticklabel',[]) | ||
201 | 201 | ||
202 | 202 | ||
203 | 203 | ||
... | ... | cf_yy = ev.correlation_functions{2,2}./myvec; | |
281 | 281 | cf_xy = ev.correlation_functions{1,2}./myvec; | cf_xy = ev.correlation_functions{1,2}./myvec; |
282 | 282 | cf_yx = ev.correlation_functions{2,1}./myvec; | cf_yx = ev.correlation_functions{2,1}./myvec; |
283 | 283 | ||
284 | %% | ||
284 | %% | ||
285 | 285 | pulseCM = ev.pulse_CM{1}{1}; | pulseCM = ev.pulse_CM{1}{1}; |
286 | 286 | ||
287 | 287 | %% entangling block | %% entangling block |
... | ... | for kk=[1, 3] | |
382 | 382 | for ll=[1, 3] | for ll=[1, 3] |
383 | 383 | mat{1} = cf_CM_signal(kk:kk+1,ll:ll+1); | mat{1} = cf_CM_signal(kk:kk+1,ll:ll+1); |
384 | 384 | mat{2} = pulseCM(kk:kk+1,ll:ll+1); | mat{2} = pulseCM(kk:kk+1,ll:ll+1); |
385 | figure; | ||
385 | figure; | ||
386 | 386 | for k=1:2 | for k=1:2 |
387 | 387 | subplot(3,1,k); | subplot(3,1,k); |
388 | 388 | myimagesc(mypreproc(mat{k})) | myimagesc(mypreproc(mat{k})) |
... | ... | end | |
408 | 408 | %% | %% |
409 | 409 | diag(reldiff(pulseCM, cf_CM_signal)) | diag(reldiff(pulseCM, cf_CM_signal)) |
410 | 410 | figure; imagesc(triu(reldiff(pulseCM, cf_CM_signal),1)); colorbar() | figure; imagesc(triu(reldiff(pulseCM, cf_CM_signal),1)); colorbar() |
411 |
File data_analysis/unittests/test_cf-based_evaluation/cf_based_CM.m changed (mode: 100644) (index b630a9d..4f25320) | |||
... | ... | function cm = cf_based_CM_subblock(cfp,cf,part) | |
9 | 9 | cf_21 = part(cf{2,1}); | cf_21 = part(cf{2,1}); |
10 | 10 | cf_22 = part(cf{2,2}); | cf_22 = part(cf{2,2}); |
11 | 11 | ||
12 | cfp_11 = cfp{1,1}; | ||
12 | cfp_11 = cfp{1,1}; | ||
13 | 13 | cfp_12 = cfp{1,2}; | cfp_12 = cfp{1,2}; |
14 | 14 | cfp_21 = cfp{2,1}; | cfp_21 = cfp{2,1}; |
15 | 15 | cfp_22 = cfp{2,2}; | cfp_22 = cfp{2,2}; |
16 | |||
16 | |||
17 | 17 | cm = zeros(2,2); | cm = zeros(2,2); |
18 | 18 | cm(1,1) = cfp_11*cf_11 + cfp_22*cf_22 - cfp_12*cf_12 - cfp_21*cf_21; | cm(1,1) = cfp_11*cf_11 + cfp_22*cf_22 - cfp_12*cf_12 - cfp_21*cf_21; |
19 | 19 | cm(1,2) = cfp_12*cf_11 - cfp_21*cf_22 + cfp_11*cf_12 - cfp_22*cf_21; | cm(1,2) = cfp_12*cf_11 - cfp_21*cf_22 + cfp_11*cf_12 - cfp_22*cf_21; |
20 | cm(2,1) = cfp_21*cf_11 - cfp_12*cf_22 - cfp_22*cf_12 + cfp_11*cf_21; | ||
21 | cm(2,2) = cfp_22*cf_11 + cfp_11*cf_22 + cfp_21*cf_12 + cfp_12*cf_21; | ||
20 | cm(2,1) = cfp_21*cf_11 - cfp_12*cf_22 - cfp_22*cf_12 + cfp_11*cf_21; | ||
21 | cm(2,2) = cfp_22*cf_11 + cfp_11*cf_22 + cfp_21*cf_12 + cfp_12*cf_21; | ||
22 | 22 | end | end |
File data_analysis/unittests/test_cf-based_evaluation/quick_comparison_CMs.m changed (mode: 100644) (index c5fdedb..d3e02a0) | |||
1 | 1 | function quick_comparison_CMs(pulsedCM, pulsedCMci, rows, cols, cfCM) | function quick_comparison_CMs(pulsedCM, pulsedCMci, rows, cols, cfCM) |
2 | mytriu = @(mat)mat(:)';%[mat(1,1), mat(1,2), mat(2,1), mat(2,2)]; | ||
3 | |||
2 | mytriu = @(mat)mat(:)';%[mat(1,1), mat(1,2), mat(2,1), mat(2,2)]; | ||
3 | |||
4 | 4 | disp('** pulse-based result with lower and upper CI-bounds **') | disp('** pulse-based result with lower and upper CI-bounds **') |
5 | 5 | disp(mytriu(squeeze(pulsedCMci(1,rows,cols)))) %lower CI-bound | disp(mytriu(squeeze(pulsedCMci(1,rows,cols)))) %lower CI-bound |
6 | 6 | disp(mytriu(pulsedCM(rows,cols))) %actually measured value | disp(mytriu(pulsedCM(rows,cols))) %actually measured value |
... | ... | function quick_comparison_CMs(pulsedCM, pulsedCMci, rows, cols, cfCM) | |
13 | 13 | ||
14 | 14 | disp('** cf-based result **') | disp('** cf-based result **') |
15 | 15 | disp(mytriu(cfCM)) | disp(mytriu(cfCM)) |
16 | |||
16 | |||
17 | 17 | disp('** relative deviation in percent **') | disp('** relative deviation in percent **') |
18 | 18 | myreldiff = @(mat1,mat2)100*abs(2*(mat1-mat2)./(mat1+mat2)); | myreldiff = @(mat1,mat2)100*abs(2*(mat1-mat2)./(mat1+mat2)); |
19 | 19 | myreldiff2 = @(mat1, mat2)myreldiff(mytriu(mat1),mytriu(mat2)); | myreldiff2 = @(mat1, mat2)myreldiff(mytriu(mat1),mytriu(mat2)); |
File data_analysis/unittests/test_cf-based_evaluation/simulate_test_data.m changed (mode: 100644) (index bec943c..f1f9bca) | |||
... | ... | fidp = fopen(fullfile(datadir, 'p.dat'),'w'); | |
22 | 22 | ||
23 | 23 | for k=1:block_no | for k=1:block_no |
24 | 24 | k | k |
25 | start_sample = (k-1)*N+1; | ||
26 | stop_sample = k*N; | ||
27 | if k==1 | ||
28 | x0 = simgauss(zeros(length(ss_cov),1), ss_cov,1); | ||
29 | else | ||
30 | x0 = states_full(end,:); | ||
31 | end | ||
32 | [~, ~, states_full] = lsim(sys, u, t, x0); | ||
25 | start_sample = (k-1)*N+1; | ||
26 | stop_sample = k*N; | ||
27 | if k==1 | ||
28 | x0 = simgauss(zeros(length(ss_cov),1), ss_cov,1); | ||
29 | else | ||
30 | x0 = states_full(end,:); | ||
31 | end | ||
32 | [~, ~, states_full] = lsim(sys, u, t, x0); | ||
33 | 33 | x = states_full(2:end,1); | x = states_full(2:end,1); |
34 | 34 | p = states_full(2:end,2); | p = states_full(2:end,2); |
35 | |||
35 | |||
36 | 36 | % write to binary files | % write to binary files |
37 | 37 | fwrite(fidx,x, precision); | fwrite(fidx,x, precision); |
38 | 38 | fwrite(fidp,p, precision); | fwrite(fidp,p, precision); |
... | ... | for k=1:reps | |
51 | 51 | k | k |
52 | 52 | x0 = simgauss(zeros(length(ss_cov),1), ss_cov,1); | x0 = simgauss(zeros(length(ss_cov),1), ss_cov,1); |
53 | 53 | [~,~, states_full] = lsim(sys, u, t, x0); | [~,~, states_full] = lsim(sys, u, t, x0); |
54 | for l=1:6 | ||
54 | for l=1:6 | ||
55 | 55 | energies{l}(k) = sum(diag(cov(states_full(1:10^l,:)))); | energies{l}(k) = sum(diag(cov(states_full(1:10^l,:)))); |
56 | 56 | end | end |
57 | 57 | % for visual inspection... | % for visual inspection... |
... | ... | end | |
62 | 62 | ||
63 | 63 | %% plot spread of energies vs stretch length | %% plot spread of energies vs stretch length |
64 | 64 | figure; hold all | figure; hold all |
65 | for l=1:6 | ||
65 | for l=1:6 | ||
66 | 66 | scatter([10^l],[std(energies{l})/mean(energies{l})],'b','filled') | scatter([10^l],[std(energies{l})/mean(energies{l})],'b','filled') |
67 | 67 | end | end |
68 | 68 | plot([10,1e6],[1e3,1]*std(energies{6})/mean(energies{6})) | plot([10,1e6],[1e3,1]*std(energies{6})/mean(energies{6})) |
... | ... | set(gca, 'xscale','log') | |
111 | 111 | %% autocorrelation function | %% autocorrelation function |
112 | 112 | figure; hold all | figure; hold all |
113 | 113 | plot(xcorr(data(1:1e7,:),'biased')) | plot(xcorr(data(1:1e7,:),'biased')) |
114 | |||
114 | |||
115 | 115 | %% ETC | %% ETC |
116 | 116 | w = warning('query','last') | w = warning('query','last') |
117 | 117 | warning('off',w.identifier) | warning('off',w.identifier) |
File data_analysis/unittests/test_cf-based_evaluation/test_cf_based_evaluation.m changed (mode: 100644) (index 15a4a41..bde236b) | |||
... | ... | delta = imag(readout_mode); | |
78 | 78 | ||
79 | 79 | %% plots | %% plots |
80 | 80 | figure; hold all; | figure; hold all; |
81 | subplot(2,1,1); | ||
81 | subplot(2,1,1); | ||
82 | 82 | plot(ev.pulse_timevector, alpha, ... | plot(ev.pulse_timevector, alpha, ... |
83 | 83 | ev.pulse_timevector, beta) | ev.pulse_timevector, beta) |
84 | 84 | legend({'\alpha';'\beta'}) | legend({'\alpha';'\beta'}) |
85 | 85 | xlabel('time [sec]') | xlabel('time [sec]') |
86 | 86 | ||
87 | subplot(2,1,2); | ||
87 | subplot(2,1,2); | ||
88 | 88 | plot(ev.pulse_timevector, gamma, ... | plot(ev.pulse_timevector, gamma, ... |
89 | 89 | ev.pulse_timevector, delta) | ev.pulse_timevector, delta) |
90 | 90 | legend({'\gamma';'\delta'}) | legend({'\gamma';'\delta'}) |
... | ... | ratio_shot = cf_CM_shot./pulsedCM_shot | |
200 | 200 | ||
201 | 201 | %% | %% |
202 | 202 | ratio_signal | ratio_signal |
203 | ratio_shot | ||
203 | ratio_shot | ||
204 | 204 | ||
205 | 205 | %% | %% |
206 | 206 | ||
... | ... | plot(real(cf{1,5})) | |
251 | 251 | testmat = zeros(2,50); | testmat = zeros(2,50); |
252 | 252 | testmat(1,:) = ones(50,1); | testmat(1,:) = ones(50,1); |
253 | 253 | testmat*randn(50,1) | testmat*randn(50,1) |
254 |
File data_analysis/unittests/testevaluation/setup_eval.m changed (mode: 100644) (index 223a5b2..5550ae8) | |||
... | ... | f_ref = 1.2E6; | |
11 | 11 | ev.mech_frequencies = f_ref; | ev.mech_frequencies = f_ref; |
12 | 12 | ev.opt_pulse_widths = 1; | ev.opt_pulse_widths = 1; |
13 | 13 | ev.pulse_gammas = f_ref*logspace(-2,0,20); | ev.pulse_gammas = f_ref*logspace(-2,0,20); |
14 |
File data_analysis/unittests/testevaluation/setup_meas.m changed (mode: 100644) (index 888573f..1167af3) | |||
... | ... | meas.add_trace_pair(... | |
19 | 19 | '200muW_yQ_int16_sf40.000_Nts1.0e+05_MCr1.dat',... | '200muW_yQ_int16_sf40.000_Nts1.0e+05_MCr1.dat',... |
20 | 20 | 'amplification', 40,... | 'amplification', 40,... |
21 | 21 | 'signal_power_muW', 200); | 'signal_power_muW', 200); |
22 |
File data_analysis/unittests/timetrace_test.m changed (mode: 100644) (index bf09b37..fff7be0) | |||
1 | 1 | function test_suite = timetrace_test %#ok<STOUT> | function test_suite = timetrace_test %#ok<STOUT> |
2 | localFunctionHandles = cellfun(@str2func,... | ||
3 | which('-subfun', mfilename('fullpath')), 'UniformOutput', false); | ||
4 | test_suite = buildFunctionHandleTestSuite(localFunctionHandles); | ||
2 | localFunctionHandles = cellfun(@str2func,... | ||
3 | which('-subfun', mfilename('fullpath')), 'UniformOutput', false); | ||
4 | test_suite = buildFunctionHandleTestSuite(localFunctionHandles); | ||
5 | 5 | ||
6 | 6 | function shared = setup | function shared = setup |
7 | shared.show_plots = false; | ||
7 | shared.show_plots = false; | ||
8 | 8 | ||
9 | shared.DAQrange = 0; | ||
10 | shared.amplification = 10; | ||
9 | shared.DAQrange = 0; | ||
10 | shared.amplification = 10; | ||
11 | 11 | ||
12 | shared.sample_no = 1e5 + 1; | ||
13 | shared.samplingrate = 1e2; | ||
14 | shared.timevec = (0:shared.sample_no-1)'/shared.samplingrate; | ||
15 | shared.mech_freq = 3.0626; | ||
16 | shared.data = sin(2*pi*shared.mech_freq*shared.timevec); | ||
12 | shared.sample_no = 1e5 + 1; | ||
13 | shared.samplingrate = 1e2; | ||
14 | shared.timevec = (0:shared.sample_no-1)'/shared.samplingrate; | ||
15 | shared.mech_freq = 3.0626; | ||
16 | shared.data = sin(2*pi*shared.mech_freq*shared.timevec); | ||
17 | 17 | ||
18 | shared.precision = 'double'; | ||
19 | shared.folder = tempname; | ||
20 | assert(~(exist(shared.folder)==7),... | ||
21 | [shared.folder, ' exists already.']); | ||
22 | mkdir(shared.folder) | ||
23 | shared.file = fullfile(shared.folder, '.timetrace.dat'); | ||
18 | shared.precision = 'double'; | ||
19 | shared.folder = tempname; | ||
20 | assert(~(exist(shared.folder)==7),... | ||
21 | [shared.folder, ' exists already.']); | ||
22 | mkdir(shared.folder) | ||
23 | shared.file = fullfile(shared.folder, '.timetrace.dat'); | ||
24 | 24 | ||
25 | fid = fopen(shared.file,'w'); | ||
26 | fwrite(fid, shared.data, shared.precision); | ||
27 | fclose(fid); | ||
25 | fid = fopen(shared.file,'w'); | ||
26 | fwrite(fid, shared.data, shared.precision); | ||
27 | fclose(fid); | ||
28 | 28 | ||
29 | 29 | function teardown(shared) | function teardown(shared) |
30 | delete(shared.file); | ||
31 | rmdir(shared.folder); | ||
30 | delete(shared.file); | ||
31 | rmdir(shared.folder); | ||
32 | 32 | ||
33 | 33 | function ht = timetrace_setup_test(shared) | function ht = timetrace_setup_test(shared) |
34 | ht = timetrace(shared.file,... | ||
35 | 'samplingrate', shared.samplingrate,... | ||
36 | 'precision', shared.precision,... | ||
37 | 'DAQrange', shared.DAQrange,... | ||
38 | 'amplification', shared.amplification); | ||
34 | ht = timetrace(shared.file,... | ||
35 | 'samplingrate', shared.samplingrate,... | ||
36 | 'precision', shared.precision,... | ||
37 | 'DAQrange', shared.DAQrange,... | ||
38 | 'amplification', shared.amplification); | ||
39 | 39 | ||
40 | 40 | function ht = timetrace_read_data_test(shared) | function ht = timetrace_read_data_test(shared) |
41 | ht = timetrace_setup_test(shared); | ||
42 | ht.fopen(); | ||
43 | assertEqual(ht.fread(shared.sample_no), shared.data/shared.amplification); | ||
44 | ht.fclose(); | ||
45 | |||
46 | assertEqual(ht.read_from_t1_to_t2(0,ht.duration), shared.data/shared.amplification); | ||
47 | assertEqual(... | ||
48 | ht.read_from_t1_to_t2(0,ht.duration/2),... | ||
49 | shared.data(1:floor(shared.sample_no/2))/shared.amplification); | ||
50 | |||
51 | if shared.show_plots | ||
52 | div = 1e3; | ||
53 | figure; | ||
54 | plot(shared.timevec(1:floor(shared.sample_no/div)), ht.read_from_t1_to_t2(0,ht.duration/div)) | ||
55 | end | ||
41 | ht = timetrace_setup_test(shared); | ||
42 | ht.fopen(); | ||
43 | assertEqual(ht.fread(shared.sample_no), shared.data/shared.amplification); | ||
44 | ht.fclose(); | ||
45 | |||
46 | assertEqual(ht.read_from_t1_to_t2(0,ht.duration), shared.data/shared.amplification); | ||
47 | assertEqual(... | ||
48 | ht.read_from_t1_to_t2(0,ht.duration/2),... | ||
49 | shared.data(1:floor(shared.sample_no/2))/shared.amplification); | ||
50 | |||
51 | if shared.show_plots | ||
52 | div = 1e3; | ||
53 | figure; | ||
54 | plot(shared.timevec(1:floor(shared.sample_no/div)), ht.read_from_t1_to_t2(0,ht.duration/div)) | ||
55 | end | ||
56 | 56 | ||
57 | 57 | function ht = timetrace_NPS_test(shared) | function ht = timetrace_NPS_test(shared) |
58 | ht = timetrace_setup_test(shared); | ||
59 | ht.get_NPS; | ||
60 | ht.get_peaks; | ||
61 | if shared.show_plots | ||
62 | figure; hold all | ||
63 | plot(ht.spectrum.freq, ht.spectrum.noisepower) | ||
64 | plot(ht.spectrum.peaks.freq, ht.spectrum.peaks.power,'o') | ||
65 | set(gca, 'yscale','log') | ||
66 | set(gca, 'xscale','log') | ||
67 | end | ||
68 | relTol = 1e-2; | ||
69 | assertElementsAlmostEqual(ht.spectrum.peaks.freq, shared.mech_freq, 'relative', relTol); | ||
70 | |||
58 | ht = timetrace_setup_test(shared); | ||
59 | ht.get_NPS; | ||
60 | ht.get_peaks; | ||
61 | if shared.show_plots | ||
62 | figure; hold all | ||
63 | plot(ht.spectrum.freq, ht.spectrum.noisepower) | ||
64 | plot(ht.spectrum.peaks.freq, ht.spectrum.peaks.power,'o') | ||
65 | set(gca, 'yscale','log') | ||
66 | set(gca, 'xscale','log') | ||
67 | end | ||
68 | relTol = 1e-2; | ||
69 | assertElementsAlmostEqual(ht.spectrum.peaks.freq, shared.mech_freq, 'relative', relTol); | ||
70 | |||
71 | 71 | ||
72 | 72 | function ht = timetrace_properties_test(shared) | function ht = timetrace_properties_test(shared) |
73 | ht = timetrace_setup_test(shared); | ||
74 | assertEqual(ht.sample_no, shared.sample_no) | ||
75 | assertEqual(ht.samplingrate, shared.samplingrate) | ||
76 | assertEqual(ht.precision, shared.precision) | ||
73 | ht = timetrace_setup_test(shared); | ||
74 | assertEqual(ht.sample_no, shared.sample_no) | ||
75 | assertEqual(ht.samplingrate, shared.samplingrate) | ||
76 | assertEqual(ht.precision, shared.precision) | ||
77 | 77 | ||
78 | assertEqual(ht.DAQrange, shared.DAQrange) | ||
79 | assertEqual(ht.amplification, shared.amplification) | ||
78 | assertEqual(ht.DAQrange, shared.DAQrange) | ||
79 | assertEqual(ht.amplification, shared.amplification) | ||
80 | 80 | ||
81 | 81 | ||
82 | assertEqual(ht.filepath, shared.file) | ||
83 | [folder, filename, fileext] = fileparts(shared.file); | ||
84 | assertEqual(ht.directory, folder) | ||
85 | assertEqual(ht.filename, [filename, fileext]) | ||
82 | assertEqual(ht.filepath, shared.file) | ||
83 | [folder, filename, fileext] = fileparts(shared.file); | ||
84 | assertEqual(ht.directory, folder) | ||
85 | assertEqual(ht.filename, [filename, fileext]) | ||
86 | 86 | ||
87 | assertEqual(ht.sample_from_time(0), 1) | ||
88 | assertEqual(ht.duration, ht.sample_no/ht.samplingrate) | ||
89 | assertEqual(ht.sample_from_time(ht.duration),ht.sample_no+1) | ||
87 | assertEqual(ht.sample_from_time(0), 1) | ||
88 | assertEqual(ht.duration, ht.sample_no/ht.samplingrate) | ||
89 | assertEqual(ht.sample_from_time(ht.duration),ht.sample_no+1) |
File homo_measurements/@dual_homo_measurement/test_dual_homo_measurement.m changed (mode: 100644) (index 85d9ef6..6e1c6b8) | |||
... | ... | function meas = test_dual_homo_measurement(meas_file) | |
12 | 12 | cd(meas_folder); | cd(meas_folder); |
13 | 13 | run(meas_script) | run(meas_script) |
14 | 14 | disp(meas) | disp(meas) |
15 | |||
15 | |||
16 | 16 | %% create subfolder for test output | %% create subfolder for test output |
17 | 17 | mkdir(meas_folder, 'test') | mkdir(meas_folder, 'test') |
18 | 18 | test_folder = fullfile(meas_folder, 'test'); | test_folder = fullfile(meas_folder, 'test'); |
... | ... | function [npsfig] = create_save_sample_NPS(meas, test_folder) | |
43 | 43 | fclose(outid); | fclose(outid); |
44 | 44 | ||
45 | 45 | dlmwrite(outfile, data, 'delimiter', '\t', '-append'); | dlmwrite(outfile, data, 'delimiter', '\t', '-append'); |
46 | |||
46 | |||
47 | 47 | %% print shotnoise PSD and non-shotnoise PSD | %% print shotnoise PSD and non-shotnoise PSD |
48 | ii = 1; | ||
48 | ii = 1; | ||
49 | 49 | for kk=1:2 | for kk=1:2 |
50 | 50 | disp(['mean noise power of ', meas.homotraces(ii,kk).dataset_label]) | disp(['mean noise power of ', meas.homotraces(ii,kk).dataset_label]) |
51 | 51 | disp(mean(meas.homotraces(ii,kk).spectrum.noisepower)) | disp(mean(meas.homotraces(ii,kk).spectrum.noisepower)) |
52 | 52 | disp('') | disp('') |
53 | 53 | end | end |
54 | |||
54 | |||
55 | 55 | ii = 2; | ii = 2; |
56 | 56 | for kk=1:2 | for kk=1:2 |
57 | 57 | disp(['mean noise power of ', meas.homotraces(ii,kk).dataset_label, ' for high freqs.']) | disp(['mean noise power of ', meas.homotraces(ii,kk).dataset_label, ' for high freqs.']) |
File homo_measurements/@homo_measurement/homo_measurement.m changed (mode: 100644) (index f6fa907..b77cf1b) | |||
... | ... | classdef homo_measurement < handle | |
25 | 25 | ||
26 | 26 | %scalar properties: the same for all homotraces | %scalar properties: the same for all homotraces |
27 | 27 | samplingrate@double scalar | samplingrate@double scalar |
28 | |||
28 | |||
29 | 29 | %dummy = true creates a short dummy file with random numbers to play around with | %dummy = true creates a short dummy file with random numbers to play around with |
30 | 30 | % for more details see PXItrace-code | % for more details see PXItrace-code |
31 | dummy = false; | ||
31 | dummy = false; | ||
32 | 32 | end | end |
33 | 33 | properties(Dependent) | properties(Dependent) |
34 | 34 | % scalar | % scalar |
File homo_measurements/quickcheck_dualhomo.m changed (mode: 100644) (index 67a09e6..7653daf) | |||
... | ... | DAQrange_mV = 200; | |
7 | 7 | signalpower_muW = 588; | signalpower_muW = 588; |
8 | 8 | ||
9 | 9 | filename1 = ['P', num2str(signalpower_muW),'muW_']; | filename1 = ['P', num2str(signalpower_muW),'muW_']; |
10 | % or | ||
10 | % or | ||
11 | 11 | %filename1 = 'Pdarknoise_'; | %filename1 = 'Pdarknoise_'; |
12 | 12 | filename1 = 'Pshotnoise_'; | filename1 = 'Pshotnoise_'; |
13 | 13 | amplification_dB = 40; | amplification_dB = 40; |
... | ... | meas.add_trace_pair(... | |
29 | 29 | ||
30 | 30 | %% spectra | %% spectra |
31 | 31 | meas.get_NPS | meas.get_NPS |
32 | fig = figure; meas.show_NPS; | ||
32 | fig = figure; meas.show_NPS; | ||
33 | 33 | title([filename1, '...', filename2], 'Interpreter', 'none'); | title([filename1, '...', filename2], 'Interpreter', 'none'); |
34 | 34 | saveas(fig, ['spectra_', filename1, filename2, '.fig']) | saveas(fig, ['spectra_', filename1, filename2, '.fig']) |
35 | 35 | saveas(fig, ['spectra_', filename1, filename2, '.jpg']) | saveas(fig, ['spectra_', filename1, filename2, '.jpg']) |
36 | 36 | ||
37 | 37 | %% snapshot of timetrace | %% snapshot of timetrace |
38 | fig = figure; meas.show_snapshot; | ||
38 | fig = figure; meas.show_snapshot; | ||
39 | 39 | title([filename1, '...', filename2], 'Interpreter', 'none'); | title([filename1, '...', filename2], 'Interpreter', 'none'); |
40 | 40 | saveas(fig, ['snapshot_', filename1, filename2, '.fig']) | saveas(fig, ['snapshot_', filename1, filename2, '.fig']) |
41 | 41 | saveas(fig, ['snapshot_', filename1, filename2, '.jpg']) | saveas(fig, ['snapshot_', filename1, filename2, '.jpg']) |
42 | 42 | ||
43 | 43 | %% histogram of timetrace | %% histogram of timetrace |
44 | fig = figure; meas.show_hist; | ||
44 | fig = figure; meas.show_hist; | ||
45 | 45 | title([filename1, '...', filename2], 'Interpreter', 'none'); | title([filename1, '...', filename2], 'Interpreter', 'none'); |
46 | 46 | saveas(fig, ['hist_', filename1, filename2, '.fig']) | saveas(fig, ['hist_', filename1, filename2, '.fig']) |
47 | 47 | saveas(fig, ['hist_', filename1, filename2, '.jpg']) | saveas(fig, ['hist_', filename1, filename2, '.jpg']) |
File homo_measurements/quickcheck_dualhomo_long.m changed (mode: 100644) (index b442278..3cffe48) | |||
... | ... | end | |
40 | 40 | tic; | tic; |
41 | 41 | meas.get_NPS('duration', 0.01, 'averages', 20) | meas.get_NPS('duration', 0.01, 'averages', 20) |
42 | 42 | toc; | toc; |
43 | fig = figure; meas.show_NPS; | ||
43 | fig = figure; meas.show_NPS; | ||
44 | 44 | title([filename1, '...', filename2], 'Interpreter', 'none'); | title([filename1, '...', filename2], 'Interpreter', 'none'); |
45 | 45 | saveas(fig, ['spectra_high_res_', filename1, filename2, '.fig']) | saveas(fig, ['spectra_high_res_', filename1, filename2, '.fig']) |
46 | 46 | saveas(fig, ['spectra_high_res_', filename1, filename2, '.jpg']) | saveas(fig, ['spectra_high_res_', filename1, filename2, '.jpg']) |
... | ... | saveas(fig, ['spectra_high_res_', filename1, filename2, '.jpg']) | |
48 | 48 | %% get peaks | %% get peaks |
49 | 49 | meas.get_peaks('minheight', 1E-14, 'minfreq', 500E3, 'maxfreq', 5E6,... | meas.get_peaks('minheight', 1E-14, 'minfreq', 500E3, 'maxfreq', 5E6,... |
50 | 50 | 'mindistance', 1) | 'mindistance', 1) |
51 | % | ||
51 | % | ||
52 | 52 | % %% plot peaks for different chunks | % %% plot peaks for different chunks |
53 | 53 | % figure; hold all | % figure; hold all |
54 | 54 | % chunk_no = 10; | % chunk_no = 10; |
... | ... | for l=all_peaks | |
78 | 78 | peak_ind = peak_ind+1; | peak_ind = peak_ind+1; |
79 | 79 | end | end |
80 | 80 | ||
81 | %% plot | ||
81 | %% plot | ||
82 | 82 | figure; hold all | figure; hold all |
83 | 83 | for k=1:chunk_no | for k=1:chunk_no |
84 | 84 | plot(all_peaks, k*occurences(:,k), 'o') | plot(all_peaks, k*occurences(:,k), 'o') |
... | ... | dlmwrite(['robust_peaks_', filename1, filename2, '.csv'], robust_peaks') | |
112 | 112 | tic; | tic; |
113 | 113 | meas.get_NPS('duration', 0.0005, 'averages', 100) | meas.get_NPS('duration', 0.0005, 'averages', 100) |
114 | 114 | toc; | toc; |
115 | fig = figure; meas.show_NPS; | ||
115 | fig = figure; meas.show_NPS; | ||
116 | 116 | title([filename1, '...', filename2], 'Interpreter', 'none'); | title([filename1, '...', filename2], 'Interpreter', 'none'); |
117 | 117 | saveas(fig, ['spectra_many_avgs_', filename1, filename2, '.fig']) | saveas(fig, ['spectra_many_avgs_', filename1, filename2, '.fig']) |
118 | 118 | saveas(fig, ['spectra_many_avgs_', filename1, filename2, '.jpg']) | saveas(fig, ['spectra_many_avgs_', filename1, filename2, '.jpg']) |
119 | 119 | ||
120 | 120 | ||
121 | 121 | %% snapshot of timetrace | %% snapshot of timetrace |
122 | fig = figure; meas.show_snapshot; | ||
122 | fig = figure; meas.show_snapshot; | ||
123 | 123 | title([filename1, '...', filename2], 'Interpreter', 'none'); | title([filename1, '...', filename2], 'Interpreter', 'none'); |
124 | 124 | saveas(fig, ['snapshot_', filename1, filename2, '.fig']) | saveas(fig, ['snapshot_', filename1, filename2, '.fig']) |
125 | 125 | saveas(fig, ['snapshot_', filename1, filename2, '.jpg']) | saveas(fig, ['snapshot_', filename1, filename2, '.jpg']) |
126 | 126 | ||
127 | 127 | ||
128 | 128 | %% histogram of timetrace | %% histogram of timetrace |
129 | fig = figure; meas.show_hist; | ||
129 | fig = figure; meas.show_hist; | ||
130 | 130 | title([filename1, '...', filename2], 'Interpreter', 'none'); | title([filename1, '...', filename2], 'Interpreter', 'none'); |
131 | 131 | saveas(fig, ['hist_', filename1, filename2, '.fig']) | saveas(fig, ['hist_', filename1, filename2, '.fig']) |
132 | 132 | saveas(fig, ['hist_', filename1, filename2, '.jpg']) | saveas(fig, ['hist_', filename1, filename2, '.jpg']) |
File kalmanfilter/kalmanfilter.m changed (mode: 100644) (index 4af2b17..46a68e0) | |||
... | ... | function [xest,pest,varargout] = kalmanfilter(F,G,H,D,L,Q,R,M,z,u,xinit,pinit,va | |
4 | 4 | % | % |
5 | 5 | % Kalman filter for a linear discrete system with a time-dependent | % Kalman filter for a linear discrete system with a time-dependent |
6 | 6 | % state-space model given by F(k), G(k), H(k), D(k) | % state-space model given by F(k), G(k), H(k), D(k) |
7 | % | ||
7 | % | ||
8 | 8 | % x(k+1) = F(k) x(k) + G(k) u(k) + L w(k) | % x(k+1) = F(k) x(k) + G(k) u(k) + L w(k) |
9 | 9 | % z(k) = H(k) x(k) + D(k) u(k) + n(k) | % z(k) = H(k) x(k) + D(k) u(k) + n(k) |
10 | 10 | % | % |
... | ... | function [xest,pest,varargout] = kalmanfilter(F,G,H,D,L,Q,R,M,z,u,xinit,pinit,va | |
18 | 18 | % measurement basis in a homodyne-detection measurement.) | % measurement basis in a homodyne-detection measurement.) |
19 | 19 | % | % |
20 | 20 | % xinit and pinit are initial estimates. xinit can be replaced by []. | % xinit and pinit are initial estimates. xinit can be replaced by []. |
21 | % | ||
21 | % | ||
22 | 22 | % The optional output arguments are the predicted measurement output | % The optional output arguments are the predicted measurement output |
23 | 23 | % (which can be used to find the innovation sequence), the statistics | % (which can be used to find the innovation sequence), the statistics |
24 | 24 | % of the NIS test and the NIS sequence. | % of the NIS test and the NIS sequence. |
... | ... | end | |
127 | 127 | ||
128 | 128 | % check if inputs are time-dependent | % check if inputs are time-dependent |
129 | 129 | % x_TD=true <> x is time dependent! | % x_TD=true <> x is time dependent! |
130 | if size(F,3)==1, F_TD=false; f=F; else F_TD=true; fprintf(fID,'Kalmanfilter: Matrix F is time dependent.\n'); end | ||
130 | if size(F,3)==1, F_TD=false; f=F; else F_TD=true; fprintf(fID,'Kalmanfilter: Matrix F is time dependent.\n'); end | ||
131 | 131 | if size(G,3)==1, G_TD=false; g=G; else G_TD=true; fprintf(fID,'Kalmanfilter: Matrix G is time dependent.\n'); end | if size(G,3)==1, G_TD=false; g=G; else G_TD=true; fprintf(fID,'Kalmanfilter: Matrix G is time dependent.\n'); end |
132 | 132 | if size(H,3)==1, H_TD=false; h=H; else H_TD=true; fprintf(fID,'Kalmanfilter: Matrix H is time dependent.\n'); end | if size(H,3)==1, H_TD=false; h=H; else H_TD=true; fprintf(fID,'Kalmanfilter: Matrix H is time dependent.\n'); end |
133 | 133 | if size(D,3)==1, D_TD=false; d=D; else D_TD=true; fprintf(fID,'Kalmanfilter: Matrix D is time dependent.\n'); end | if size(D,3)==1, D_TD=false; d=D; else D_TD=true; fprintf(fID,'Kalmanfilter: Matrix D is time dependent.\n'); end |
... | ... | for mm = 1:NT | |
182 | 182 | ||
183 | 183 | % update state | % update state |
184 | 184 | % alternatively: | % alternatively: |
185 | % xest(:,mm)=(id-K*h)*xm+K*z(:,mm); | ||
185 | % xest(:,mm)=(id-K*h)*xm+K*z(:,mm); | ||
186 | 186 | xest(:,mm) = xm+K*innov; | xest(:,mm) = xm+K*innov; |
187 | 187 | ||
188 | 188 | % update error covariance | % update error covariance |
... | ... | zmvec = zmvec.'; | |
213 | 213 | %% setting output arguments | %% setting output arguments |
214 | 214 | varargout = cell(1,nargout); | varargout = cell(1,nargout); |
215 | 215 | if PREDICT_OUTPUT | if PREDICT_OUTPUT |
216 | varargout{1} = zmvec; | ||
216 | varargout{1} = zmvec; | ||
217 | 217 | end | end |
218 | if NIS_TEST | ||
218 | if NIS_TEST | ||
219 | 219 | [varargout{2:3}] = nistest(z-zmvec,pmvec,H,R,args{:}); | [varargout{2:3}] = nistest(z-zmvec,pmvec,H,R,args{:}); |
220 | 220 | end | end |
221 | 221 |
File misc/3rdparty/AnDarksamtest.m changed (mode: 100644) (index 04e1c33..5bf7c04) | |||
1 | 1 | function [AnDarksamtest] = AnDarksamtest(X,alpha) | function [AnDarksamtest] = AnDarksamtest(X,alpha) |
2 | 2 | %ANDARKSAMTEST Anderson-Darling k-sample procedure to test whether | %ANDARKSAMTEST Anderson-Darling k-sample procedure to test whether |
3 | 3 | % k sampled populations are identical | % k sampled populations are identical |
4 | % | ||
4 | % | ||
5 | 5 | % Anderson and Darling (1952,1954) introduced a goodness-of-fit statistic | % Anderson and Darling (1952,1954) introduced a goodness-of-fit statistic |
6 | 6 | % | % |
7 | 7 | % _inf 2 | % _inf 2 |
8 | 8 | % / {Fm(x) - Fo(x)} | % / {Fm(x) - Fo(x)} |
9 | 9 | % ADm = m / ----------------- dFo(x) | % ADm = m / ----------------- dFo(x) |
10 | 10 | % -inf_/ Fo(x){1 - Fo(x)} | % -inf_/ Fo(x){1 - Fo(x)} |
11 | % | ||
11 | % | ||
12 | 12 | % to test the hypothesis that a random sample Fm(x) comes from a continuous | % to test the hypothesis that a random sample Fm(x) comes from a continuous |
13 | % population with a specified distribution function Fo(x). It is a | ||
13 | % population with a specified distribution function Fo(x). It is a | ||
14 | 14 | % modification of the Kolmogorov-Smirnov (K-S) test and gives more weight | % modification of the Kolmogorov-Smirnov (K-S) test and gives more weight |
15 | 15 | % to the tails than the K-S test. | % to the tails than the K-S test. |
16 | 16 | % | % |
... | ... | function [AnDarksamtest] = AnDarksamtest(X,alpha) | |
21 | 21 | % ADmn = ---- / ----------------- dHn(x) | % ADmn = ---- / ----------------- dHn(x) |
22 | 22 | % N -inf_/ Hn(x){1 - Hn(x)} | % N -inf_/ Hn(x){1 - Hn(x)} |
23 | 23 | % | % |
24 | % was proposed by Darling (1957) and studied in detail by Pettitt (1976). | ||
25 | % Where Gn(x) is the empirical distribution function of the second | ||
24 | % was proposed by Darling (1957) and studied in detail by Pettitt (1976). | ||
25 | % Where Gn(x) is the empirical distribution function of the second | ||
26 | 26 | % independent sample G(x) and Hn(x) = {mFm(x) + nGn(x)}/N, with N = m+n, is | % independent sample G(x) and Hn(x) = {mFm(x) + nGn(x)}/N, with N = m+n, is |
27 | 27 | % the empirical distribution function of the pooled sample. It is used to | % the empirical distribution function of the pooled sample. It is used to |
28 | 28 | % test the hypothesis that F = G. | % test the hypothesis that F = G. |
29 | 29 | % | % |
30 | 30 | % The Anderson-Darling k-sample test was introduced by Scholz and Stephens | % The Anderson-Darling k-sample test was introduced by Scholz and Stephens |
31 | 31 | % (1987) as a generalization of the two-sample Anderson-Darling test. It is | % (1987) as a generalization of the two-sample Anderson-Darling test. It is |
32 | % a nonparametric statistical procedure, i.e., a rank test, and, thus, | ||
33 | % requires no assumptions other than that the samples are true independent | ||
34 | % random samples from their respective continuous populations (although | ||
32 | % a nonparametric statistical procedure, i.e., a rank test, and, thus, | ||
33 | % requires no assumptions other than that the samples are true independent | ||
34 | % random samples from their respective continuous populations (although | ||
35 | 35 | % provisions for tied observations are made). It tests the hypothesis that | % provisions for tied observations are made). It tests the hypothesis that |
36 | 36 | % the populations from which two or more independent samples of data were | % the populations from which two or more independent samples of data were |
37 | 37 | % drawn are identical. This test can be used to decide whether data from | % drawn are identical. This test can be used to decide whether data from |
... | ... | function [AnDarksamtest] = AnDarksamtest(X,alpha) | |
46 | 46 | % it is effective for changes in scale while locations are matched, which is | % it is effective for changes in scale while locations are matched, which is |
47 | 47 | % a weakness of the Kruskal-Wallis test. | % a weakness of the Kruskal-Wallis test. |
48 | 48 | % | % |
49 | % The Anderson-Darling k-sample procedure assumes that i-th sample has a | ||
49 | % The Anderson-Darling k-sample procedure assumes that i-th sample has a | ||
50 | 50 | % continuous distribution function and we are interested in testing the null | % continuous distribution function and we are interested in testing the null |
51 | 51 | % hypothesis that all sampled populations have the same distribution, without | % hypothesis that all sampled populations have the same distribution, without |
52 | 52 | % specifying the nature of that common distribution, | % specifying the nature of that common distribution, |
... | ... | function [AnDarksamtest] = AnDarksamtest(X,alpha) | |
69 | 69 | % n-1 \ 1 \ {nFij - niHj} | % n-1 \ 1 \ {nFij - niHj} |
70 | 70 | % ADK = ---- /_ _ [ ---- /_ _ ---------------- ] | % ADK = ---- /_ _ [ ---- /_ _ ---------------- ] |
71 | 71 | % n^2 i=1 ni j=1 Hj(n-Hj) - nhj/4 | % n^2 i=1 ni j=1 Hj(n-Hj) - nhj/4 |
72 | % | ||
72 | % | ||
73 | 73 | % | % |
74 | 74 | % and the corresponding not adjusted for ties is | % and the corresponding not adjusted for ties is |
75 | 75 | % | % |
... | ... | function [AnDarksamtest] = AnDarksamtest(X,alpha) | |
91 | 91 | % the number of values in the combined samples equal to zj | % the number of values in the combined samples equal to zj |
92 | 92 | % Fij = number of values in the ith group which are less than zj plus one | % Fij = number of values in the ith group which are less than zj plus one |
93 | 93 | % half the number of values in this group which are equal to zj | % half the number of values in this group which are equal to zj |
94 | % | ||
94 | % | ||
95 | 95 | % Under Ho and assuming continuity of the common F distribution the mean of | % Under Ho and assuming continuity of the common F distribution the mean of |
96 | 96 | % ADK is k-1 and the variance* is, | % ADK is k-1 and the variance* is, |
97 | % | ||
98 | % an^3 + bn^2 + cn + d | ||
99 | % var(ADK) = --------------------- | ||
97 | % | ||
98 | % an^3 + bn^2 + cn + d | ||
99 | % var(ADK) = --------------------- | ||
100 | 100 | % (n-1)(n-2)(n-3) | % (n-1)(n-2)(n-3) |
101 | 101 | % | % |
102 | 102 | % where, | % where, |
... | ... | function [AnDarksamtest] = AnDarksamtest(X,alpha) | |
104 | 104 | % b = (2g -4)k^2 + 8Tk + (2g - 14T -4)S - 8T + 4g -6 | % b = (2g -4)k^2 + 8Tk + (2g - 14T -4)S - 8T + 4g -6 |
105 | 105 | % c = (6T + 2g -2)k^2 + (4T - 4g + 6)k + (2T -6)S + 4T | % c = (6T + 2g -2)k^2 + (4T - 4g + 6)k + (2T -6)S + 4T |
106 | 106 | % d = (2T +6)k^2 - 4Tk | % d = (2T +6)k^2 - 4Tk |
107 | % | ||
107 | % | ||
108 | 108 | % with, | % with, |
109 | 109 | % _k _ _n-1_ | % _k _ _n-1_ |
110 | 110 | % \ 1 \ 1 | % \ 1 \ 1 |
111 | % S = /_ _ ---- , T = /_ _ ---- | ||
111 | % S = /_ _ ---- , T = /_ _ ---- | ||
112 | 112 | % ni i=1 i | % ni i=1 i |
113 | 113 | % | % |
114 | 114 | % and | % and |
115 | 115 | % _n-2_ _n-1_ | % _n-2_ _n-1_ |
116 | 116 | % \ \ 1 | % \ \ 1 |
117 | % g = /_ _ /_ _ ------ | ||
117 | % g = /_ _ /_ _ ------ | ||
118 | 118 | % i=1 j=i+1 (n-i)j | % i=1 j=i+1 (n-i)j |
119 | 119 | % | % |
120 | 120 | % The observed k-sample Anderson-Darling statistic (ADK) is standardized | % The observed k-sample Anderson-Darling statistic (ADK) is standardized |
... | ... | function [AnDarksamtest] = AnDarksamtest(X,alpha) | |
136 | 136 | % n^2(k-1) i=1 ni j=1 Hj(n-Hj) - nhj/4 | % n^2(k-1) i=1 ni j=1 Hj(n-Hj) - nhj/4 |
137 | 137 | % | % |
138 | 138 | % | % |
139 | % an^3 + bn^2 + cn + d | ||
139 | % an^3 + bn^2 + cn + d | ||
140 | 140 | % var(ADK) = ------------------------ , | % var(ADK) = ------------------------ , |
141 | 141 | % (n-1)(n-2)(n-3)(k-1)^2 | % (n-1)(n-2)(n-3)(k-1)^2 |
142 | 142 | % | % |
... | ... | function [AnDarksamtest] = AnDarksamtest(X,alpha) | |
149 | 149 | % | % |
150 | 150 | % The approximate P-value of the observed ADK statistic can be calculated | % The approximate P-value of the observed ADK statistic can be calculated |
151 | 151 | % using a spline interpolation method. For the interested users, we are | % using a spline interpolation method. For the interested users, we are |
152 | % including, as a comment, the mathematical procedure to get the ADK | ||
152 | % including, as a comment, the mathematical procedure to get the ADK | ||
153 | 153 | % critical value. | % critical value. |
154 | 154 | % | % |
155 | 155 | % The interpolation coefficients for each alpa-value, | % The interpolation coefficients for each alpa-value, |
... | ... | function [AnDarksamtest] = AnDarksamtest(X,alpha) | |
164 | 164 | % | % |
165 | 165 | % qnt = bo + b1/sqrt(k-1) + b2/(k-1) | % qnt = bo + b1/sqrt(k-1) + b2/(k-1) |
166 | 166 | % | % |
167 | % We give the Anderson-Darling k-sample procedure with and without | ||
167 | % We give the Anderson-Darling k-sample procedure with and without | ||
168 | 168 | % adjustment for ties. | % adjustment for ties. |
169 | 169 | % | % |
170 | 170 | % Finally, we compare the P-value with the desired significance level alpha | % Finally, we compare the P-value with the desired significance level alpha |
171 | % to facilitate a decision about the null hypothesis Ho. | ||
171 | % to facilitate a decision about the null hypothesis Ho. | ||
172 | % | ||
173 | % Syntax: function AnDarksamtest(X,alpha) | ||
172 | 174 | % | % |
173 | % Syntax: function AnDarksamtest(X,alpha) | ||
174 | % | ||
175 | 175 | % Inputs: | % Inputs: |
176 | 176 | % X - data matrix (Size of matrix must be n-by-2; data=column 1, | % X - data matrix (Size of matrix must be n-by-2; data=column 1, |
177 | % sample=column 2) | ||
177 | % sample=column 2) | ||
178 | 178 | % alpha - significance level (default = 0.05) | % alpha - significance level (default = 0.05) |
179 | 179 | % | % |
180 | 180 | % Output: | % Output: |
... | ... | function [AnDarksamtest] = AnDarksamtest(X,alpha) | |
182 | 182 | % | % |
183 | 183 | % Example: From the example given by Scholz and Stephens (1987, p.922). It | % Example: From the example given by Scholz and Stephens (1987, p.922). It |
184 | 184 | % is interested to test if the four sets of eight measurements each of the | % is interested to test if the four sets of eight measurements each of the |
185 | % smoothness of a certain type of paper obtained by four independent | ||
185 | % smoothness of a certain type of paper obtained by four independent | ||
186 | 186 | % laboratories are homogeneous or identical to consider them | % laboratories are homogeneous or identical to consider them |
187 | 187 | % unstructurated. We use an alpha-value = 0.05. Data are, | % unstructurated. We use an alpha-value = 0.05. Data are, |
188 | 188 | % | % |
... | ... | function [AnDarksamtest] = AnDarksamtest(X,alpha) | |
198 | 198 | % Data vector is: | % Data vector is: |
199 | 199 | % X=[38.7 1;41.5 1;43.8 1;44.5 1;45.5 1;46.0 1;47.7 1;58.0 1; | % X=[38.7 1;41.5 1;43.8 1;44.5 1;45.5 1;46.0 1;47.7 1;58.0 1; |
200 | 200 | % 39.2 2;39.3 2;39.7 2;41.4 2;41.8 2;42.9 2;43.3 2;45.8 2; | % 39.2 2;39.3 2;39.7 2;41.4 2;41.8 2;42.9 2;43.3 2;45.8 2; |
201 | % 34.0 3;35.0 3;39.0 3;40.0 3;43.0 3;43.0 3;44.0 3;45.0 3; | ||
201 | % 34.0 3;35.0 3;39.0 3;40.0 3;43.0 3;43.0 3;44.0 3;45.0 3; | ||
202 | 202 | % 34.0 4;34.8 4;34.8 4;35.4 4;37.2 4;37.8 4;41.2 4;42.8 4]; | % 34.0 4;34.8 4;34.8 4;35.4 4;37.2 4;37.8 4;41.2 4;42.8 4]; |
203 | 203 | % | % |
204 | % Calling on Matlab the function: | ||
204 | % Calling on Matlab the function: | ||
205 | 205 | % AnDarksamtest(X) | % AnDarksamtest(X) |
206 | 206 | % | % |
207 | 207 | % Answer is: | % Answer is: |
... | ... | function [AnDarksamtest] = AnDarksamtest(X,alpha) | |
220 | 220 | % Anderson-Darling rank statistic: 8.3558723 | % Anderson-Darling rank statistic: 8.3558723 |
221 | 221 | % Standardized Anderson-Darling rank statistic: 4.4492622 | % Standardized Anderson-Darling rank statistic: 4.4492622 |
222 | 222 | % Probability associated to the Anderson-Darling rank statistic = 0.0022547 | % Probability associated to the Anderson-Darling rank statistic = 0.0022547 |
223 | % | ||
223 | % | ||
224 | 224 | % With a given significance = 0.050 | % With a given significance = 0.050 |
225 | 225 | % The samples were drawn from different populations: data may be considered | % The samples were drawn from different populations: data may be considered |
226 | 226 | % structurated with respect to the random of fixed effect in question. | % structurated with respect to the random of fixed effect in question. |
... | ... | function [AnDarksamtest] = AnDarksamtest(X,alpha) | |
230 | 230 | % Anderson-Darling rank statistic: 8.3926093 | % Anderson-Darling rank statistic: 8.3926093 |
231 | 231 | % Standardized Anderson-Darling rank statistic: 4.4797806 | % Standardized Anderson-Darling rank statistic: 4.4797806 |
232 | 232 | % Probability associated to the Anderson-Darling rank statistic = 0.0021700 | % Probability associated to the Anderson-Darling rank statistic = 0.0021700 |
233 | % | ||
233 | % | ||
234 | 234 | % With a given significance = 0.050 | % With a given significance = 0.050 |
235 | 235 | % The samples were drawn from different populations: data may be considered | % The samples were drawn from different populations: data may be considered |
236 | 236 | % structurated with respect to the random of fixed effect in question. | % structurated with respect to the random of fixed effect in question. |
237 | 237 | % ---------------------------------------------------------------------------- | % ---------------------------------------------------------------------------- |
238 | 238 | % | % |
239 | % Created by A. Trujillo-Ortiz, R. Hernandez-Walls, K. Barba-Rojo, | ||
239 | % Created by A. Trujillo-Ortiz, R. Hernandez-Walls, K. Barba-Rojo, | ||
240 | 240 | % L. Cupul-Magana and R.C. Zavala-Garcia | % L. Cupul-Magana and R.C. Zavala-Garcia |
241 | 241 | % Facultad de Ciencias Marinas | % Facultad de Ciencias Marinas |
242 | 242 | % Universidad Autonoma de Baja California | % Universidad Autonoma de Baja California |
... | ... | function [AnDarksamtest] = AnDarksamtest(X,alpha) | |
247 | 247 | % | % |
248 | 248 | % Copyright. November 1, 2007. | % Copyright. November 1, 2007. |
249 | 249 | % | % |
250 | % ---Special thanks are given to Michael Singer, Department of Earth & | ||
250 | % ---Special thanks are given to Michael Singer, Department of Earth & | ||
251 | 251 | % Planetary Science, Institute for Computational Earth System Science, | % Planetary Science, Institute for Computational Earth System Science, |
252 | 252 | % University of California at Berkely, for encouraging us to create | % University of California at Berkely, for encouraging us to create |
253 | 253 | % this m-file-- | % this m-file-- |
... | ... | function [AnDarksamtest] = AnDarksamtest(X,alpha) | |
266 | 266 | % Anderson, T.W. and Darling, D.A. (1952), Asymptotic Theory of Certain | % Anderson, T.W. and Darling, D.A. (1952), Asymptotic Theory of Certain |
267 | 267 | % Goodness of Fit Criteria Based on Stochastic Processes. Annals of | % Goodness of Fit Criteria Based on Stochastic Processes. Annals of |
268 | 268 | % Mathematical Statistics, 23:193-212. | % Mathematical Statistics, 23:193-212. |
269 | % Anderson, T.W. and Darling, D.A. (1954), A Test of Goodness of Fit. | ||
269 | % Anderson, T.W. and Darling, D.A. (1954), A Test of Goodness of Fit. | ||
270 | 270 | % Journal of the American Statistical Association, 49:765-769. | % Journal of the American Statistical Association, 49:765-769. |
271 | 271 | % Darling, D.A. (1957), The Kolmogorov-Smirnov, Cramer-von Mises | % Darling, D.A. (1957), The Kolmogorov-Smirnov, Cramer-von Mises |
272 | 272 | % Tests. Annals of Mathematical Statistics, 28:823-838. | % Tests. Annals of Mathematical Statistics, 28:823-838. |
... | ... | function [AnDarksamtest] = AnDarksamtest(X,alpha) | |
274 | 274 | % variance analysis. Journal of the American Statistical Association, | % variance analysis. Journal of the American Statistical Association, |
275 | 275 | % 47(260):583�621. | % 47(260):583�621. |
276 | 276 | % Kruskal, W.H. and Wallis, W.A. (1953), Errata to Use of ranks in one- | % Kruskal, W.H. and Wallis, W.A. (1953), Errata to Use of ranks in one- |
277 | % criterion variance analysis. Journal of the American Statistical | ||
277 | % criterion variance analysis. Journal of the American Statistical | ||
278 | 278 | % Association, 48:907-911. | % Association, 48:907-911. |
279 | 279 | % MIL-HDBK-17-1E (1997), The Composite Materials Handbook, Volume 1. | % MIL-HDBK-17-1E (1997), The Composite Materials Handbook, Volume 1. |
280 | 280 | % Polymer Matrix Composites: Guidelines for Characterization of | % Polymer Matrix Composites: Guidelines for Characterization of |
281 | % Structural Materials. Chapter 8, Department of Defense, | ||
281 | % Structural Materials. Chapter 8, Department of Defense, | ||
282 | 282 | % Washington, D.C. | % Washington, D.C. |
283 | 283 | % Pettitt, A.N. (1976), A Two-Sample Anderson-Darling Rank Statistic. | % Pettitt, A.N. (1976), A Two-Sample Anderson-Darling Rank Statistic. |
284 | 284 | % Biometrika, 63:161-168. | % Biometrika, 63:161-168. |
... | ... | switch nargin | |
296 | 296 | end | end |
297 | 297 | case{1} | case{1} |
298 | 298 | alpha = 0.05; | alpha = 0.05; |
299 | otherwise | ||
299 | otherwise | ||
300 | 300 | error('Requires at least one input argument.'); | error('Requires at least one input argument.'); |
301 | 301 | end | end |
302 | 302 | ||
... | ... | hj = c(:,2); %number of values in combined samples equal to zj | |
316 | 316 | hjn = c(1:end-1,2); | hjn = c(1:end-1,2); |
317 | 317 | O = sort(X1); | O = sort(X1); |
318 | 318 | zj = unique(O); %distinct values in the combined data set ordered | zj = unique(O); %distinct values in the combined data set ordered |
319 | L = length(zj); | ||
320 | zjn = zj(1:end-1); %distinct values in the combined data set ordered | ||
319 | L = length(zj); | ||
320 | zjn = zj(1:end-1); %distinct values in the combined data set ordered | ||
321 | 321 | %for adjust for ties | %for adjust for ties |
322 | 322 | Ln = length(zjn); | Ln = length(zjn); |
323 | 323 | ||
324 | 324 | n=[];fij=0;Fij=0;Fijn=0;NN=0;DD=0;ADK1=0;ADK1n=0; | n=[];fij=0;Fij=0;Fijn=0;NN=0;DD=0;ADK1=0;ADK1n=0; |
325 | 325 | for i=1:k, | for i=1:k, |
326 | r = find(X2 == i); | ||
326 | r = find(X2 == i); | ||
327 | 327 | ni = length(r); %number of observations in sample i | ni = length(r); %number of observations in sample i |
328 | 328 | n = [n ni]; | n = [n ni]; |
329 | 329 | if (any(ni==0)), | if (any(ni==0)), |
... | ... | for i=1:k, | |
339 | 339 | %half the number of values in this | %half the number of values in this |
340 | 340 | %group which are equal to zj. It is | %group which are equal to zj. It is |
341 | 341 | %adjusted for ties. | %adjusted for ties. |
342 | |||
342 | |||
343 | 343 | Fijn = [cumsum(fijn)]'; %number of values in the ith group | Fijn = [cumsum(fijn)]'; %number of values in the ith group |
344 | 344 | %which are less than zj plus one | %which are less than zj plus one |
345 | 345 | %half the number of values in this | %half the number of values in this |
346 | 346 | %group which are equal to zj. It is | %group which are equal to zj. It is |
347 | 347 | %not adjusted for ties. | %not adjusted for ties. |
348 | 348 | ||
349 | Hj = [cumsum(hj)-(hj*.5)]; %number of values in the combined samples less | ||
349 | Hj = [cumsum(hj)-(hj*.5)]; %number of values in the combined samples less | ||
350 | 350 | %than zj plus one half the number of values in | %than zj plus one half the number of values in |
351 | %the combined samples equal to zj. It is | ||
351 | %the combined samples equal to zj. It is | ||
352 | 352 | %adjusted for ties. | %adjusted for ties. |
353 | 353 | ||
354 | Hjn = [cumsum(hjn)]; %number of values in the combined samples less | ||
354 | Hjn = [cumsum(hjn)]; %number of values in the combined samples less | ||
355 | 355 | %than zj plus one half the number of values in | %than zj plus one half the number of values in |
356 | 356 | %the combined samples equal to zj. It is not | %the combined samples equal to zj. It is not |
357 | 357 | %adjusted for ties. | %adjusted for ties. |
... | ... | for i=1:k, | |
359 | 359 | NN = (N*Fij-ni*Hj).^2; | NN = (N*Fij-ni*Hj).^2; |
360 | 360 | DD = (Hj.*(N-Hj))-(N*hj./4); | DD = (Hj.*(N-Hj))-(N*hj./4); |
361 | 361 | ADK1 = ADK1 + (1/ni*sum(hj.*(NN./DD))); | ADK1 = ADK1 + (1/ni*sum(hj.*(NN./DD))); |
362 | |||
362 | |||
363 | 363 | NNn = (N*Fijn-ni*Hjn).^2; | NNn = (N*Fijn-ni*Hjn).^2; |
364 | 364 | DDn = Hjn.*(N-Hjn); | DDn = Hjn.*(N-Hjn); |
365 | 365 | ADK1n = ADK1n + (1/ni*sum(hjn.*(NNn./DDn))); | ADK1n = ADK1n + (1/ni*sum(hjn.*(NNn./DDn))); |
... | ... | d = (2*T+6)*k^2-4*T*k; | |
388 | 388 | ||
389 | 389 | vADK = ((a*N^3)+(b*N^2)+(c*N)+d)/((N-1)*(N-2)*(N-3)); | vADK = ((a*N^3)+(b*N^2)+(c*N)+d)/((N-1)*(N-2)*(N-3)); |
390 | 390 | ||
391 | ADKs = (ADK-(k-1))/sqrt(vADK); %standardized k-sample Anderson-Darling | ||
391 | ADKs = (ADK-(k-1))/sqrt(vADK); %standardized k-sample Anderson-Darling | ||
392 | 392 | %statistic | %statistic |
393 | 393 | ||
394 | ADKsn = (ADKn-(k-1))/sqrt(vADK); %standardized k-sample Anderson-Darling | ||
394 | ADKsn = (ADKn-(k-1))/sqrt(vADK); %standardized k-sample Anderson-Darling | ||
395 | 395 | %statistic not adjusted for ties | %statistic not adjusted for ties |
396 | 396 | ||
397 | 397 | %k-sample Anderson-Darling P-value calculation by an extrapolate-interpolate | %k-sample Anderson-Darling P-value calculation by an extrapolate-interpolate |
... | ... | Pn = 1/(1+exp(Y)); | |
451 | 451 | % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
452 | 452 | %Optional k-sample Anderson-Darling critical value calculation procedure | %Optional k-sample Anderson-Darling critical value calculation procedure |
453 | 453 | % zc=norminv(1-alpha); | % zc=norminv(1-alpha); |
454 | % | ||
454 | % | ||
455 | 455 | % if (alpha == 0.25), | % if (alpha == 0.25), |
456 | 456 | % ADKc = 1 + sqrt(vADK)*(zc+(0.25/sqrt(k-1)) - (-0.105/(k-1))); | % ADKc = 1 + sqrt(vADK)*(zc+(0.25/sqrt(k-1)) - (-0.105/(k-1))); |
457 | 457 | % elseif (alpha == 0.10), | % elseif (alpha == 0.10), |
... | ... | if Pn >= alpha; | |
487 | 487 | disp('The populations from which the k-samples of data were drawn are identical:'); | disp('The populations from which the k-samples of data were drawn are identical:'); |
488 | 488 | disp('natural groupings have no significant effect (unstructurated).'); | disp('natural groupings have no significant effect (unstructurated).'); |
489 | 489 | else | else |
490 | disp('The samples were drawn from different populations: data may be considered'); | ||
490 | disp('The samples were drawn from different populations: data may be considered'); | ||
491 | 491 | disp('structurated with respect to the random of fixed effect in question.'); | disp('structurated with respect to the random of fixed effect in question.'); |
492 | 492 | end | end |
493 | 493 | disp('----------------------------------------------------------------------------') | disp('----------------------------------------------------------------------------') |
... | ... | if P >= alpha; | |
502 | 502 | disp('The populations from which the k-samples of data were drawn are identical:'); | disp('The populations from which the k-samples of data were drawn are identical:'); |
503 | 503 | disp('natural groupings have no significant effect (unstructurated).'); | disp('natural groupings have no significant effect (unstructurated).'); |
504 | 504 | else | else |
505 | disp('The samples were drawn from different populations: data may be considered'); | ||
505 | disp('The samples were drawn from different populations: data may be considered'); | ||
506 | 506 | disp('structurated with respect to the random of fixed effect in question.'); | disp('structurated with respect to the random of fixed effect in question.'); |
507 | 507 | end | end |
508 | 508 | disp('----------------------------------------------------------------------------') | disp('----------------------------------------------------------------------------') |
File misc/3rdparty/DataHash.m changed (mode: 100644) (index a5dde25..ae29a53) | |||
... | ... | if nArg == 2 | |
121 | 121 | error(['JSimon:', mfilename, ':BadInput2'], ... | error(['JSimon:', mfilename, ':BadInput2'], ... |
122 | 122 | '*** %s: 2nd input [Opt] must be a struct.', mfilename); | '*** %s: 2nd input [Opt] must be a struct.', mfilename); |
123 | 123 | end | end |
124 | |||
124 | |||
125 | 125 | % Specify hash algorithm: | % Specify hash algorithm: |
126 | 126 | if isfield(Opt, 'Method') | if isfield(Opt, 'Method') |
127 | 127 | Method = upper(Opt.Method); | Method = upper(Opt.Method); |
128 | 128 | end | end |
129 | |||
129 | |||
130 | 130 | % Specify output format: | % Specify output format: |
131 | 131 | if isfield(Opt, 'Format') | if isfield(Opt, 'Format') |
132 | 132 | OutFormat = Opt.Format; | OutFormat = Opt.Format; |
133 | 133 | end | end |
134 | |||
134 | |||
135 | 135 | % Check if the Input type is specified - default: 'array': | % Check if the Input type is specified - default: 'array': |
136 | 136 | if isfield(Opt, 'Input') | if isfield(Opt, 'Input') |
137 | 137 | if strcmpi(Opt.Input, 'File') | if strcmpi(Opt.Input, 'File') |
... | ... | if nArg == 2 | |
140 | 140 | error(['JSimon:', mfilename, ':CannotOpen'], ... | error(['JSimon:', mfilename, ':CannotOpen'], ... |
141 | 141 | '*** %s: 1st input is not a file name', mfilename); | '*** %s: 1st input is not a file name', mfilename); |
142 | 142 | end | end |
143 | |||
143 | |||
144 | 144 | if exist(Data, 'file') ~= 2 | if exist(Data, 'file') ~= 2 |
145 | 145 | error(['JSimon:', mfilename, ':FileNotFound'], ... | error(['JSimon:', mfilename, ':FileNotFound'], ... |
146 | 146 | '*** %s: File not found: %s.', mfilename, Data); | '*** %s: File not found: %s.', mfilename, Data); |
147 | 147 | end | end |
148 | |||
148 | |||
149 | 149 | elseif strncmpi(Opt.Input, 'bin', 3) % Accept 'binary' | elseif strncmpi(Opt.Input, 'bin', 3) % Accept 'binary' |
150 | 150 | isBin = true; | isBin = true; |
151 | 151 | if (isnumeric(Data) || ischar(Data) || islogical(Data)) == 0 | if (isnumeric(Data) || ischar(Data) || islogical(Data)) == 0 |
... | ... | if nArg == 2 | |
154 | 154 | end | end |
155 | 155 | end | end |
156 | 156 | end | end |
157 | |||
157 | |||
158 | 158 | elseif nArg ~= 1 % Bad number of arguments: | elseif nArg ~= 1 % Bad number of arguments: |
159 | 159 | error(['JSimon:', mfilename, ':BadNInput'], ... | error(['JSimon:', mfilename, ':BadNInput'], ... |
160 | 160 | '*** %s: 1 or 2 inputs required.', mfilename); | '*** %s: 1 or 2 inputs required.', mfilename); |
... | ... | if isFile | |
178 | 178 | end | end |
179 | 179 | Data = fread(FID, Inf, '*uint8'); | Data = fread(FID, Inf, '*uint8'); |
180 | 180 | fclose(FID); | fclose(FID); |
181 | |||
181 | |||
182 | 182 | Engine.update(Data); | Engine.update(Data); |
183 | 183 | if usetypecastx | if usetypecastx |
184 | 184 | Hash = typecastx(Engine.digest, 'uint8'); | Hash = typecastx(Engine.digest, 'uint8'); |
... | ... | elseif isBin % Contents of an elementary array: | |
197 | 197 | Engine.update(typecastx(imag(Data(:)), 'uint8')); | Engine.update(typecastx(imag(Data(:)), 'uint8')); |
198 | 198 | end | end |
199 | 199 | Hash = typecastx(Engine.digest, 'uint8'); | Hash = typecastx(Engine.digest, 'uint8'); |
200 | |||
200 | |||
201 | 201 | else % Matlab's TYPECAST is less elegant: | else % Matlab's TYPECAST is less elegant: |
202 | 202 | if isnumeric(Data) | if isnumeric(Data) |
203 | 203 | if isreal(Data) | if isreal(Data) |
... | ... | elseif isBin % Contents of an elementary array: | |
214 | 214 | end | end |
215 | 215 | Hash = typecast(Engine.digest, 'uint8'); | Hash = typecast(Engine.digest, 'uint8'); |
216 | 216 | end | end |
217 | |||
217 | |||
218 | 218 | elseif usetypecastx % Faster typecastx: | elseif usetypecastx % Faster typecastx: |
219 | 219 | Engine = CoreHash_(Data, Engine); | Engine = CoreHash_(Data, Engine); |
220 | 220 | Hash = typecastx(Engine.digest, 'uint8'); | Hash = typecastx(Engine.digest, 'uint8'); |
221 | |||
221 | |||
222 | 222 | else % Slower built-in TYPECAST: | else % Slower built-in TYPECAST: |
223 | 223 | Engine = CoreHash(Data, Engine); | Engine = CoreHash(Data, Engine); |
224 | 224 | Hash = typecast(Engine.digest, 'uint8'); | Hash = typecast(Engine.digest, 'uint8'); |
... | ... | Engine.update([uint8(class(Data)), typecastx(size(Data), 'uint8')]); | |
256 | 256 | if isstruct(Data) % Hash for all array elements and fields: | if isstruct(Data) % Hash for all array elements and fields: |
257 | 257 | F = sort(fieldnames(Data)); % Ignore order of fields | F = sort(fieldnames(Data)); % Ignore order of fields |
258 | 258 | Engine = CoreHash_(F, Engine); % Catch the fieldnames | Engine = CoreHash_(F, Engine); % Catch the fieldnames |
259 | |||
259 | |||
260 | 260 | for iS = 1:numel(Data) % Loop over elements of struct array | for iS = 1:numel(Data) % Loop over elements of struct array |
261 | 261 | for iField = 1:length(F) % Loop over fields | for iField = 1:length(F) % Loop over fields |
262 | 262 | Engine = CoreHash_(Data(iS).(F{iField}), Engine); | Engine = CoreHash_(Data(iS).(F{iField}), Engine); |
263 | 263 | end | end |
264 | 264 | end | end |
265 | |||
265 | |||
266 | 266 | elseif iscell(Data) % Get hash for all cell elements: | elseif iscell(Data) % Get hash for all cell elements: |
267 | 267 | for iS = 1:numel(Data) | for iS = 1:numel(Data) |
268 | 268 | Engine = CoreHash_(Data{iS}, Engine); | Engine = CoreHash_(Data{iS}, Engine); |
269 | 269 | end | end |
270 | |||
270 | |||
271 | 271 | elseif isnumeric(Data) || islogical(Data) || ischar(Data) | elseif isnumeric(Data) || islogical(Data) || ischar(Data) |
272 | 272 | if isempty(Data) == 0 | if isempty(Data) == 0 |
273 | 273 | if isreal(Data) % TRUE for LOGICAL and CHAR also: | if isreal(Data) % TRUE for LOGICAL and CHAR also: |
... | ... | elseif isnumeric(Data) || islogical(Data) || ischar(Data) | |
277 | 277 | Engine.update(typecastx(imag(Data(:)), 'uint8')); | Engine.update(typecastx(imag(Data(:)), 'uint8')); |
278 | 278 | end | end |
279 | 279 | end | end |
280 | |||
280 | |||
281 | 281 | elseif isa(Data, 'function_handle') | elseif isa(Data, 'function_handle') |
282 | 282 | Engine = CoreHash(ConvertFuncHandle(Data), Engine); | Engine = CoreHash(ConvertFuncHandle(Data), Engine); |
283 | |||
283 | |||
284 | 284 | else % Most likely this is a user-defined object: | else % Most likely this is a user-defined object: |
285 | 285 | try | try |
286 | 286 | Engine = CoreHash(ConvertObject(Data), Engine); | Engine = CoreHash(ConvertObject(Data), Engine); |
File misc/3rdparty/GetFullPath/GetFullPath.m changed (mode: 100644 -> 100755) (index 79788af..8820f3b) | |||
... | ... | if isempty(hasDataRead) | |
125 | 125 | % ['GetFullPath: Using slow Matlab-version instead of fast Mex.', ... | % ['GetFullPath: Using slow Matlab-version instead of fast Mex.', ... |
126 | 126 | % char(10), 'Compile: InstallMex GetFullPath.c']); | % char(10), 'Compile: InstallMex GetFullPath.c']); |
127 | 127 | %end | %end |
128 | |||
128 | |||
129 | 129 | % DATAREAD is deprecated in 2011b, but still available. In Matlab 6.5, REGEXP | % DATAREAD is deprecated in 2011b, but still available. In Matlab 6.5, REGEXP |
130 | 130 | % does not know the 'split' command, therefore DATAREAD is preferred: | % does not know the 'split' command, therefore DATAREAD is preferred: |
131 | 131 | hasDataRead = ~isempty(which('dataread')); | hasDataRead = ~isempty(which('dataread')); |
... | ... | end | |
149 | 149 | if isWIN % Windows: -------------------------------------------------------- | if isWIN % Windows: -------------------------------------------------------- |
150 | 150 | FSep = '\'; | FSep = '\'; |
151 | 151 | File = strrep(File, '/', FSep); | File = strrep(File, '/', FSep); |
152 | |||
152 | |||
153 | 153 | % Remove the magic key on demand, it is appended finally again: | % Remove the magic key on demand, it is appended finally again: |
154 | 154 | if strncmp(File, '\\?\', 4) | if strncmp(File, '\\?\', 4) |
155 | 155 | if strncmpi(File, '\\?\UNC\', 8) | if strncmpi(File, '\\?\UNC\', 8) |
... | ... | if isWIN % Windows: -------------------------------------------------------- | |
158 | 158 | File = File(5:length(File)); | File = File(5:length(File)); |
159 | 159 | end | end |
160 | 160 | end | end |
161 | |||
161 | |||
162 | 162 | isUNC = strncmp(File, '\\', 2); | isUNC = strncmp(File, '\\', 2); |
163 | 163 | FileLen = length(File); | FileLen = length(File); |
164 | 164 | if isUNC == 0 % File is not a UNC path | if isUNC == 0 % File is not a UNC path |
... | ... | if isWIN % Windows: -------------------------------------------------------- | |
172 | 172 | ThePath = ThePath(1:3); % Drive letter only | ThePath = ThePath(1:3); % Drive letter only |
173 | 173 | end | end |
174 | 174 | end | end |
175 | |||
175 | |||
176 | 176 | if FileLen < 2 || File(2) ~= ':' % Does not start with drive letter | if FileLen < 2 || File(2) ~= ':' % Does not start with drive letter |
177 | 177 | if ThePath(length(ThePath)) ~= FSep | if ThePath(length(ThePath)) ~= FSep |
178 | 178 | if File(1) ~= FSep | if File(1) ~= FSep |
... | ... | if isWIN % Windows: -------------------------------------------------------- | |
188 | 188 | File = [ThePath, File]; | File = [ThePath, File]; |
189 | 189 | end | end |
190 | 190 | end | end |
191 | |||
191 | |||
192 | 192 | elseif FileLen == 2 && File(2) == ':' % "C:" current directory on C! | elseif FileLen == 2 && File(2) == ':' % "C:" current directory on C! |
193 | 193 | % "C:" is the current directory on the C-disk, even if the current | % "C:" is the current directory on the C-disk, even if the current |
194 | 194 | % directory is on another disk! This was ignored in Matlab 6.5, but | % directory is on another disk! This was ignored in Matlab 6.5, but |
... | ... | if isWIN % Windows: -------------------------------------------------------- | |
208 | 208 | end | end |
209 | 209 | end | end |
210 | 210 | end | end |
211 | |||
211 | |||
212 | 212 | else % Linux, MacOS: --------------------------------------------------- | else % Linux, MacOS: --------------------------------------------------- |
213 | 213 | FSep = '/'; | FSep = '/'; |
214 | 214 | File = strrep(File, '\', FSep); | File = strrep(File, '\', FSep); |
215 | |||
215 | |||
216 | 216 | if strcmp(File, '~') || strncmp(File, '~/', 2) % Home directory: | if strcmp(File, '~') || strncmp(File, '~/', 2) % Home directory: |
217 | 217 | HomeDir = getenv('HOME'); | HomeDir = getenv('HOME'); |
218 | 218 | if ~isempty(HomeDir) | if ~isempty(HomeDir) |
219 | 219 | File(1) = []; | File(1) = []; |
220 | 220 | File = [HomeDir, File]; | File = [HomeDir, File]; |
221 | 221 | end | end |
222 | |||
222 | |||
223 | 223 | elseif strncmpi(File, FSep, 1) == 0 | elseif strncmpi(File, FSep, 1) == 0 |
224 | 224 | % Append relative path to current folder: | % Append relative path to current folder: |
225 | 225 | ThePath = cd; | ThePath = cd; |
... | ... | if ~isempty(strfind(File, [FSep, '.'])) | |
251 | 251 | Drive = FSep; | Drive = FSep; |
252 | 252 | File(1) = []; | File(1) = []; |
253 | 253 | end | end |
254 | |||
254 | |||
255 | 255 | hasTrailFSep = (File(length(File)) == FSep); | hasTrailFSep = (File(length(File)) == FSep); |
256 | 256 | if hasTrailFSep | if hasTrailFSep |
257 | 257 | File(length(File)) = []; | File(length(File)) = []; |
258 | 258 | end | end |
259 | |||
259 | |||
260 | 260 | if hasDataRead | if hasDataRead |
261 | 261 | if isWIN % Need "\\" as separator: | if isWIN % Need "\\" as separator: |
262 | 262 | C = dataread('string', File, '%s', 'delimiter', '\\'); %#ok<REMFF1> | C = dataread('string', File, '%s', 'delimiter', '\\'); %#ok<REMFF1> |
... | ... | if ~isempty(strfind(File, [FSep, '.'])) | |
266 | 266 | else % Use the slower REGEXP, when DATAREAD is not available anymore: | else % Use the slower REGEXP, when DATAREAD is not available anymore: |
267 | 267 | C = regexp(File, FSep, 'split'); | C = regexp(File, FSep, 'split'); |
268 | 268 | end | end |
269 | |||
269 | |||
270 | 270 | % Remove '\.\' directly without side effects: | % Remove '\.\' directly without side effects: |
271 | 271 | C(strcmp(C, '.')) = []; | C(strcmp(C, '.')) = []; |
272 | |||
272 | |||
273 | 273 | % Remove '\..' with the parent recursively: | % Remove '\..' with the parent recursively: |
274 | 274 | R = 1:length(C); | R = 1:length(C); |
275 | 275 | for dd = reshape(find(strcmp(C, '..')), 1, []) | for dd = reshape(find(strcmp(C, '..')), 1, []) |
... | ... | if ~isempty(strfind(File, [FSep, '.'])) | |
279 | 279 | R(index - 1) = []; | R(index - 1) = []; |
280 | 280 | end | end |
281 | 281 | end | end |
282 | |||
282 | |||
283 | 283 | if isempty(R) | if isempty(R) |
284 | 284 | File = Drive; | File = Drive; |
285 | 285 | if isUNC && ~hasTrailFSep | if isUNC && ~hasTrailFSep |
286 | 286 | File(length(File)) = []; | File(length(File)) = []; |
287 | 287 | end | end |
288 | |||
288 | |||
289 | 289 | elseif isWIN | elseif isWIN |
290 | 290 | % If you have CStr2String, use the faster: | % If you have CStr2String, use the faster: |
291 | 291 | % File = CStr2String(C(R), FSep, hasTrailFSep); | % File = CStr2String(C(R), FSep, hasTrailFSep); |
... | ... | if ~isempty(strfind(File, [FSep, '.'])) | |
295 | 295 | else | else |
296 | 296 | File = [Drive, File(1:length(File) - 1)]; | File = [Drive, File(1:length(File) - 1)]; |
297 | 297 | end | end |
298 | |||
298 | |||
299 | 299 | else % Unix: | else % Unix: |
300 | 300 | File = [Drive, sprintf('%s/', C{R})]; | File = [Drive, sprintf('%s/', C{R})]; |
301 | 301 | if ~hasTrailFSep | if ~hasTrailFSep |
... | ... | if isWIN | |
310 | 310 | error(['JSimon:', mfilename, ':BadTypeInput2'], ... | error(['JSimon:', mfilename, ':BadTypeInput2'], ... |
311 | 311 | ['*** ', mfilename, ': Input must be a string or cell string']); | ['*** ', mfilename, ': Input must be a string or cell string']); |
312 | 312 | end | end |
313 | |||
313 | |||
314 | 314 | if (strncmpi(Style, 'a', 1) && length(File) >= MAX_PATH) || ... | if (strncmpi(Style, 'a', 1) && length(File) >= MAX_PATH) || ... |
315 | 315 | strncmpi(Style, 'f', 1) | strncmpi(Style, 'f', 1) |
316 | 316 | % Do not use [isUNC] here, because this concerns the input, which can | % Do not use [isUNC] here, because this concerns the input, which can |
File misc/3rdparty/GetFullPath/InstallMex.m changed (mode: 100644 -> 100755) (index c3fc72f..89f88f1) | |||
... | ... | end | |
148 | 148 | Flags = cat(1, Flags(:), Param(:)); | Flags = cat(1, Flags(:), Param(:)); |
149 | 149 | cmd = ['mex', sprintf(' %s', Flags{:})]; | cmd = ['mex', sprintf(' %s', Flags{:})]; |
150 | 150 | fprintf(' %s\n', cmd); | fprintf(' %s\n', cmd); |
151 | |||
151 | |||
152 | 152 | try | try |
153 | 153 | % Start the compilation: | % Start the compilation: |
154 | 154 | cd(SourcePath); | cd(SourcePath); |
155 | 155 | mex(Flags{:}); | mex(Flags{:}); |
156 | 156 | fprintf('Success:\n %s\n', which([SourceName, '.', mexext])); | fprintf('Success:\n %s\n', which([SourceName, '.', mexext])); |
157 | 157 | compiled = true; | compiled = true; |
158 | |||
158 | |||
159 | 159 | catch % No MException to support Matlab 6.5 | catch % No MException to support Matlab 6.5 |
160 | 160 | compiled = false; | compiled = false; |
161 | 161 | err = lasterror; | err = lasterror; |
File misc/3rdparty/GetFullPath/uTest_GetFullPath.m changed (mode: 100644 -> 100755) (index 8003311..f428e99) | |||
... | ... | isWindows = ispc; | |
34 | 34 | ||
35 | 35 | [dum, fName, fExt] = fileparts(whichFunc); %#ok<ASGLU> | [dum, fName, fExt] = fileparts(whichFunc); %#ok<ASGLU> |
36 | 36 | examined = [fName, fExt]; | examined = [fName, fExt]; |
37 | |||
37 | |||
38 | 38 | if isWindows | if isWindows |
39 | 39 | magicLong = '\\?\'; | magicLong = '\\?\'; |
40 | 40 | magicUNC = '\\?\UNC\'; | magicUNC = '\\?\UNC\'; |
... | ... | if isWindows | |
134 | 134 | fullfile(UNCPath, longName, longName), ... % Input | fullfile(UNCPath, longName, longName), ... % Input |
135 | 135 | fullfile(magicUNC, UNCBare, longName, longName); ... % Want | fullfile(magicUNC, UNCBare, longName, longName); ... % Want |
136 | 136 | }); | }); |
137 | |||
137 | |||
138 | 138 | else | else |
139 | 139 | TestSet = cat(1, TestSet, { ... | TestSet = cat(1, TestSet, { ... |
140 | 140 | fullfile(Base, '..', '..'), '/'; ... | fullfile(Base, '..', '..'), '/'; ... |
... | ... | for iTest = 1:size(TestSet, 1) | |
157 | 157 | In_ = strrep(In, longName, longReplace); | In_ = strrep(In, longName, longReplace); |
158 | 158 | Got_ = strrep(Got, longName, longReplace); | Got_ = strrep(Got, longName, longReplace); |
159 | 159 | Want_ = strrep(Want, longName, longReplace); | Want_ = strrep(Want, longName, longReplace); |
160 | |||
160 | |||
161 | 161 | if strcmpi(Got, Want) | if strcmpi(Got, Want) |
162 | 162 | fprintf(' ok: [%s]\n => [%s]\n', In_, Want_); | fprintf(' ok: [%s]\n => [%s]\n', In_, Want_); |
163 | 163 | else | else |
... | ... | for i = depth:-1:2 | |
206 | 206 | try | try |
207 | 207 | cf = GetFullPath(testStr); | cf = GetFullPath(testStr); |
208 | 208 | xfl = fl(:, 1:i - 1); | xfl = fl(:, 1:i - 1); |
209 | |||
209 | |||
210 | 210 | % Construct the reply by hand: | % Construct the reply by hand: |
211 | 211 | cf2 = cat(2, xfl{:}, testFolder); | cf2 = cat(2, xfl{:}, testFolder); |
212 | 212 | if strcmpi(cf, cf2) | if strcmpi(cf, cf2) |
... | ... | for i = depth:-1:2 | |
234 | 234 | try | try |
235 | 235 | cf = GetFullPath(testStr); | cf = GetFullPath(testStr); |
236 | 236 | xfl = fl(:, 1:i - 1); | xfl = fl(:, 1:i - 1); |
237 | |||
237 | |||
238 | 238 | % Construct the reply by hand: | % Construct the reply by hand: |
239 | 239 | cf2 = [cat(2, xfl{:}), testFile]; | cf2 = [cat(2, xfl{:}), testFile]; |
240 | 240 | if strcmpi(cf, cf2) | if strcmpi(cf, cf2) |
... | ... | for i = depth:-1:2 | |
263 | 263 | try | try |
264 | 264 | cf = GetFullPath(testStr); | cf = GetFullPath(testStr); |
265 | 265 | xfl = fl(:, 1:i - 1); | xfl = fl(:, 1:i - 1); |
266 | |||
266 | |||
267 | 267 | % Construct the reply by hand: | % Construct the reply by hand: |
268 | 268 | cf2 = [cat(2, xfl{:}), testFolder]; | cf2 = [cat(2, xfl{:}), testFolder]; |
269 | 269 | if strcmpi(cf, cf2) | if strcmpi(cf, cf2) |
... | ... | for i = depth:-1:2 | |
292 | 292 | try | try |
293 | 293 | cf = GetFullPath(testStr); | cf = GetFullPath(testStr); |
294 | 294 | xfl = fl(:, 1:i - 1); | xfl = fl(:, 1:i - 1); |
295 | |||
295 | |||
296 | 296 | % Construct the reply by hand: | % Construct the reply by hand: |
297 | 297 | cf2 = [cat(2, xfl{:}), testFile]; | cf2 = [cat(2, xfl{:}), testFile]; |
298 | 298 | if strcmpi(cf, cf2) | if strcmpi(cf, cf2) |
... | ... | for i = depth:-1:1 | |
318 | 318 | testStr = [testStr, FSep, '..']; %#ok<AGROW> | testStr = [testStr, FSep, '..']; %#ok<AGROW> |
319 | 319 | try | try |
320 | 320 | cf = GetFullPath(testStr); | cf = GetFullPath(testStr); |
321 | |||
321 | |||
322 | 322 | % Construct the reply by hand: | % Construct the reply by hand: |
323 | 323 | cf2 = CleanReply(testStr); | cf2 = CleanReply(testStr); |
324 | 324 | if strcmpi(cf, cf2) | if strcmpi(cf, cf2) |
... | ... | end | |
342 | 342 | if isWindows | if isWindows |
343 | 343 | fprintf('\n== Test Magic prefix under Windows:\n'); | fprintf('\n== Test Magic prefix under Windows:\n'); |
344 | 344 | MAX_PATH = 260; | MAX_PATH = 260; |
345 | |||
345 | |||
346 | 346 | % Test data folders do not need to exist: | % Test data folders do not need to exist: |
347 | 347 | longName = repmat('a', 1, 250); | longName = repmat('a', 1, 250); |
348 | 348 | testData = {'C:\Temp', fullfile('C:\Temp', longName, longName), ... | testData = {'C:\Temp', fullfile('C:\Temp', longName, longName), ... |
... | ... | if isWindows | |
352 | 352 | '\\Server\Share', ... | '\\Server\Share', ... |
353 | 353 | fullfile('\\Server\Share', longName, longName), ... | fullfile('\\Server\Share', longName, longName), ... |
354 | 354 | 'short', fullfile(longName, longName)}; | 'short', fullfile(longName, longName)}; |
355 | |||
355 | |||
356 | 356 | cd(tempdir); | cd(tempdir); |
357 | |||
357 | |||
358 | 358 | for iTestData = 1:numel(testData) | for iTestData = 1:numel(testData) |
359 | 359 | folder = testData{iTestData}; % Need not exist | folder = testData{iTestData}; % Need not exist |
360 | 360 | leanPath = GetFullPath(folder, 'lean'); | leanPath = GetFullPath(folder, 'lean'); |
361 | 361 | fatPath = GetFullPath(folder, 'fat'); | fatPath = GetFullPath(folder, 'fat'); |
362 | 362 | autoPath = GetFullPath(folder, 'auto'); | autoPath = GetFullPath(folder, 'auto'); |
363 | |||
363 | |||
364 | 364 | fullWant = GetFullPath(folder); | fullWant = GetFullPath(folder); |
365 | 365 | leanWant = strrep(strrep(fullWant, '\\?\UNC', '\'), '\\?\', ''); | leanWant = strrep(strrep(fullWant, '\\?\UNC', '\'), '\\?\', ''); |
366 | 366 | uncIndex = strfind(fullWant, '\Server\Share'); | uncIndex = strfind(fullWant, '\Server\Share'); |
... | ... | if isWindows | |
374 | 374 | else | else |
375 | 375 | autoWant = leanWant; | autoWant = leanWant; |
376 | 376 | end | end |
377 | |||
377 | |||
378 | 378 | if strcmp(leanPath, leanWant) == 0 | if strcmp(leanPath, leanWant) == 0 |
379 | 379 | error(ErrID, '%s: Unexpected name for lean style?! [%s]', ... | error(ErrID, '%s: Unexpected name for lean style?! [%s]', ... |
380 | 380 | mfilename, leanPath); | mfilename, leanPath); |
File misc/3rdparty/Singleton.m changed (mode: 100644) (index 34e24ec..4aa6a56) | |||
... | ... | classdef Singleton < handle | |
24 | 24 | % 1. Constructor must be hidden from the user (Access=private). | % 1. Constructor must be hidden from the user (Access=private). |
25 | 25 | % 2. The concrete implementation of instance() must use a persistent | % 2. The concrete implementation of instance() must use a persistent |
26 | 26 | % variable to store the unique instance of the subclass. | % variable to store the unique instance of the subclass. |
27 | % | ||
27 | % | ||
28 | 28 | % Refer to pp.127-134 Gamma et al.[1] for more information on the | % Refer to pp.127-134 Gamma et al.[1] for more information on the |
29 | 29 | % Singleton Design Pattern. | % Singleton Design Pattern. |
30 | % | ||
30 | % | ||
31 | 31 | % Written by Bobby Nedelkovski | % Written by Bobby Nedelkovski |
32 | 32 | % The MathWorks Australia Pty Ltd | % The MathWorks Australia Pty Ltd |
33 | 33 | % Copyright 2009, The MathWorks, Inc. | % Copyright 2009, The MathWorks, Inc. |
... | ... | classdef Singleton < handle | |
42 | 42 | properties(Access=private) | properties(Access=private) |
43 | 43 | singletonData = []; | singletonData = []; |
44 | 44 | end | end |
45 | |||
45 | |||
46 | 46 | methods(Abstract, Static) | methods(Abstract, Static) |
47 | 47 | % This method serves as the global point of access in creating a | % This method serves as the global point of access in creating a |
48 | 48 | % single instance *or* acquiring a reference to the singleton. | % single instance *or* acquiring a reference to the singleton. |
... | ... | classdef Singleton < handle | |
54 | 54 | % obj = reference to a persistent instance of the class | % obj = reference to a persistent instance of the class |
55 | 55 | obj = instance(); | obj = instance(); |
56 | 56 | end | end |
57 | |||
57 | |||
58 | 58 | methods % Public Access | methods % Public Access |
59 | 59 | % Accessor method for querying the singleton data. | % Accessor method for querying the singleton data. |
60 | 60 | % Input: | % Input: |
... | ... | classdef Singleton < handle | |
64 | 64 | function singletonData = getSingletonData(obj) | function singletonData = getSingletonData(obj) |
65 | 65 | singletonData = obj.singletonData; | singletonData = obj.singletonData; |
66 | 66 | end | end |
67 | |||
67 | |||
68 | 68 | % Accessor method for modifying the singleton data. | % Accessor method for modifying the singleton data. |
69 | 69 | % Input: | % Input: |
70 | 70 | % obj = reference to the singleton instance of the subclass | % obj = reference to the singleton instance of the subclass |
... | ... | classdef Singleton < handle | |
74 | 74 | function setSingletonData(obj, singletonData) | function setSingletonData(obj, singletonData) |
75 | 75 | obj.singletonData = singletonData; | obj.singletonData = singletonData; |
76 | 76 | end | end |
77 | |||
77 | |||
78 | 78 | end | end |
79 | 79 | ||
80 | 80 | end | end |
File misc/3rdparty/allcomb.m changed (mode: 100644) (index a200cc3..5e5ea44) | |||
... | ... | function A = allcomb(varargin) | |
33 | 33 | % % 'Bye' [1x3 double] [] } ; % a 8-by-3 cell array | % % 'Bye' [1x3 double] [] } ; % a 8-by-3 cell array |
34 | 34 | % | % |
35 | 35 | % ALLCOMB(..., 'matlab') causes the first column to change fastest which | % ALLCOMB(..., 'matlab') causes the first column to change fastest which |
36 | % is consistent with matlab indexing. Example: | ||
37 | % allcomb(1:2,3:4,5:6,'matlab') | ||
36 | % is consistent with matlab indexing. Example: | ||
37 | % allcomb(1:2,3:4,5:6,'matlab') | ||
38 | 38 | % % -> [ 1 3 5 ; 1 4 5 ; 1 3 6 ; ... ; 2 4 6 ] | % % -> [ 1 3 5 ; 1 4 5 ; 1 3 6 ; ... ; 2 4 6 ] |
39 | 39 | % | % |
40 | 40 | % If one of the arguments is empty, ALLCOMB returns a 0-by-N empty array. | % If one of the arguments is empty, ALLCOMB returns a 0-by-N empty array. |
41 | % | ||
41 | % | ||
42 | 42 | % See also NCHOOSEK, PERMS, NDGRID | % See also NCHOOSEK, PERMS, NDGRID |
43 | 43 | % and NCHOOSE, COMBN, KTHCOMBN (Matlab Central FEX) | % and NCHOOSE, COMBN, KTHCOMBN (Matlab Central FEX) |
44 | 44 | ||
... | ... | elseif NC > 1 | |
90 | 90 | end | end |
91 | 91 | % for cell input, we use to indices to get all combinations | % for cell input, we use to indices to get all combinations |
92 | 92 | ix = cellfun(@(c) 1:numel(c), args,'un',0) ; | ix = cellfun(@(c) 1:numel(c), args,'un',0) ; |
93 | |||
93 | |||
94 | 94 | % flip using ii if last column is changing fastest | % flip using ii if last column is changing fastest |
95 | 95 | [ix{ii}] = ndgrid(ix{ii}) ; | [ix{ii}] = ndgrid(ix{ii}) ; |
96 | |||
96 | |||
97 | 97 | A = cell(numel(ix{1}),NC) ; % pre-allocate the output | A = cell(numel(ix{1}),NC) ; % pre-allocate the output |
98 | 98 | for k=1:NC, | for k=1:NC, |
99 | 99 | % combine | % combine |
File misc/3rdparty/allcomb_invert.m changed (mode: 100644) (index d18d9c8..47866d8) | |||
1 | 1 | function factorlist = allcomb_invert(array) | function factorlist = allcomb_invert(array) |
2 | % invert the Cartesian product: | ||
3 | % if array = allcomb(list_1, ..., list_n), return list_1, ..., list_n (column vectors) | ||
4 | [elems, list_no] = size(array); | ||
5 | factorlist = {}; | ||
6 | if isequal(class(array),'double') | ||
7 | for k=1:list_no | ||
8 | factorlist{k} = unique(array(:,k), 'stable'); | ||
9 | end | ||
10 | % functionality for handling nonnumeric input does not work yet | ||
11 | % elseif isequal(class(array),'cell') | ||
12 | % for k=1:list_no | ||
13 | % factorlist{k} = unique({array{:,k}}, 'stable'); | ||
14 | % end | ||
15 | else | ||
16 | error('Input to allcomb_invert must be cell array or double array'); | ||
17 | end | ||
2 | % invert the Cartesian product: | ||
3 | % if array = allcomb(list_1, ..., list_n), return list_1, ..., list_n (column vectors) | ||
4 | [elems, list_no] = size(array); | ||
5 | factorlist = {}; | ||
6 | if isequal(class(array),'double') | ||
7 | for k=1:list_no | ||
8 | factorlist{k} = unique(array(:,k), 'stable'); | ||
9 | end | ||
10 | % functionality for handling nonnumeric input does not work yet | ||
11 | % elseif isequal(class(array),'cell') | ||
12 | % for k=1:list_no | ||
13 | % factorlist{k} = unique({array{:,k}}, 'stable'); | ||
14 | % end | ||
15 | else | ||
16 | error('Input to allcomb_invert must be cell array or double array'); | ||
17 | end |
File misc/3rdparty/allcomb_invert_test.m changed (mode: 100644) (index 7c517ab..df8d045) | |||
1 | 1 | function test_suite = allcomb_invert_test %#ok<STOUT> | function test_suite = allcomb_invert_test %#ok<STOUT> |
2 | initTestSuite; | ||
2 | initTestSuite; | ||
3 | 3 | ||
4 | 4 | function two_dimensional_numeric_test | function two_dimensional_numeric_test |
5 | list_1 = [1:2]'; | ||
6 | list_2 = [10:12]'; | ||
7 | lists = {list_1, list_2}; | ||
5 | list_1 = [1:2]'; | ||
6 | list_2 = [10:12]'; | ||
7 | lists = {list_1, list_2}; | ||
8 | 8 | ||
9 | cartprod = allcomb(lists{:}); | ||
10 | factorlist = allcomb_invert(cartprod); | ||
11 | assertEqual(factorlist, lists) | ||
9 | cartprod = allcomb(lists{:}); | ||
10 | factorlist = allcomb_invert(cartprod); | ||
11 | assertEqual(factorlist, lists) | ||
12 | 12 | ||
13 | 13 | function two_dimensional_numeric_unsorted_test | function two_dimensional_numeric_unsorted_test |
14 | list_1 = [1; 2]; | ||
15 | list_2 = [11; 10; 12]; | ||
16 | lists = {list_1, list_2}; | ||
14 | list_1 = [1; 2]; | ||
15 | list_2 = [11; 10; 12]; | ||
16 | lists = {list_1, list_2}; | ||
17 | 17 | ||
18 | cartprod = allcomb(lists{:}); | ||
19 | factorlist = allcomb_invert(cartprod); | ||
20 | assertEqual(factorlist, lists) | ||
18 | cartprod = allcomb(lists{:}); | ||
19 | factorlist = allcomb_invert(cartprod); | ||
20 | assertEqual(factorlist, lists) | ||
21 | 21 | ||
22 | 22 | function two_dimensional_singleton_test | function two_dimensional_singleton_test |
23 | list_1 = 1; | ||
24 | list_2 = [10:12]'; | ||
25 | lists = {list_1, list_2}; | ||
23 | list_1 = 1; | ||
24 | list_2 = [10:12]'; | ||
25 | lists = {list_1, list_2}; | ||
26 | 26 | ||
27 | cartprod = allcomb(lists{:}); | ||
28 | factorlist = allcomb_invert(cartprod); | ||
29 | assertEqual(factorlist, lists) | ||
27 | cartprod = allcomb(lists{:}); | ||
28 | factorlist = allcomb_invert(cartprod); | ||
29 | assertEqual(factorlist, lists) | ||
30 | 30 | ||
31 | 31 | function three_dimensional_numeric_test | function three_dimensional_numeric_test |
32 | list_1 = [1; 2]; | ||
33 | list_2 = [11; 10; 12]; | ||
34 | list_3 = [11; 100; -12; 1]; | ||
35 | lists = {list_1, list_2, list_3}; | ||
32 | list_1 = [1; 2]; | ||
33 | list_2 = [11; 10; 12]; | ||
34 | list_3 = [11; 100; -12; 1]; | ||
35 | lists = {list_1, list_2, list_3}; | ||
36 | 36 | ||
37 | cartprod = allcomb(lists{:}); | ||
38 | factorlist = allcomb_invert(cartprod); | ||
39 | assertEqual(factorlist, lists) | ||
37 | cartprod = allcomb(lists{:}); | ||
38 | factorlist = allcomb_invert(cartprod); | ||
39 | assertEqual(factorlist, lists) | ||
40 | 40 | ||
41 | 41 | function random_numeric_test | function random_numeric_test |
42 | list_1 = randn(10,1); | ||
43 | list_2 = randn(10,1); | ||
44 | list_3 = randn(10,1); | ||
45 | lists = {list_1, list_2, list_3}; | ||
46 | |||
47 | cartprod = allcomb(lists{:}); | ||
48 | factorlist = allcomb_invert(cartprod); | ||
49 | assertEqual(factorlist, lists) | ||
42 | list_1 = randn(10,1); | ||
43 | list_2 = randn(10,1); | ||
44 | list_3 = randn(10,1); | ||
45 | lists = {list_1, list_2, list_3}; | ||
46 | |||
47 | cartprod = allcomb(lists{:}); | ||
48 | factorlist = allcomb_invert(cartprod); | ||
49 | assertEqual(factorlist, lists) | ||
50 | 50 | ||
51 | 51 | % % functionality for handling nonnumeric input does not work yet | % % functionality for handling nonnumeric input does not work yet |
52 | 52 | % function two_dimensional_nonnumeric_test | % function two_dimensional_nonnumeric_test |
File misc/3rdparty/bplot.m changed (mode: 100644) (index 24b1c7b..cedb79a) | |||
1 | 1 | % function forLegend = bplot(X,varargin) | % function forLegend = bplot(X,varargin) |
2 | 2 | % This function will create a nice boxplot from a set of data. You don't | % This function will create a nice boxplot from a set of data. You don't |
3 | 3 | % need any toolboxes. | % need any toolboxes. |
4 | % | ||
4 | % | ||
5 | 5 | % bplot(D) will create a boxplot of data D, no fuss. | % bplot(D) will create a boxplot of data D, no fuss. |
6 | % | ||
6 | % | ||
7 | 7 | % T = bplot(D) If X is a matrix, there is one box per column; if X is a | % T = bplot(D) If X is a matrix, there is one box per column; if X is a |
8 | 8 | % vector, there is just one box. On each box, the central | % vector, there is just one box. On each box, the central |
9 | 9 | % mark is the median, the edges of the box are the 25th and | % mark is the median, the edges of the box are the 25th and |
10 | 10 | % 75th percentiles | % 75th percentiles |
11 | 11 | % array 'T' for a legend. You can add the legend as legend(T) | % array 'T' for a legend. You can add the legend as legend(T) |
12 | % | ||
12 | % | ||
13 | 13 | % T = bplot(D,x) will plot the boxplot of data D above the 'x' value x | % T = bplot(D,x) will plot the boxplot of data D above the 'x' value x |
14 | % | ||
14 | % | ||
15 | 15 | % T = bplot(D,y,'horiz') will plot a horizontal boxplot at the 'y' value of y | % T = bplot(D,y,'horiz') will plot a horizontal boxplot at the 'y' value of y |
16 | % | ||
16 | % | ||
17 | 17 | % T = bplot(...,'Property', . . . ) | % T = bplot(...,'Property', . . . ) |
18 | 18 | % T = bplot(...,'PropertyName',PropertyValue, . . . ) | % T = bplot(...,'PropertyName',PropertyValue, . . . ) |
19 | % | ||
19 | % | ||
20 | 20 | % SINGLE PARAMETERS: | % SINGLE PARAMETERS: |
21 | % | ||
21 | % | ||
22 | 22 | % 'horizontal': Display the boxplot along the horizontal axis. The | % 'horizontal': Display the boxplot along the horizontal axis. The |
23 | 23 | % default is to display the boxplot vertically. | % default is to display the boxplot vertically. |
24 | 24 | % 'horiz' | % 'horiz' |
45 | 45 | % 'boxes','boxedge' | % 'boxes','boxedge' |
46 | 46 | % 'whisker': Set the percentage of points that the whiskers | % 'whisker': Set the percentage of points that the whiskers |
47 | 47 | % span. Default is the 9% and 91%. Choose only the | % span. Default is the 9% and 91%. Choose only the |
48 | % lower number in %, for example: 9. | ||
48 | % lower number in %, for example: 9. | ||
49 | 49 | % 'whiskers','whiskeredge' | % 'whiskers','whiskeredge' |
50 | 50 | % 'linewidth': Set the width of all the lines. | % 'linewidth': Set the width of all the lines. |
51 | 51 | % 'color': Change the color of all the lines. If you use this | % 'color': Change the color of all the lines. If you use this |
57 | 57 | % horizontal plots the height is 1.5/20 of the y axis | % horizontal plots the height is 1.5/20 of the y axis |
58 | 58 | % the bars. | % the bars. |
59 | 59 | % 'barwidth' | % 'barwidth' |
60 | % | ||
61 | %% Jitter feature | ||
60 | % | ||
61 | %% Jitter feature | ||
62 | 62 | % The boxplot has a cool jitter feature which will help you view each | % The boxplot has a cool jitter feature which will help you view each |
63 | 63 | % outlier separately even if two have identical values. It jitters the | % outlier separately even if two have identical values. It jitters the |
64 | 64 | % points around the other axis so that you can see exactly how many are | % points around the other axis so that you can see exactly how many are |
65 | 65 | % there. | % there. |
66 | % | ||
67 | % % Examples: | ||
66 | % | ||
67 | % % Examples: | ||
68 | 68 | % bplot(randn(30,3),'outliers') | % bplot(randn(30,3),'outliers') |
69 | 69 | % bplot(randn(30,3),'color','black'); | % bplot(randn(30,3),'color','black'); |
70 | 70 | % ---- | % ---- |
71 | 71 | % X = round(randn(30,4)*5)/5; % random, with some duplicates | % X = round(randn(30,4)*5)/5; % random, with some duplicates |
72 | 72 | % T = bplot(X,'points'); | % T = bplot(X,'points'); |
73 | 73 | % legend(T,'location','eastoutside'); | % legend(T,'location','eastoutside'); |
74 | % | ||
74 | % | ||
75 | 75 | %% development notes: | %% development notes: |
76 | 76 | % This function was developed to be part of a larger histogram function | % This function was developed to be part of a larger histogram function |
77 | 77 | % which can be found at this location: | % which can be found at this location: |
78 | 78 | % http://www.mathworks.com/matlabcentral/fileexchange/27388-plot-and-compare-histograms-pretty-by-default | % http://www.mathworks.com/matlabcentral/fileexchange/27388-plot-and-compare-histograms-pretty-by-default |
79 | % | ||
79 | % | ||
80 | 80 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
81 | 81 | % Jonathan Lansey 2013, % | % Jonathan Lansey 2013, % |
82 | 82 | % questions to Lansey at gmail.com % | % questions to Lansey at gmail.com % |
83 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
83 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
84 | 84 | %% | %% |
85 | 85 | function [forLegend, boxEdge, wisEdge] = bplot(x,varargin) | function [forLegend, boxEdge, wisEdge] = bplot(x,varargin) |
86 | 86 | %% save the initial hold state of the figure. | %% save the initial hold state of the figure. |
... | ... | function [forLegend, boxEdge, wisEdge] = bplot(x,varargin) | |
145 | 145 | ||
146 | 146 | %% Initialize some things before accepting user parameters | %% Initialize some things before accepting user parameters |
147 | 147 | horizontalFlag=0; | horizontalFlag=0; |
148 | barFactor=1; % | ||
148 | barFactor=1; % | ||
149 | 149 | linewidth=2; | linewidth=2; |
150 | 150 | forceNoLegend=0; % will any legend items be allowed in. | forceNoLegend=0; % will any legend items be allowed in. |
151 | 151 | stdFlag = 0; | stdFlag = 0; |
152 | 152 | meanFlag = 1; | meanFlag = 1; |
153 | specialWidthFlag = 0; % this flag will determine whether the bar width is | ||
153 | specialWidthFlag = 0; % this flag will determine whether the bar width is | ||
154 | 154 | % automatically set as a proportion of the axis width | % automatically set as a proportion of the axis width |
155 | 155 | ||
156 | toScale = 0; % this flag is to scale the jitter function in case the | ||
156 | toScale = 0; % this flag is to scale the jitter function in case the | ||
157 | 157 | % histogram function is calling it | % histogram function is calling it |
158 | 158 | xoffset = 0; | xoffset = 0; |
159 | 159 | if justOneInputFlag | if justOneInputFlag |
... | ... | function [forLegend, boxEdge, wisEdge] = bplot(x,varargin) | |
273 | 273 | hReg2(end+1) = rectangle('Position',[y-barWidth/2,boxEdge(1),barWidth,IQR],'linewidth',linewidth,... | hReg2(end+1) = rectangle('Position',[y-barWidth/2,boxEdge(1),barWidth,IQR],'linewidth',linewidth,... |
274 | 274 | 'EdgeColor',boxColor, 'facecolor',[1 1 1]); | 'EdgeColor',boxColor, 'facecolor',[1 1 1]); |
275 | 275 | hold on; | hold on; |
276 | |||
276 | |||
277 | 277 | hReg2(end+1) = plot([y-barWidth/2 y+barWidth/2],[medianX medianX],'color',meanColor,'linewidth',linewidth); | hReg2(end+1) = plot([y-barWidth/2 y+barWidth/2],[medianX medianX],'color',meanColor,'linewidth',linewidth); |
278 | 278 | if meanFlag | if meanFlag |
279 | 279 | hReg2(end+1) = plot(y,meanX,'+','linewidth',linewidth,'color',meanColor,'markersize',10); | hReg2(end+1) = plot(y,meanX,'+','linewidth',linewidth,'color',meanColor,'markersize',10); |
... | ... | function [forLegend, boxEdge, wisEdge] = bplot(x,varargin) | |
314 | 314 | end | end |
315 | 315 | end | end |
316 | 316 | end | end |
317 | %% Remove the legend entries | ||
317 | %% Remove the legend entries | ||
318 | 318 | % remove extras for all the items. | % remove extras for all the items. |
319 | 319 | for ii=1:length(hReg) | for ii=1:length(hReg) |
320 | 320 | set(get(get(hReg(ii),'Annotation'),'LegendInformation'),'IconDisplayStyle','off'); % Exclude line from legend | set(get(get(hReg(ii),'Annotation'),'LegendInformation'),'IconDisplayStyle','off'); % Exclude line from legend |
... | ... | function [forLegend, boxEdge, wisEdge] = bplot(x,varargin) | |
338 | 338 | padxfac = 2; | padxfac = 2; |
339 | 339 | padyfac = .1; | padyfac = .1; |
340 | 340 | end | end |
341 | |||
341 | |||
342 | 342 | axis tight; | axis tight; |
343 | 343 | p = axis; | p = axis; |
344 | 344 | padx = (p(2)-p(1))*padxfac; pady = (p(4)-p(3))*padyfac; | padx = (p(2)-p(1))*padxfac; pady = (p(4)-p(3))*padyfac; |
File misc/3rdparty/brewermap.m changed (mode: 100644) (index 98eacf9..0494e1b) | |||
... | ... | persistent dcs | |
135 | 135 | str = 'A colorscheme must be preselected before calling without a scheme token.'; | str = 'A colorscheme must be preselected before calling without a scheme token.'; |
136 | 136 | % | % |
137 | 137 | if nargin==0 % Current figure's colormap length and the preselected colorscheme. | if nargin==0 % Current figure's colormap length and the preselected colorscheme. |
138 | assert(~isempty(dcs),str) | ||
139 | [map,num,typ] = cbSample([],dcs); | ||
138 | assert(~isempty(dcs),str) | ||
139 | [map,num,typ] = cbSample([],dcs); | ||
140 | 140 | elseif nargin==2 % Input colormap length and colorscheme. | elseif nargin==2 % Input colormap length and colorscheme. |
141 | assert(isnumeric(N),'The first argument must be a numeric scalar, or empty.') | ||
142 | assert(ischar(scheme)&&isrow(scheme),'The second argument must be a string.') | ||
143 | [map,num,typ] = cbSample(N,scheme); | ||
141 | assert(isnumeric(N),'The first argument must be a numeric scalar, or empty.') | ||
142 | assert(ischar(scheme)&&isrow(scheme),'The second argument must be a string.') | ||
143 | [map,num,typ] = cbSample(N,scheme); | ||
144 | 144 | elseif isnumeric(N) % Input colormap length and the preselected colorscheme. | elseif isnumeric(N) % Input colormap length and the preselected colorscheme. |
145 | assert(~isempty(dcs),str) | ||
146 | [map,num,typ] = cbSample(N,dcs); | ||
145 | assert(~isempty(dcs),str) | ||
146 | [map,num,typ] = cbSample(N,dcs); | ||
147 | 147 | else% String | else% String |
148 | assert(ischar(N)&&isrow(N),'The first argument must be a string or numeric.') | ||
149 | % The order of <vec>: case-insensitive sort by type and then name. | ||
150 | vec = {'BrBG';'PiYG';'PRGn';'PuOr';'RdBu';'RdGy';'RdYlBu';'RdYlGn';'Spectral';'Accent';'Dark2';'Paired';'Pastel1';'Pastel2';'Set1';'Set2';'Set3';'Blues';'BuGn';'BuPu';'GnBu';'Greens';'Greys';'OrRd';'Oranges';'PuBu';'PuBuGn';'PuRd';'Purples';'RdPu';'Reds';'YlGn';'YlGnBu';'YlOrBr';'YlOrRd'}; | ||
151 | switch lower(N) | ||
152 | case 'demo' % Plot all colorschemes in a figure. | ||
153 | cbDemoFig(vec) | ||
154 | case 'list' % Return a list of all colorschemes. | ||
155 | [num,typ] = cellfun(@cbSelect,vec,'UniformOutput',false); | ||
156 | num = cat(1,num{:}); | ||
157 | map = vec; | ||
158 | otherwise % Store the preselected colorscheme token. | ||
159 | map = dcs; | ||
160 | isr = strncmp('*',N,1); | ||
161 | scm = N(1+isr:end); | ||
162 | [num,typ] = cbSelect(scm); | ||
163 | dcs = [N(1:+isr),vec{strcmpi(vec,scm)}]; | ||
164 | end | ||
148 | assert(ischar(N)&&isrow(N),'The first argument must be a string or numeric.') | ||
149 | % The order of <vec>: case-insensitive sort by type and then name. | ||
150 | vec = {'BrBG';'PiYG';'PRGn';'PuOr';'RdBu';'RdGy';'RdYlBu';'RdYlGn';'Spectral';'Accent';'Dark2';'Paired';'Pastel1';'Pastel2';'Set1';'Set2';'Set3';'Blues';'BuGn';'BuPu';'GnBu';'Greens';'Greys';'OrRd';'Oranges';'PuBu';'PuBuGn';'PuRd';'Purples';'RdPu';'Reds';'YlGn';'YlGnBu';'YlOrBr';'YlOrRd'}; | ||
151 | switch lower(N) | ||
152 | case 'demo' % Plot all colorschemes in a figure. | ||
153 | cbDemoFig(vec) | ||
154 | case 'list' % Return a list of all colorschemes. | ||
155 | [num,typ] = cellfun(@cbSelect,vec,'UniformOutput',false); | ||
156 | num = cat(1,num{:}); | ||
157 | map = vec; | ||
158 | otherwise % Store the preselected colorscheme token. | ||
159 | map = dcs; | ||
160 | isr = strncmp('*',N,1); | ||
161 | scm = N(1+isr:end); | ||
162 | [num,typ] = cbSelect(scm); | ||
163 | dcs = [N(1:+isr),vec{strcmpi(vec,scm)}]; | ||
164 | end | ||
165 | 165 | end | end |
166 | 166 | % | % |
167 | 167 | end | end |
... | ... | function [map,num,typ] = cbSample(N,tok) | |
170 | 170 | % Pick a colorscheme, downsample/interpolate to the requested colormap length. | % Pick a colorscheme, downsample/interpolate to the requested colormap length. |
171 | 171 | % | % |
172 | 172 | if isempty(N) | if isempty(N) |
173 | N = size(get(gcf,'colormap'),1); | ||
173 | N = size(get(gcf,'colormap'),1); | ||
174 | 174 | else | else |
175 | assert(isscalar(N)&&isreal(N),'First argument must be a real numeric scalar, or empty.') | ||
175 | assert(isscalar(N)&&isreal(N),'First argument must be a real numeric scalar, or empty.') | ||
176 | 176 | end | end |
177 | 177 | % | % |
178 | 178 | % obtain nodes: | % obtain nodes: |
... | ... | tok = tok(1+isr:end); | |
183 | 183 | map = rgb(cbIndex(N,num,typ,tok,isr),:); | map = rgb(cbIndex(N,num,typ,tok,isr),:); |
184 | 184 | % interpolate: | % interpolate: |
185 | 185 | if N>num | if N>num |
186 | map = interp1(1:num,map,linspace(1,num,N),'pchip'); | ||
186 | map = interp1(1:num,map,linspace(1,num,N),'pchip'); | ||
187 | 187 | end | end |
188 | 188 | % | % |
189 | 189 | end | end |
... | ... | xmx = max(cellfun(@cbSelect,seq)); | |
197 | 197 | ymx = numel(seq); | ymx = numel(seq); |
198 | 198 | % | % |
199 | 199 | if ishghandle(cbh) | if ishghandle(cbh) |
200 | figure(cbh); | ||
201 | delete(axh); | ||
200 | figure(cbh); | ||
201 | delete(axh); | ||
202 | 202 | else | else |
203 | cbh = figure('HandleVisibility','callback', 'IntegerHandle','off',... | ||
204 | 'NumberTitle','off', 'Name',[mfilename,' Demo'],'Color','white'); | ||
203 | cbh = figure('HandleVisibility','callback', 'IntegerHandle','off',... | ||
204 | 'NumberTitle','off', 'Name',[mfilename,' Demo'],'Color','white'); | ||
205 | 205 | end | end |
206 | 206 | % | % |
207 | 207 | axh = axes('Parent',cbh, 'Color','none',... | axh = axes('Parent',cbh, 'Color','none',... |
208 | 'XTick',0:xmx, 'YTick',0.5:ymx, 'YTickLabel',seq, 'YDir','reverse'); | ||
208 | 'XTick',0:xmx, 'YTick',0.5:ymx, 'YTickLabel',seq, 'YDir','reverse'); | ||
209 | 209 | title(axh,['ColorBrewer Color Schemes (',mfilename,'.m)'], 'Interpreter','none') | title(axh,['ColorBrewer Color Schemes (',mfilename,'.m)'], 'Interpreter','none') |
210 | 210 | xlabel(axh,'Scheme Nodes') | xlabel(axh,'Scheme Nodes') |
211 | 211 | ylabel(axh,'Scheme Name') | ylabel(axh,'Scheme Name') |
212 | 212 | axf = get(axh,'FontName'); | axf = get(axh,'FontName'); |
213 | 213 | % | % |
214 | 214 | for y = 1:ymx | for y = 1:ymx |
215 | [num,typ,rgb] = cbSelect(seq{y}); | ||
216 | rgb = rgb(cbIndex(num,num,typ,seq{y},false),:); % downsample | ||
217 | for x = 1:num | ||
218 | patch([x-1,x-1,x,x],[y-1,y,y,y-1],1, 'FaceColor',rgb(x,:), 'Parent',axh) | ||
219 | end | ||
220 | text(xmx+0.1,y-0.5,typ, 'Parent',axh, 'FontName',axf) | ||
215 | [num,typ,rgb] = cbSelect(seq{y}); | ||
216 | rgb = rgb(cbIndex(num,num,typ,seq{y},false),:); % downsample | ||
217 | for x = 1:num | ||
218 | patch([x-1,x-1,x,x],[y-1,y,y,y-1],1, 'FaceColor',rgb(x,:), 'Parent',axh) | ||
219 | end | ||
220 | text(xmx+0.1,y-0.5,typ, 'Parent',axh, 'FontName',axf) | ||
221 | 221 | end | end |
222 | 222 | % | % |
223 | 223 | end | end |
... | ... | function idx = cbIndex(N,num,typ,tok,isr) | |
226 | 226 | % Ensure exactly the same colors as in the online ColorBrewer schemes. | % Ensure exactly the same colors as in the online ColorBrewer schemes. |
227 | 227 | % | % |
228 | 228 | if strcmp(typ,'Qualitative') | if strcmp(typ,'Qualitative') |
229 | assert(N<=num,'Colorscheme "%s" maximum colormap length: %d. Requested: %d.',tok,num,N) | ||
230 | idx = 1:N; | ||
229 | assert(N<=num,'Colorscheme "%s" maximum colormap length: %d. Requested: %d.',tok,num,N) | ||
230 | idx = 1:N; | ||
231 | 231 | elseif strcmp(typ,'Diverging') | elseif strcmp(typ,'Diverging') |
232 | switch min(N,num) | ||
233 | case 1 % extrapolated | ||
234 | idx = 8; | ||
235 | case 2 % extrapolated | ||
236 | idx = [4,12]; | ||
237 | case 3 | ||
238 | idx = [5,8,11]; | ||
239 | case 4 | ||
240 | idx = [3,6,10,13]; | ||
241 | case 5 | ||
242 | idx = [3,6,8,10,13]; | ||
243 | case 6 | ||
244 | idx = [2,5,7,9,11,14]; | ||
245 | case 7 | ||
246 | idx = [2,5,7,8,9,11,14]; | ||
247 | case 8 | ||
248 | idx = [2,4,6,7,9,10,12,14]; | ||
249 | case 9 | ||
250 | idx = [2,4,6,7,8,9,10,12,14]; | ||
251 | case 10 | ||
252 | idx = [1,2,4,6,7,9,10,12,14,15]; | ||
253 | case 11 | ||
254 | idx = [1,2,4,6,7,8,9,10,12,14,15]; | ||
255 | end | ||
232 | switch min(N,num) | ||
233 | case 1 % extrapolated | ||
234 | idx = 8; | ||
235 | case 2 % extrapolated | ||
236 | idx = [4,12]; | ||
237 | case 3 | ||
238 | idx = [5,8,11]; | ||
239 | case 4 | ||
240 | idx = [3,6,10,13]; | ||
241 | case 5 | ||
242 | idx = [3,6,8,10,13]; | ||
243 | case 6 | ||
244 | idx = [2,5,7,9,11,14]; | ||
245 | case 7 | ||
246 | idx = [2,5,7,8,9,11,14]; | ||
247 | case 8 | ||
248 | idx = [2,4,6,7,9,10,12,14]; | ||
249 | case 9 | ||
250 | idx = [2,4,6,7,8,9,10,12,14]; | ||
251 | case 10 | ||
252 | idx = [1,2,4,6,7,9,10,12,14,15]; | ||
253 | case 11 | ||
254 | idx = [1,2,4,6,7,8,9,10,12,14,15]; | ||
255 | end | ||
256 | 256 | elseif strcmp(typ,'Sequential') | elseif strcmp(typ,'Sequential') |
257 | switch min(N,num) | ||
258 | case 1 % extrapolated | ||
259 | idx = 6; | ||
260 | case 2 % extrapolated | ||
261 | idx = [4,8]; | ||
262 | case 3 | ||
263 | idx = [3,6,9]; | ||
264 | case 4 | ||
265 | idx = [2,5,7,10]; | ||
266 | case 5 | ||
267 | idx = [2,5,7,9,11]; | ||
268 | case 6 | ||
269 | idx = [2,4,6,7,9,11]; | ||
270 | case 7 | ||
271 | idx = [2,4,6,7,8,10,12]; | ||
272 | case 8 | ||
273 | idx = [1,3,4,6,7,8,10,12]; | ||
274 | case 9 | ||
275 | idx = [1,3,4,6,7,8,10,11,13]; | ||
276 | end | ||
257 | switch min(N,num) | ||
258 | case 1 % extrapolated | ||
259 | idx = 6; | ||
260 | case 2 % extrapolated | ||
261 | idx = [4,8]; | ||
262 | case 3 | ||
263 | idx = [3,6,9]; | ||
264 | case 4 | ||
265 | idx = [2,5,7,10]; | ||
266 | case 5 | ||
267 | idx = [2,5,7,9,11]; | ||
268 | case 6 | ||
269 | idx = [2,4,6,7,9,11]; | ||
270 | case 7 | ||
271 | idx = [2,4,6,7,8,10,12]; | ||
272 | case 8 | ||
273 | idx = [1,3,4,6,7,8,10,12]; | ||
274 | case 9 | ||
275 | idx = [1,3,4,6,7,8,10,11,13]; | ||
276 | end | ||
277 | 277 | else | else |
278 | error('The colorscheme type "%s" is not recognized',typ) | ||
278 | error('The colorscheme type "%s" is not recognized',typ) | ||
279 | 279 | end | end |
280 | 280 | % | % |
281 | 281 | if isr | if isr |
282 | idx = idx(end:-1:1); | ||
282 | idx = idx(end:-1:1); | ||
283 | 283 | end | end |
284 | 284 | % | % |
285 | 285 | end | end |
... | ... | function [num,typ,rgb] = cbSelect(tok) | |
289 | 289 | % | % |
290 | 290 | switch lower(tok) % ColorName | switch lower(tok) % ColorName |
291 | 291 | case 'brbg' % BrBG | case 'brbg' % BrBG |
292 | rgb = [84,48,5;140,81,10;166,97,26;191,129,45;216,179,101;223,194,125;246,232,195;245,245,245;199,234,229;128,205,193;90,180,172;53,151,143;1,133,113;1,102,94;0,60,48]; | ||
293 | typ = 'Diverging'; | ||
292 | rgb = [84,48,5;140,81,10;166,97,26;191,129,45;216,179,101;223,194,125;246,232,195;245,245,245;199,234,229;128,205,193;90,180,172;53,151,143;1,133,113;1,102,94;0,60,48]; | ||
293 | typ = 'Diverging'; | ||
294 | 294 | case 'piyg' % PiYG | case 'piyg' % PiYG |
295 | rgb = [142,1,82;197,27,125;208,28,139;222,119,174;233,163,201;241,182,218;253,224,239;247,247,247;230,245,208;184,225,134;161,215,106;127,188,65;77,172,38;77,146,33;39,100,25]; | ||
296 | typ = 'Diverging'; | ||
295 | rgb = [142,1,82;197,27,125;208,28,139;222,119,174;233,163,201;241,182,218;253,224,239;247,247,247;230,245,208;184,225,134;161,215,106;127,188,65;77,172,38;77,146,33;39,100,25]; | ||
296 | typ = 'Diverging'; | ||
297 | 297 | case 'prgn' % PRGn | case 'prgn' % PRGn |
298 | rgb = [64,0,75;118,42,131;123,50,148;153,112,171;175,141,195;194,165,207;231,212,232;247,247,247;217,240,211;166,219,160;127,191,123;90,174,97;0,136,55;27,120,55;0,68,27]; | ||
299 | typ = 'Diverging'; | ||
298 | rgb = [64,0,75;118,42,131;123,50,148;153,112,171;175,141,195;194,165,207;231,212,232;247,247,247;217,240,211;166,219,160;127,191,123;90,174,97;0,136,55;27,120,55;0,68,27]; | ||
299 | typ = 'Diverging'; | ||
300 | 300 | case 'puor' % PuOr | case 'puor' % PuOr |
301 | rgb = [127,59,8;179,88,6;230,97,1;224,130,20;241,163,64;253,184,99;254,224,182;247,247,247;216,218,235;178,171,210;153,142,195;128,115,172;94,60,153;84,39,136;45,0,75]; | ||
302 | typ = 'Diverging'; | ||
301 | rgb = [127,59,8;179,88,6;230,97,1;224,130,20;241,163,64;253,184,99;254,224,182;247,247,247;216,218,235;178,171,210;153,142,195;128,115,172;94,60,153;84,39,136;45,0,75]; | ||
302 | typ = 'Diverging'; | ||
303 | 303 | case 'rdbu' % RdBu | case 'rdbu' % RdBu |
304 | rgb = [103,0,31;178,24,43;202,0,32;214,96,77;239,138,98;244,165,130;253,219,199;247,247,247;209,229,240;146,197,222;103,169,207;67,147,195;5,113,176;33,102,172;5,48,97]; | ||
305 | typ = 'Diverging'; | ||
304 | rgb = [103,0,31;178,24,43;202,0,32;214,96,77;239,138,98;244,165,130;253,219,199;247,247,247;209,229,240;146,197,222;103,169,207;67,147,195;5,113,176;33,102,172;5,48,97]; | ||
305 | typ = 'Diverging'; | ||
306 | 306 | case 'rdgy' % RdGy | case 'rdgy' % RdGy |
307 | rgb = [103,0,31;178,24,43;202,0,32;214,96,77;239,138,98;244,165,130;253,219,199;255,255,255;224,224,224;186,186,186;153,153,153;135,135,135;64,64,64;77,77,77;26,26,26]; | ||
308 | typ = 'Diverging'; | ||
307 | rgb = [103,0,31;178,24,43;202,0,32;214,96,77;239,138,98;244,165,130;253,219,199;255,255,255;224,224,224;186,186,186;153,153,153;135,135,135;64,64,64;77,77,77;26,26,26]; | ||
308 | typ = 'Diverging'; | ||
309 | 309 | case 'rdylbu' % RdYlBu | case 'rdylbu' % RdYlBu |
310 | rgb = [165,0,38;215,48,39;215,25,28;244,109,67;252,141,89;253,174,97;254,224,144;255,255,191;224,243,248;171,217,233;145,191,219;116,173,209;44,123,182;69,117,180;49,54,149]; | ||
311 | typ = 'Diverging'; | ||
310 | rgb = [165,0,38;215,48,39;215,25,28;244,109,67;252,141,89;253,174,97;254,224,144;255,255,191;224,243,248;171,217,233;145,191,219;116,173,209;44,123,182;69,117,180;49,54,149]; | ||
311 | typ = 'Diverging'; | ||
312 | 312 | case 'rdylgn' % RdYlGn | case 'rdylgn' % RdYlGn |
313 | rgb = [165,0,38;215,48,39;215,25,28;244,109,67;252,141,89;253,174,97;254,224,139;255,255,191;217,239,139;166,217,106;145,207,96;102,189,99;26,150,65;26,152,80;0,104,55]; | ||
314 | typ = 'Diverging'; | ||
313 | rgb = [165,0,38;215,48,39;215,25,28;244,109,67;252,141,89;253,174,97;254,224,139;255,255,191;217,239,139;166,217,106;145,207,96;102,189,99;26,150,65;26,152,80;0,104,55]; | ||
314 | typ = 'Diverging'; | ||
315 | 315 | case 'spectral' % Spectral | case 'spectral' % Spectral |
316 | rgb = [158,1,66;213,62,79;215,25,28;244,109,67;252,141,89;253,174,97;254,224,139;255,255,191;230,245,152;171,221,164;153,213,148;102,194,165;43,131,186;50,136,189;94,79,162]; | ||
317 | typ = 'Diverging'; | ||
316 | rgb = [158,1,66;213,62,79;215,25,28;244,109,67;252,141,89;253,174,97;254,224,139;255,255,191;230,245,152;171,221,164;153,213,148;102,194,165;43,131,186;50,136,189;94,79,162]; | ||
317 | typ = 'Diverging'; | ||
318 | 318 | case 'accent' % Accent | case 'accent' % Accent |
319 | rgb = [127,201,127;190,174,212;253,192,134;255,255,153;56,108,176;240,2,127;191,91,23;102,102,102]; | ||
320 | typ = 'Qualitative'; | ||
319 | rgb = [127,201,127;190,174,212;253,192,134;255,255,153;56,108,176;240,2,127;191,91,23;102,102,102]; | ||
320 | typ = 'Qualitative'; | ||
321 | 321 | case 'dark2' % Dark2 | case 'dark2' % Dark2 |
322 | rgb = [27,158,119;217,95,2;117,112,179;231,41,138;102,166,30;230,171,2;166,118,29;102,102,102]; | ||
323 | typ = 'Qualitative'; | ||
322 | rgb = [27,158,119;217,95,2;117,112,179;231,41,138;102,166,30;230,171,2;166,118,29;102,102,102]; | ||
323 | typ = 'Qualitative'; | ||
324 | 324 | case 'paired' % Paired | case 'paired' % Paired |
325 | rgb = [166,206,227;31,120,180;178,223,138;51,160,44;251,154,153;227,26,28;253,191,111;255,127,0;202,178,214;106,61,154;255,255,153;177,89,40]; | ||
326 | typ = 'Qualitative'; | ||
325 | rgb = [166,206,227;31,120,180;178,223,138;51,160,44;251,154,153;227,26,28;253,191,111;255,127,0;202,178,214;106,61,154;255,255,153;177,89,40]; | ||
326 | typ = 'Qualitative'; | ||
327 | 327 | case 'pastel1' % Pastel1 | case 'pastel1' % Pastel1 |
328 | rgb = [251,180,174;179,205,227;204,235,197;222,203,228;254,217,166;255,255,204;229,216,189;253,218,236;242,242,242]; | ||
329 | typ = 'Qualitative'; | ||
328 | rgb = [251,180,174;179,205,227;204,235,197;222,203,228;254,217,166;255,255,204;229,216,189;253,218,236;242,242,242]; | ||
329 | typ = 'Qualitative'; | ||
330 | 330 | case 'pastel2' % Pastel2 | case 'pastel2' % Pastel2 |
331 | rgb = [179,226,205;253,205,172;203,213,232;244,202,228;230,245,201;255,242,174;241,226,204;204,204,204]; | ||
332 | typ = 'Qualitative'; | ||
331 | rgb = [179,226,205;253,205,172;203,213,232;244,202,228;230,245,201;255,242,174;241,226,204;204,204,204]; | ||
332 | typ = 'Qualitative'; | ||
333 | 333 | case 'set1' % Set1 | case 'set1' % Set1 |
334 | rgb = [228,26,28;55,126,184;77,175,74;152,78,163;255,127,0;255,255,51;166,86,40;247,129,191;153,153,153]; | ||
335 | typ = 'Qualitative'; | ||
334 | rgb = [228,26,28;55,126,184;77,175,74;152,78,163;255,127,0;255,255,51;166,86,40;247,129,191;153,153,153]; | ||
335 | typ = 'Qualitative'; | ||
336 | 336 | case 'set2' % Set2 | case 'set2' % Set2 |
337 | rgb = [102,194,165;252,141,98;141,160,203;231,138,195;166,216,84;255,217,47;229,196,148;179,179,179]; | ||
338 | typ = 'Qualitative'; | ||
337 | rgb = [102,194,165;252,141,98;141,160,203;231,138,195;166,216,84;255,217,47;229,196,148;179,179,179]; | ||
338 | typ = 'Qualitative'; | ||
339 | 339 | case 'set3' % Set3 | case 'set3' % Set3 |
340 | rgb = [141,211,199;255,255,179;190,186,218;251,128,114;128,177,211;253,180,98;179,222,105;252,205,229;217,217,217;188,128,189;204,235,197;255,237,111]; | ||
341 | typ = 'Qualitative'; | ||
340 | rgb = [141,211,199;255,255,179;190,186,218;251,128,114;128,177,211;253,180,98;179,222,105;252,205,229;217,217,217;188,128,189;204,235,197;255,237,111]; | ||
341 | typ = 'Qualitative'; | ||
342 | 342 | case 'blues' % Blues | case 'blues' % Blues |
343 | rgb = [247,251,255;239,243,255;222,235,247;198,219,239;189,215,231;158,202,225;107,174,214;66,146,198;49,130,189;33,113,181;8,81,156;8,69,148;8,48,107]; | ||
344 | typ = 'Sequential'; | ||
343 | rgb = [247,251,255;239,243,255;222,235,247;198,219,239;189,215,231;158,202,225;107,174,214;66,146,198;49,130,189;33,113,181;8,81,156;8,69,148;8,48,107]; | ||
344 | typ = 'Sequential'; | ||
345 | 345 | case 'bugn' % BuGn | case 'bugn' % BuGn |
346 | rgb = [247,252,253;237,248,251;229,245,249;204,236,230;178,226,226;153,216,201;102,194,164;65,174,118;44,162,95;35,139,69;0,109,44;0,88,36;0,68,27]; | ||
347 | typ = 'Sequential'; | ||
346 | rgb = [247,252,253;237,248,251;229,245,249;204,236,230;178,226,226;153,216,201;102,194,164;65,174,118;44,162,95;35,139,69;0,109,44;0,88,36;0,68,27]; | ||
347 | typ = 'Sequential'; | ||
348 | 348 | case 'bupu' % BuPu | case 'bupu' % BuPu |
349 | rgb = [247,252,253;237,248,251;224,236,244;191,211,230;179,205,227;158,188,218;140,150,198;140,107,177;136,86,167;136,65,157;129,15,124;110,1,107;77,0,75]; | ||
350 | typ = 'Sequential'; | ||
349 | rgb = [247,252,253;237,248,251;224,236,244;191,211,230;179,205,227;158,188,218;140,150,198;140,107,177;136,86,167;136,65,157;129,15,124;110,1,107;77,0,75]; | ||
350 | typ = 'Sequential'; | ||
351 | 351 | case 'gnbu' % GnBu | case 'gnbu' % GnBu |
352 | rgb = [247,252,240;240,249,232;224,243,219;204,235,197;186,228,188;168,221,181;123,204,196;78,179,211;67,162,202;43,140,190;8,104,172;8,88,158;8,64,129]; | ||
353 | typ = 'Sequential'; | ||
352 | rgb = [247,252,240;240,249,232;224,243,219;204,235,197;186,228,188;168,221,181;123,204,196;78,179,211;67,162,202;43,140,190;8,104,172;8,88,158;8,64,129]; | ||
353 | typ = 'Sequential'; | ||
354 | 354 | case 'greens' % Greens | case 'greens' % Greens |
355 | rgb = [247,252,245;237,248,233;229,245,224;199,233,192;186,228,179;161,217,155;116,196,118;65,171,93;49,163,84;35,139,69;0,109,44;0,90,50;0,68,27]; | ||
356 | typ = 'Sequential'; | ||
355 | rgb = [247,252,245;237,248,233;229,245,224;199,233,192;186,228,179;161,217,155;116,196,118;65,171,93;49,163,84;35,139,69;0,109,44;0,90,50;0,68,27]; | ||
356 | typ = 'Sequential'; | ||
357 | 357 | case 'greys' % Greys | case 'greys' % Greys |
358 | rgb = [255,255,255;247,247,247;240,240,240;217,217,217;204,204,204;189,189,189;150,150,150;115,115,115;99,99,99;82,82,82;37,37,37;37,37,37;0,0,0]; | ||
359 | typ = 'Sequential'; | ||
358 | rgb = [255,255,255;247,247,247;240,240,240;217,217,217;204,204,204;189,189,189;150,150,150;115,115,115;99,99,99;82,82,82;37,37,37;37,37,37;0,0,0]; | ||
359 | typ = 'Sequential'; | ||
360 | 360 | case 'orrd' % OrRd | case 'orrd' % OrRd |
361 | rgb = [255,247,236;254,240,217;254,232,200;253,212,158;253,204,138;253,187,132;252,141,89;239,101,72;227,74,51;215,48,31;179,0,0;153,0,0;127,0,0]; | ||
362 | typ = 'Sequential'; | ||
361 | rgb = [255,247,236;254,240,217;254,232,200;253,212,158;253,204,138;253,187,132;252,141,89;239,101,72;227,74,51;215,48,31;179,0,0;153,0,0;127,0,0]; | ||
362 | typ = 'Sequential'; | ||
363 | 363 | case 'oranges' % Oranges | case 'oranges' % Oranges |
364 | rgb = [255,245,235;254,237,222;254,230,206;253,208,162;253,190,133;253,174,107;253,141,60;241,105,19;230,85,13;217,72,1;166,54,3;140,45,4;127,39,4]; | ||
365 | typ = 'Sequential'; | ||
364 | rgb = [255,245,235;254,237,222;254,230,206;253,208,162;253,190,133;253,174,107;253,141,60;241,105,19;230,85,13;217,72,1;166,54,3;140,45,4;127,39,4]; | ||
365 | typ = 'Sequential'; | ||
366 | 366 | case 'pubu' % PuBu | case 'pubu' % PuBu |
367 | rgb = [255,247,251;241,238,246;236,231,242;208,209,230;189,201,225;166,189,219;116,169,207;54,144,192;43,140,190;5,112,176;4,90,141;3,78,123;2,56,88]; | ||
368 | typ = 'Sequential'; | ||
367 | rgb = [255,247,251;241,238,246;236,231,242;208,209,230;189,201,225;166,189,219;116,169,207;54,144,192;43,140,190;5,112,176;4,90,141;3,78,123;2,56,88]; | ||
368 | typ = 'Sequential'; | ||
369 | 369 | case 'pubugn' % PuBuGn | case 'pubugn' % PuBuGn |
370 | rgb = [255,247,251;246,239,247;236,226,240;208,209,230;189,201,225;166,189,219;103,169,207;54,144,192;28,144,153;2,129,138;1,108,89;1,100,80;1,70,54]; | ||
371 | typ = 'Sequential'; | ||
370 | rgb = [255,247,251;246,239,247;236,226,240;208,209,230;189,201,225;166,189,219;103,169,207;54,144,192;28,144,153;2,129,138;1,108,89;1,100,80;1,70,54]; | ||
371 | typ = 'Sequential'; | ||
372 | 372 | case 'purd' % PuRd | case 'purd' % PuRd |
373 | rgb = [247,244,249;241,238,246;231,225,239;212,185,218;215,181,216;201,148,199;223,101,176;231,41,138;221,28,119;206,18,86;152,0,67;145,0,63;103,0,31]; | ||
374 | typ = 'Sequential'; | ||
373 | rgb = [247,244,249;241,238,246;231,225,239;212,185,218;215,181,216;201,148,199;223,101,176;231,41,138;221,28,119;206,18,86;152,0,67;145,0,63;103,0,31]; | ||
374 | typ = 'Sequential'; | ||
375 | 375 | case 'purples' % Purples | case 'purples' % Purples |
376 | rgb = [252,251,253;242,240,247;239,237,245;218,218,235;203,201,226;188,189,220;158,154,200;128,125,186;117,107,177;106,81,163;84,39,143;74,20,134;63,0,125]; | ||
377 | typ = 'Sequential'; | ||
376 | rgb = [252,251,253;242,240,247;239,237,245;218,218,235;203,201,226;188,189,220;158,154,200;128,125,186;117,107,177;106,81,163;84,39,143;74,20,134;63,0,125]; | ||
377 | typ = 'Sequential'; | ||
378 | 378 | case 'rdpu' % RdPu | case 'rdpu' % RdPu |
379 | rgb = [255,247,243;254,235,226;253,224,221;252,197,192;251,180,185;250,159,181;247,104,161;221,52,151;197,27,138;174,1,126;122,1,119;122,1,119;73,0,106]; | ||
380 | typ = 'Sequential'; | ||
379 | rgb = [255,247,243;254,235,226;253,224,221;252,197,192;251,180,185;250,159,181;247,104,161;221,52,151;197,27,138;174,1,126;122,1,119;122,1,119;73,0,106]; | ||
380 | typ = 'Sequential'; | ||
381 | 381 | case 'reds' % Reds | case 'reds' % Reds |
382 | rgb = [255,245,240;254,229,217;254,224,210;252,187,161;252,174,145;252,146,114;251,106,74;239,59,44;222,45,38;203,24,29;165,15,21;153,0,13;103,0,13]; | ||
383 | typ = 'Sequential'; | ||
382 | rgb = [255,245,240;254,229,217;254,224,210;252,187,161;252,174,145;252,146,114;251,106,74;239,59,44;222,45,38;203,24,29;165,15,21;153,0,13;103,0,13]; | ||
383 | typ = 'Sequential'; | ||
384 | 384 | case 'ylgn' % YlGn | case 'ylgn' % YlGn |
385 | rgb = [255,255,229;255,255,204;247,252,185;217,240,163;194,230,153;173,221,142;120,198,121;65,171,93;49,163,84;35,132,67;0,104,55;0,90,50;0,69,41]; | ||
386 | typ = 'Sequential'; | ||
385 | rgb = [255,255,229;255,255,204;247,252,185;217,240,163;194,230,153;173,221,142;120,198,121;65,171,93;49,163,84;35,132,67;0,104,55;0,90,50;0,69,41]; | ||
386 | typ = 'Sequential'; | ||
387 | 387 | case 'ylgnbu' % YlGnBu | case 'ylgnbu' % YlGnBu |
388 | rgb = [255,255,217;255,255,204;237,248,177;199,233,180;161,218,180;127,205,187;65,182,196;29,145,192;44,127,184;34,94,168;37,52,148;12,44,132;8,29,88]; | ||
389 | typ = 'Sequential'; | ||
388 | rgb = [255,255,217;255,255,204;237,248,177;199,233,180;161,218,180;127,205,187;65,182,196;29,145,192;44,127,184;34,94,168;37,52,148;12,44,132;8,29,88]; | ||
389 | typ = 'Sequential'; | ||
390 | 390 | case 'ylorbr' % YlOrBr | case 'ylorbr' % YlOrBr |
391 | rgb = [255,255,229;255,255,212;255,247,188;254,227,145;254,217,142;254,196,79;254,153,41;236,112,20;217,95,14;204,76,2;153,52,4;140,45,4;102,37,6]; | ||
392 | typ = 'Sequential'; | ||
391 | rgb = [255,255,229;255,255,212;255,247,188;254,227,145;254,217,142;254,196,79;254,153,41;236,112,20;217,95,14;204,76,2;153,52,4;140,45,4;102,37,6]; | ||
392 | typ = 'Sequential'; | ||
393 | 393 | case 'ylorrd' % YlOrRd | case 'ylorrd' % YlOrRd |
394 | rgb = [255,255,204;255,255,178;255,237,160;254,217,118;254,204,92;254,178,76;253,141,60;252,78,42;240,59,32;227,26,28;189,0,38;177,0,38;128,0,38]; | ||
395 | typ = 'Sequential'; | ||
394 | rgb = [255,255,204;255,255,178;255,237,160;254,217,118;254,204,92;254,178,76;253,141,60;252,78,42;240,59,32;227,26,28;189,0,38;177,0,38;128,0,38]; | ||
395 | typ = 'Sequential'; | ||
396 | 396 | otherwise | otherwise |
397 | error('Colorscheme "%s" is not supported. Check the token tables.',tok) | ||
397 | error('Colorscheme "%s" is not supported. Check the token tables.',tok) | ||
398 | 398 | end | end |
399 | 399 | % | % |
400 | 400 | rgb = rgb./255; | rgb = rgb./255; |
401 | 401 | % | % |
402 | 402 | switch typ | switch typ |
403 | 403 | case 'Diverging' | case 'Diverging' |
404 | num = 11; | ||
404 | num = 11; | ||
405 | 405 | case 'Qualitative' | case 'Qualitative' |
406 | num = size(rgb,1); | ||
406 | num = size(rgb,1); | ||
407 | 407 | case 'Sequential' | case 'Sequential' |
408 | num = 9; | ||
408 | num = 9; | ||
409 | 409 | otherwise | otherwise |
410 | error('The colorscheme type "%s" is not recognized',typ) | ||
410 | error('The colorscheme type "%s" is not recognized',typ) | ||
411 | 411 | end | end |
412 | 412 | % | % |
413 | 413 | end | end |
File misc/3rdparty/brewermap_view.m changed (mode: 100644) (index d1c29b2..ea439de) | |||
... | ... | function [map,scheme] = brewermap_view(N,scheme) | |
54 | 54 | % ### Input Wrangling ### | % ### Input Wrangling ### |
55 | 55 | % | % |
56 | 56 | if nargin<1 || isnumeric(N)&&isempty(N) | if nargin<1 || isnumeric(N)&&isempty(N) |
57 | N = 128; | ||
57 | N = 128; | ||
58 | 58 | elseif iscell(N)&&numel(N) | elseif iscell(N)&&numel(N) |
59 | tmp = all(1==cellfun('prodofsize',N)&cellfun(@ishghandle,N)); | ||
60 | assert(tmp,'Input <N> may be a cell array of axes or figure handles.') | ||
59 | tmp = all(1==cellfun('prodofsize',N)&cellfun(@ishghandle,N)); | ||
60 | assert(tmp,'Input <N> may be a cell array of axes or figure handles.') | ||
61 | 61 | else | else |
62 | assert(isnumeric(N)&&isscalar(N),'Input <N> must be a scalar numeric.') | ||
63 | assert(isreal(N)&&fix(N)==N&&N>0,'Input <N> must be positive real integer: %g+%gi',N,imag(N)) | ||
64 | N = double(N); | ||
62 | assert(isnumeric(N)&&isscalar(N),'Input <N> must be a scalar numeric.') | ||
63 | assert(isreal(N)&&fix(N)==N&&N>0,'Input <N> must be positive real integer: %g+%gi',N,imag(N)) | ||
64 | N = double(N); | ||
65 | 65 | end | end |
66 | 66 | % | % |
67 | 67 | if nargin<2 | if nargin<2 |
68 | L = brewermap('list'); | ||
69 | scheme = L{1+rem(round(now*1e7),numel(L))}; | ||
68 | L = brewermap('list'); | ||
69 | scheme = L{1+rem(round(now*1e7),numel(L))}; | ||
70 | 70 | else | else |
71 | assert(ischar(scheme)&&isrow(scheme),'Second input <scheme> must be a string.') | ||
71 | assert(ischar(scheme)&&isrow(scheme),'Second input <scheme> must be a string.') | ||
72 | 72 | end | end |
73 | 73 | % | % |
74 | 74 | [~,~,h] = bmvUpDt(N, scheme); | [~,~,h] = bmvUpDt(N, scheme); |
75 | 75 | % | % |
76 | 76 | if nargout | if nargout |
77 | waitfor(h); | ||
78 | [~,scheme,map] = bmvUpDt(); | ||
77 | waitfor(h); | ||
78 | [~,scheme,map] = bmvUpDt(); | ||
79 | 79 | end | end |
80 | 80 | % | % |
81 | 81 | end | end |
... | ... | stp = [1,10]; | |
93 | 93 | [L,V,T] = brewermap('list'); | [L,V,T] = brewermap('list'); |
94 | 94 | % | % |
95 | 95 | switch nargin | switch nargin |
96 | case 0 % Demo initialize OR return colormap | ||
97 | N = prvN; | ||
98 | S = prvS; | ||
99 | if nargout==3 % Return colormap | ||
100 | ghnd = brewermap(N,H.fRev(S)); | ||
101 | return | ||
102 | end | ||
103 | case 1 % Button/Slider callback | ||
104 | if get(H.demo,'Value') % Demo | ||
105 | return | ||
106 | elseif ischar(N) % scheme name | ||
107 | S = N; | ||
108 | N = prvN; | ||
109 | else % parameter N only | ||
110 | S = prvS; | ||
111 | N = round(get(H.vSld(1),'Value')); | ||
112 | end | ||
113 | case 2 % Demo update OR function call | ||
114 | if iscell(N) % External axes/figure | ||
115 | extH = N; | ||
116 | N = size(colormap(extH{1}),1); | ||
117 | end | ||
118 | if isempty(H) || ~ishghandle(H.fig) | ||
119 | if nargout<3 % Demo | ||
120 | return | ||
121 | end | ||
122 | % Check brewermap version: | ||
123 | str = 'The function "brewermap" returned an unusual %s.'; | ||
124 | assert(all(35==[numel(L),numel(V),numel(T)]),str,'array size') | ||
125 | tmp = find(any(diff(+char(T)),2)); | ||
126 | assert(numel(tmp)==2&&all(tmp==[9;17]),str,'scheme name sequence') | ||
127 | % Create a new figure: | ||
128 | H = bmvPlot(lbd,rbd,stp,N,S,L); | ||
129 | else % Update slider position: | ||
130 | set(H.vSld, 'Value',max(lbd,min(rbd,N))); | ||
131 | if nargout<3 % Demo | ||
132 | S = L{1+mod(find(strcmpi(S,L)),numel(L))}; | ||
133 | set(H.bGrp,'SelectedObject',H.bSep(strcmpi(S,L))); | ||
134 | end | ||
135 | end | ||
136 | % | ||
137 | otherwise | ||
138 | error('How did this happen? This should not be possible.') | ||
96 | case 0 % Demo initialize OR return colormap | ||
97 | N = prvN; | ||
98 | S = prvS; | ||
99 | if nargout==3 % Return colormap | ||
100 | ghnd = brewermap(N,H.fRev(S)); | ||
101 | return | ||
102 | end | ||
103 | case 1 % Button/Slider callback | ||
104 | if get(H.demo,'Value') % Demo | ||
105 | return | ||
106 | elseif ischar(N) % scheme name | ||
107 | S = N; | ||
108 | N = prvN; | ||
109 | else % parameter N only | ||
110 | S = prvS; | ||
111 | N = round(get(H.vSld(1),'Value')); | ||
112 | end | ||
113 | case 2 % Demo update OR function call | ||
114 | if iscell(N) % External axes/figure | ||
115 | extH = N; | ||
116 | N = size(colormap(extH{1}),1); | ||
117 | end | ||
118 | if isempty(H) || ~ishghandle(H.fig) | ||
119 | if nargout<3 % Demo | ||
120 | return | ||
121 | end | ||
122 | % Check brewermap version: | ||
123 | str = 'The function "brewermap" returned an unusual %s.'; | ||
124 | assert(all(35==[numel(L),numel(V),numel(T)]),str,'array size') | ||
125 | tmp = find(any(diff(+char(T)),2)); | ||
126 | assert(numel(tmp)==2&&all(tmp==[9;17]),str,'scheme name sequence') | ||
127 | % Create a new figure: | ||
128 | H = bmvPlot(lbd,rbd,stp,N,S,L); | ||
129 | else % Update slider position: | ||
130 | set(H.vSld, 'Value',max(lbd,min(rbd,N))); | ||
131 | if nargout<3 % Demo | ||
132 | S = L{1+mod(find(strcmpi(S,L)),numel(L))}; | ||
133 | set(H.bGrp,'SelectedObject',H.bSep(strcmpi(S,L))); | ||
134 | end | ||
135 | end | ||
136 | % | ||
137 | otherwise | ||
138 | error('How did this happen? This should not be possible.') | ||
139 | 139 | end | end |
140 | 140 | % | % |
141 | 141 | prvN = N; | prvN = N; |
... | ... | ghnd = H.fig; | |
146 | 146 | idx = strcmpi(S,L); | idx = strcmpi(S,L); |
147 | 147 | idy = strcmp('Qualitative',T{idx}) && V(idx)<N; | idy = strcmp('Qualitative',T{idx}) && V(idx)<N; |
148 | 148 | if idy | if idy |
149 | N = V(idx); | ||
150 | set(H.vSld, 'Value',max(lbd,min(rbd,N))); | ||
149 | N = V(idx); | ||
150 | set(H.vSld, 'Value',max(lbd,min(rbd,N))); | ||
151 | 151 | end | end |
152 | 152 | % | % |
153 | 153 | % Update parameter value text: | % Update parameter value text: |
... | ... | set(H.cbIm(2), 'CData',repmat(mag,[1,1,3])) | |
164 | 164 | % | % |
165 | 165 | % Update 2D line / 3D patch values: | % Update 2D line / 3D patch values: |
166 | 166 | if get(H.D2D3,'Value') | if get(H.D2D3,'Value') |
167 | set(H.ln2D, 'XData',linspace(0,1,abs(N))); | ||
168 | set(H.ln2D, {'YData'},num2cell([map,mag],1).'); | ||
167 | set(H.ln2D, 'XData',linspace(0,1,abs(N))); | ||
168 | set(H.ln2D, {'YData'},num2cell([map,mag],1).'); | ||
169 | 169 | else | else |
170 | set(H.pt3D, 'XData',map(:,1), 'YData',map(:,2), 'ZData',map(:,3), 'FaceVertexCData',map) | ||
170 | set(H.pt3D, 'XData',map(:,1), 'YData',map(:,2), 'ZData',map(:,3), 'FaceVertexCData',map) | ||
171 | 171 | end | end |
172 | 172 | % | % |
173 | 173 | % Update warning text: | % Update warning text: |
... | ... | set(H.warn,'String',str); | |
176 | 176 | % | % |
177 | 177 | % Update external axes/figure: | % Update external axes/figure: |
178 | 178 | if ~isempty(extH) | if ~isempty(extH) |
179 | for k = find(cellfun(@ishghandle,extH)) | ||
180 | colormap(extH{k},map); | ||
181 | end | ||
179 | for k = find(cellfun(@ishghandle,extH)) | ||
180 | colormap(extH{k},map); | ||
181 | end | ||
182 | 182 | end | end |
183 | 183 | % | % |
184 | 184 | end | end |
... | ... | axh = 1-uih-2*gap; % axes height | |
196 | 196 | wdt = 1-cbw-2*gap; % axes width | wdt = 1-cbw-2*gap; % axes width |
197 | 197 | % | % |
198 | 198 | H.fig = figure('HandleVisibility','callback', 'Color','white',... | H.fig = figure('HandleVisibility','callback', 'Color','white',... |
199 | 'IntegerHandle','off', 'NumberTitle','off',... | ||
200 | 'Name','ColorBrewer Interactive Scheme Selector'); | ||
199 | 'IntegerHandle','off', 'NumberTitle','off',... | ||
200 | 'Name','ColorBrewer Interactive Scheme Selector'); | ||
201 | 201 | % | % |
202 | 202 | % Add 2D lineplot: | % Add 2D lineplot: |
203 | 203 | H.ax2D = axes('Parent',H.fig, 'Position',[gap, uih+gap, wdt, axh],... | H.ax2D = axes('Parent',H.fig, 'Position',[gap, uih+gap, wdt, axh],... |
204 | 'ColorOrder',[1,0,0; 0,1,0; 0,0,1; 0.6,0.6,0.6], 'HitTest','off',... | ||
205 | 'Visible','off', 'XLim',[0,1], 'YLim',[0,1], 'XTick',[], 'YTick',[]); | ||
204 | 'ColorOrder',[1,0,0; 0,1,0; 0,0,1; 0.6,0.6,0.6], 'HitTest','off',... | ||
205 | 'Visible','off', 'XLim',[0,1], 'YLim',[0,1], 'XTick',[], 'YTick',[]); | ||
206 | 206 | H.ln2D = line([0,0,0,0;1,1,1,1],[0,0,0,0;1,1,1,1], 'Parent',H.ax2D, 'Visible','off'); | H.ln2D = line([0,0,0,0;1,1,1,1],[0,0,0,0;1,1,1,1], 'Parent',H.ax2D, 'Visible','off'); |
207 | 207 | % | % |
208 | 208 | % Add 3D scatterplot: | % Add 3D scatterplot: |
209 | 209 | H.ax3D = axes('Parent',H.fig, 'OuterPosition',[0, uih, wdt+2*gap, 1-uih],... | H.ax3D = axes('Parent',H.fig, 'OuterPosition',[0, uih, wdt+2*gap, 1-uih],... |
210 | 'Visible','on', 'XLim',[0,1], 'YLim',[0,1], 'ZLim',[0,1], 'HitTest','on'); | ||
210 | 'Visible','on', 'XLim',[0,1], 'YLim',[0,1], 'ZLim',[0,1], 'HitTest','on'); | ||
211 | 211 | H.pt3D = patch('Parent',H.ax3D, 'XData',[0;1], 'YData',[0;1], 'ZData',[0;1],... | H.pt3D = patch('Parent',H.ax3D, 'XData',[0;1], 'YData',[0;1], 'ZData',[0;1],... |
212 | 'Visible','on', 'LineStyle','none', 'FaceColor','none', 'MarkerEdgeColor','none',... | ||
213 | 'Marker','o', 'MarkerFaceColor','flat', 'MarkerSize',10, 'FaceVertexCData',[1,1,0;1,0,1]); | ||
212 | 'Visible','on', 'LineStyle','none', 'FaceColor','none', 'MarkerEdgeColor','none',... | ||
213 | 'Marker','o', 'MarkerFaceColor','flat', 'MarkerSize',10, 'FaceVertexCData',[1,1,0;1,0,1]); | ||
214 | 214 | view(H.ax3D,3); | view(H.ax3D,3); |
215 | 215 | grid(H.ax3D,'on') | grid(H.ax3D,'on') |
216 | 216 | xlabel(H.ax3D,'Red') | xlabel(H.ax3D,'Red') |
... | ... | zlabel(H.ax3D,'Blue') | |
219 | 219 | % | % |
220 | 220 | % Add warning text: | % Add warning text: |
221 | 221 | H.warn = text('Parent',H.ax2D, 'Units','normalized', 'Position',[1,1],... | H.warn = text('Parent',H.ax2D, 'Units','normalized', 'Position',[1,1],... |
222 | 'HorizontalAlignment','right', 'VerticalAlignment','top', 'Color','k'); | ||
222 | 'HorizontalAlignment','right', 'VerticalAlignment','top', 'Color','k'); | ||
223 | 223 | % | % |
224 | 224 | % Add demo button: | % Add demo button: |
225 | 225 | H.demo = uicontrol(H.fig, 'Style','togglebutton', 'Units','normalized',... | H.demo = uicontrol(H.fig, 'Style','togglebutton', 'Units','normalized',... |
226 | 'Position',[gap,uih+gap+0*bth,btw,bth], 'String','Demo',... | ||
227 | 'Max',1, 'Min',0, 'Callback',@bmvDemo); | ||
226 | 'Position',[gap,uih+gap+0*bth,btw,bth], 'String','Demo',... | ||
227 | 'Max',1, 'Min',0, 'Callback',@bmvDemo); | ||
228 | 228 | % Add 2D/3D button: | % Add 2D/3D button: |
229 | 229 | H.D2D3 = uicontrol(H.fig, 'Style','togglebutton', 'Units','normalized',... | H.D2D3 = uicontrol(H.fig, 'Style','togglebutton', 'Units','normalized',... |
230 | 'Position',[gap,uih+gap+1*bth,btw,bth], 'String','2D / 3D',... | ||
231 | 'Max',1, 'Min',0, 'Callback',@(h,~)bmv2D3D(H,h)); | ||
230 | 'Position',[gap,uih+gap+1*bth,btw,bth], 'String','2D / 3D',... | ||
231 | 'Max',1, 'Min',0, 'Callback',@(h,~)bmv2D3D(H,h)); | ||
232 | 232 | % Add reverse button: | % Add reverse button: |
233 | 233 | H.bRev = uicontrol(H.fig, 'Style','togglebutton', 'Units','normalized',... | H.bRev = uicontrol(H.fig, 'Style','togglebutton', 'Units','normalized',... |
234 | 'Position',[gap,uih+gap+2*bth,btw,bth], 'String','Reverse',... | ||
235 | 'Max',1, 'Min',0, 'Callback',@(~,~)bmvUpDt()); | ||
234 | 'Position',[gap,uih+gap+2*bth,btw,bth], 'String','Reverse',... | ||
235 | 'Max',1, 'Min',0, 'Callback',@(~,~)bmvUpDt()); | ||
236 | 236 | H.fRev = @(s)[char(42*ones(1,get(H.bRev,'Value'))),s]; | H.fRev = @(s)[char(42*ones(1,get(H.bRev,'Value'))),s]; |
237 | 237 | % | % |
238 | 238 | % Add colorbars: | % Add colorbars: |
239 | 239 | C = reshape([1,1,1],1,[],3); | C = reshape([1,1,1],1,[],3); |
240 | 240 | H.cbAx(1) = axes('Parent',H.fig, 'Visible','off', 'Units','normalized',... | H.cbAx(1) = axes('Parent',H.fig, 'Visible','off', 'Units','normalized',... |
241 | 'Position',[1-cbw/1,gap,cbw/2-gap,1-2*gap], 'YLim',[0.5,1.5], 'HitTest','off'); | ||
241 | 'Position',[1-cbw/1,gap,cbw/2-gap,1-2*gap], 'YLim',[0.5,1.5], 'HitTest','off'); | ||
242 | 242 | H.cbAx(2) = axes('Parent',H.fig, 'Visible','off', 'Units','normalized',... | H.cbAx(2) = axes('Parent',H.fig, 'Visible','off', 'Units','normalized',... |
243 | 'Position',[1-cbw/2,gap,cbw/2-gap,1-2*gap], 'YLim',[0.5,1.5], 'HitTest','off'); | ||
243 | 'Position',[1-cbw/2,gap,cbw/2-gap,1-2*gap], 'YLim',[0.5,1.5], 'HitTest','off'); | ||
244 | 244 | H.cbIm(1) = image('Parent',H.cbAx(1), 'CData',C); | H.cbIm(1) = image('Parent',H.cbAx(1), 'CData',C); |
245 | 245 | H.cbIm(2) = image('Parent',H.cbAx(2), 'CData',C); | H.cbIm(2) = image('Parent',H.cbAx(2), 'CData',C); |
246 | 246 | % | % |
247 | 247 | % Add parameter slider, listener, and corresponding text: | % Add parameter slider, listener, and corresponding text: |
248 | 248 | V = max(lbd,min(rbd,V)); | V = max(lbd,min(rbd,V)); |
249 | 249 | H.vTxt = uicontrol(H.fig,'Style','text', 'Units','normalized',... | H.vTxt = uicontrol(H.fig,'Style','text', 'Units','normalized',... |
250 | 'Position',[gap,uih-bth,btw,bth], 'String','X'); | ||
250 | 'Position',[gap,uih-bth,btw,bth], 'String','X'); | ||
251 | 251 | H.vSld = uicontrol(H.fig,'Style','slider', 'Units','normalized',... | H.vSld = uicontrol(H.fig,'Style','slider', 'Units','normalized',... |
252 | 'Position',[gap,gap,btw,uih-bth], 'Min',lbd(1), 'Max',rbd(1),... | ||
253 | 'SliderStep',stp(1,:)/(rbd(1)-lbd(1)), 'Value',V(1)); | ||
252 | 'Position',[gap,gap,btw,uih-bth], 'Min',lbd(1), 'Max',rbd(1),... | ||
253 | 'SliderStep',stp(1,:)/(rbd(1)-lbd(1)), 'Value',V(1)); | ||
254 | 254 | addlistener(H.vSld, 'Value', 'PostSet',@(a,b)bmvUpDt(0)); | addlistener(H.vSld, 'Value', 'PostSet',@(a,b)bmvUpDt(0)); |
255 | 255 | % | % |
256 | 256 | % Add scheme button group: | % Add scheme button group: |
257 | 257 | H.bGrp = uibuttongroup('Parent',H.fig, 'BorderType','none', 'Units','normalized',... | H.bGrp = uibuttongroup('Parent',H.fig, 'BorderType','none', 'Units','normalized',... |
258 | 'BackgroundColor','white', 'Position',[2*gap+btw,gap,wdt-btw-gap,uih-gap]); | ||
258 | 'BackgroundColor','white', 'Position',[2*gap+btw,gap,wdt-btw-gap,uih-gap]); | ||
259 | 259 | % Determine button locations: | % Determine button locations: |
260 | 260 | Z = 1:numel(L); | Z = 1:numel(L); |
261 | 261 | Z = Z+(Z>17); | Z = Z+(Z>17); |
... | ... | C = (ceil(Z/M)-1)/4; | |
263 | 263 | R = (M-1-mod(Z-1,M))/M; | R = (M-1-mod(Z-1,M))/M; |
264 | 264 | % Add scheme buttons to group: | % Add scheme buttons to group: |
265 | 265 | for k = numel(L):-1:1 | for k = numel(L):-1:1 |
266 | H.bSep(k) = uicontrol('Style','Toggle', 'String',L{k}, 'Parent',H.bGrp,... | ||
267 | 'Unit','normalized', 'Position',[C(k),R(k),1/4,1/M]); | ||
266 | H.bSep(k) = uicontrol('Style','Toggle', 'String',L{k}, 'Parent',H.bGrp,... | ||
267 | 'Unit','normalized', 'Position',[C(k),R(k),1/4,1/M]); | ||
268 | 268 | end | end |
269 | 269 | set(H.bGrp,'SelectedObject',H.bSep(strcmpi(S,L))); | set(H.bGrp,'SelectedObject',H.bSep(strcmpi(S,L))); |
270 | 270 | set(H.bGrp,'SelectionChangeFcn',@(~,e)bmvUpDt(get(e.NewValue,'String'))); | set(H.bGrp,'SelectionChangeFcn',@(~,e)bmvUpDt(get(e.NewValue,'String'))); |
... | ... | function bmv2D3D(H,tgh) | |
275 | 275 | % Switch between 2D-line and 3D-cube: swap visibility and hittest, then update. | % Switch between 2D-line and 3D-cube: swap visibility and hittest, then update. |
276 | 276 | % | % |
277 | 277 | if get(tgh,'Value')% 2D | if get(tgh,'Value')% 2D |
278 | set(H.ax3D, 'HitTest','off', 'Visible','off') | ||
279 | set(H.ax2D, 'HitTest','on') | ||
280 | set(H.pt3D, 'Visible','off') | ||
281 | set(H.ln2D, 'Visible','on') | ||
278 | set(H.ax3D, 'HitTest','off', 'Visible','off') | ||
279 | set(H.ax2D, 'HitTest','on') | ||
280 | set(H.pt3D, 'Visible','off') | ||
281 | set(H.ln2D, 'Visible','on') | ||
282 | 282 | else % 3D | else % 3D |
283 | set(H.ax2D, 'HitTest','off') | ||
284 | set(H.ax3D, 'HitTest','on', 'Visible','on') | ||
285 | set(H.ln2D, 'Visible','off') | ||
286 | set(H.pt3D, 'Visible','on') | ||
283 | set(H.ax2D, 'HitTest','off') | ||
284 | set(H.ax3D, 'HitTest','on', 'Visible','on') | ||
285 | set(H.ln2D, 'Visible','off') | ||
286 | set(H.pt3D, 'Visible','on') | ||
287 | 287 | end | end |
288 | 288 | bmvUpDt(); | bmvUpDt(); |
289 | 289 | % | % |
... | ... | function bmvDemo(tgh,~) | |
297 | 297 | % | % |
298 | 298 | % While the toggle button is down, step schemes: | % While the toggle button is down, step schemes: |
299 | 299 | while ishghandle(tgh)&&get(tgh,'Value') | while ishghandle(tgh)&&get(tgh,'Value') |
300 | % | ||
301 | % Update figure: | ||
302 | [~,S] = bmvUpDt(round(N),S); | ||
303 | % | ||
304 | % Frame-rate faster/slower: | ||
305 | pause(1.1); | ||
300 | % | ||
301 | % Update figure: | ||
302 | [~,S] = bmvUpDt(round(N),S); | ||
303 | % | ||
304 | % Frame-rate faster/slower: | ||
305 | pause(1.1); | ||
306 | 306 | end | end |
307 | 307 | % | % |
308 | 308 | end | end |
File misc/3rdparty/cbrewer/cbrewer.m changed (mode: 100644) (index 26be891..4d9cfd6) | |||
1 | 1 | function [colormap]=cbrewer(ctype, cname, ncol, interp_method) | function [colormap]=cbrewer(ctype, cname, ncol, interp_method) |
2 | 2 | % | % |
3 | % CBREWER - This function produces a colorbrewer table (rgb data) for a | ||
4 | % given type, name and number of colors of the colorbrewer tables. | ||
3 | % CBREWER - This function produces a colorbrewer table (rgb data) for a | ||
4 | % given type, name and number of colors of the colorbrewer tables. | ||
5 | 5 | % For more information on 'colorbrewer', please visit | % For more information on 'colorbrewer', please visit |
6 | 6 | % http://colorbrewer2.org/ | % http://colorbrewer2.org/ |
7 | % | ||
7 | % | ||
8 | 8 | % The tables were generated from an MS-Excel file provided on the website | % The tables were generated from an MS-Excel file provided on the website |
9 | 9 | % http://www.personal.psu.edu/cab38/ColorBrewer/ColorBrewer_updates.html | % http://www.personal.psu.edu/cab38/ColorBrewer/ColorBrewer_updates.html |
10 | 10 | % | % |
11 | % | ||
11 | % | ||
12 | 12 | % [colormap]=cbrewer(ctype, cname, ncol, interp_method) | % [colormap]=cbrewer(ctype, cname, ncol, interp_method) |
13 | 13 | % | % |
14 | 14 | % INPUT: | % INPUT: |
... | ... | function [colormap]=cbrewer(ctype, cname, ncol, interp_method) | |
17 | 17 | % - ncol: number of color in the table. It changes according to ctype and | % - ncol: number of color in the table. It changes according to ctype and |
18 | 18 | % cname | % cname |
19 | 19 | % - interp_method: interpolation method (see interp1.m). Default is "cubic" ) | % - interp_method: interpolation method (see interp1.m). Default is "cubic" ) |
20 | % | ||
20 | % | ||
21 | 21 | % A note on the number of colors: Based on the original data, there is | % A note on the number of colors: Based on the original data, there is |
22 | 22 | % only a certain number of colors available for each type and name of | % only a certain number of colors available for each type and name of |
23 | 23 | % colortable. When 'ncol' is larger then the maximum number of colors | % colortable. When 'ncol' is larger then the maximum number of colors |
24 | % originally given, an interpolation routine is called (interp1) to produce | ||
24 | % originally given, an interpolation routine is called (interp1) to produce | ||
25 | 25 | % the "extended" colormaps. | % the "extended" colormaps. |
26 | 26 | % | % |
27 | % Example: To produce a colortable CT of ncol X 3 entries (RGB) of | ||
27 | % Example: To produce a colortable CT of ncol X 3 entries (RGB) of | ||
28 | 28 | % sequential type and named 'Blues' with 8 colors: | % sequential type and named 'Blues' with 8 colors: |
29 | 29 | % CT=cbrewer('seq', 'Blues', 8); | % CT=cbrewer('seq', 'Blues', 8); |
30 | 30 | % To use this colortable as colormap, simply call: | % To use this colortable as colormap, simply call: |
31 | 31 | % colormap(CT) | % colormap(CT) |
32 | % | ||
32 | % | ||
33 | 33 | % To see the various colormaps available according to their types and | % To see the various colormaps available according to their types and |
34 | 34 | % names, simply call: cbrewer() | % names, simply call: cbrewer() |
35 | 35 | % | % |
... | ... | if (~exist('ctype', 'var') | ~exist('cname', 'var') | ~exist('ncol', 'var')) | |
61 | 61 | disp(' - cname: name of colortable. It changes depending on ctype.') | disp(' - cname: name of colortable. It changes depending on ctype.') |
62 | 62 | disp(' - ncol: number of color in the table. It changes according to ctype and cname') | disp(' - ncol: number of color in the table. It changes according to ctype and cname') |
63 | 63 | disp(' - interp_method: interpolation method (see interp1.m). Default is "cubic" )') | disp(' - interp_method: interpolation method (see interp1.m). Default is "cubic" )') |
64 | |||
64 | |||
65 | 65 | disp(' ') | disp(' ') |
66 | 66 | disp('Sequential tables:') | disp('Sequential tables:') |
67 | 67 | z={'Blues','BuGn','BuPu','GnBu','Greens','Greys','Oranges','OrRd','PuBu','PuBuGn','PuRd',... | z={'Blues','BuGn','BuPu','GnBu','Greens','Greys','Oranges','OrRd','PuBu','PuBuGn','PuRd',... |
68 | 68 | 'Purples','RdPu', 'Reds', 'YlGn', 'YlGnBu', 'YlOrBr', 'YlOrRd', 'Spectral'}; | 'Purples','RdPu', 'Reds', 'YlGn', 'YlGnBu', 'YlOrBr', 'YlOrRd', 'Spectral'}; |
69 | disp(z') | ||
70 | |||
69 | disp(z') | ||
70 | |||
71 | 71 | disp('Divergent tables:') | disp('Divergent tables:') |
72 | 72 | z={'BrBG', 'PiYG', 'PRGn', 'PuOr', 'RdBu', 'RdGy', 'RdYlBu', 'RdYlGn'}; | z={'BrBG', 'PiYG', 'PRGn', 'PuOr', 'RdBu', 'RdGy', 'RdYlBu', 'RdYlGn'}; |
73 | 73 | disp(z') | disp(z') |
74 | |||
74 | |||
75 | 75 | disp(' ') | disp(' ') |
76 | 76 | disp('Qualitative tables:') | disp('Qualitative tables:') |
77 | 77 | %getfield(colorbrewer, 'qual') | %getfield(colorbrewer, 'qual') |
... | ... | if (ncol>length(colorbrewer.(ctype).(cname))) | |
111 | 111 | end | end |
112 | 112 | ||
113 | 113 | if (isempty(colorbrewer.(ctype).(cname){ncol})) | if (isempty(colorbrewer.(ctype).(cname){ncol})) |
114 | |||
114 | |||
115 | 115 | while(isempty(colorbrewer.(ctype).(cname){ncol})) | while(isempty(colorbrewer.(ctype).(cname){ncol})) |
116 | 116 | ncol=ncol+1; | ncol=ncol+1; |
117 | end | ||
117 | end | ||
118 | 118 | disp(' ') | disp(' ') |
119 | 119 | disp('----------------------------------------------------------------------') | disp('----------------------------------------------------------------------') |
120 | 120 | disp(['The minimum number of colors for table *' cname '* is ' num2str(ncol)]) | disp(['The minimum number of colors for table *' cname '* is ' num2str(ncol)]) |
File misc/3rdparty/cbrewer/change_jet.m changed (mode: 100644) (index b8d4ecb..7ba58fa) | |||
1 | 1 | % This script help produce a new 'jet'-like colormap based on other RGB reference colors | % This script help produce a new 'jet'-like colormap based on other RGB reference colors |
2 | 2 | ||
3 | 3 | % ------- I WAS ASKED --------------- | % ------- I WAS ASKED --------------- |
4 | % "is there a chance that you could add a diverging map going from blue to green to red as in jet, | ||
4 | % "is there a chance that you could add a diverging map going from blue to green to red as in jet, | ||
5 | 5 | % but using the red and blue from your RdBu map and the third darkest green from your RdYlGn map?"" | % but using the red and blue from your RdBu map and the third darkest green from your RdYlGn map?"" |
6 | 6 | % | % |
7 | 7 | % ANSWER: | % ANSWER: |
8 | 8 | % You should construct the new colormap based on the existing RGB values of 'jet' | % You should construct the new colormap based on the existing RGB values of 'jet' |
9 | % but projecting these RGB values on your new RGB basis. | ||
9 | % but projecting these RGB values on your new RGB basis. | ||
10 | 10 | % ----------------------------------- | % ----------------------------------- |
11 | 11 | ||
12 | 12 | % load colormaps | % load colormaps |
... | ... | for iname=1:length(cnames) | |
61 | 61 | set(gcf, 'color', [1 1 1]) | set(gcf, 'color', [1 1 1]) |
62 | 62 | ylim([0.1 1.05.*max(Y)]); | ylim([0.1 1.05.*max(Y)]); |
63 | 63 | end % iname | end % iname |
64 |
File misc/3rdparty/cbrewer/interpolate_cbrewer.m changed (mode: 100644) (index e8b5e21..b108cf1) | |||
1 | 1 | function [interp_cmap]=interpolate_cbrewer(cbrew_init, interp_method, ncolors) | function [interp_cmap]=interpolate_cbrewer(cbrew_init, interp_method, ncolors) |
2 | % | ||
2 | % | ||
3 | 3 | % INTERPOLATE_CBREWER - interpolate a colorbrewer map to ncolors levels | % INTERPOLATE_CBREWER - interpolate a colorbrewer map to ncolors levels |
4 | 4 | % | % |
5 | 5 | % INPUT: | % INPUT: |
... | ... | function [interp_cmap]=interpolate_cbrewer(cbrew_init, interp_method, ncolors) | |
10 | 10 | % 'spline' - spline interpolation | % 'spline' - spline interpolation |
11 | 11 | % 'cubic' - bicubic interpolation as long as the data is | % 'cubic' - bicubic interpolation as long as the data is |
12 | 12 | % uniformly spaced, otherwise the same as 'spline' | % uniformly spaced, otherwise the same as 'spline' |
13 | % - ncolors=desired number of colors | ||
13 | % - ncolors=desired number of colors | ||
14 | 14 | % | % |
15 | 15 | % Author: Charles Robert | % Author: Charles Robert |
16 | 16 | % email: tannoudji@hotmail.com | % email: tannoudji@hotmail.com |
File misc/3rdparty/cbrewer/plot_brewer_cmap.m changed (mode: 100644) (index a5cab9e..ce0748b) | |||
... | ... | cnames{3,:}={'Accent', 'Dark2', 'Paired', 'Pastel1', 'Pastel2', 'Set1', 'Set2', | |
18 | 18 | ||
19 | 19 | figure('position', [314 327 807 420]) | figure('position', [314 327 807 420]) |
20 | 20 | for itype=1:3 | for itype=1:3 |
21 | |||
21 | |||
22 | 22 | %fh(itype)=figure(); | %fh(itype)=figure(); |
23 | 23 | subplot(1,3,itype) | subplot(1,3,itype) |
24 | |||
24 | |||
25 | 25 | for iname=1:length(cnames{itype,:}) | for iname=1:length(cnames{itype,:}) |
26 | |||
26 | |||
27 | 27 | ncol=length(colorbrewer.(ctypes{itype}).(cnames{itype}{iname})); | ncol=length(colorbrewer.(ctypes{itype}).(cnames{itype}{iname})); |
28 | 28 | fg=1./ncol; % geometrical factor | fg=1./ncol; % geometrical factor |
29 | 29 |
File misc/3rdparty/comp_struct/comp_struct.m changed (mode: 100644) (index 7d022db..e6d6113) | |||
... | ... | function [common, d1, d2] = comp_struct(s1,s2,prt,pse,tol,n1,n2) | |
36 | 36 | ||
37 | 37 | %% default arguent check | %% default arguent check |
38 | 38 | if nargin < 2 | if nargin < 2 |
39 | help comp_struct; error('I / O error'); | ||
39 | help comp_struct; error('I / O error'); | ||
40 | 40 | end | end |
41 | 41 | ||
42 | 42 | if nargin < 3 || isempty(prt); prt = 0; end | if nargin < 3 || isempty(prt); prt = 0; end |
... | ... | d1 = s1; d2 = s2; common = s1; | |
56 | 56 | flag = [0 0]; | flag = [0 0]; |
57 | 57 | % test entire structure | % test entire structure |
58 | 58 | if ~isequal(s1,s2) | if ~isequal(s1,s2) |
59 | % differances noted - parse | ||
60 | if isstruct(s1) && isstruct(s2) | ||
61 | % both structures - once sub structures are tested, do not | ||
62 | % modify the parrent | ||
63 | flag(2) = 1; | ||
64 | % both structures - get the field names for each structure | ||
65 | fn1 = fieldnames(s1); | ||
66 | fn2 = fieldnames(s2); | ||
67 | % missing fields? (common was a copy of s1 - so only s1 needs checking) | ||
68 | temp = find(~ismember(fn1,fn2)); | ||
69 | for ii = 1:numel(temp) | ||
70 | % drop unique fields | ||
71 | common = rmfield(common,fn1{temp(ii)}); | ||
72 | end | ||
73 | % get the common fields | ||
74 | fn = fieldnames(common); | ||
75 | % missing fields in set 1 | ||
76 | for ii = 1:numel(fn) | ||
77 | % common field - recurse and test | ||
78 | for jj = 1:min([numel(d1) numel(d2)]) | ||
79 | [common(jj).(fn{ii}) d1(jj).(fn{ii}) d2(jj).(fn{ii})] = ... | ||
80 | comp_struct(s1(jj).(fn{ii}),s2(jj).(fn{ii}), ... | ||
81 | prt,pse,tol, ... | ||
82 | [n1 '(' num2str(jj) ').' fn{ii}], ... | ||
83 | [n2 '(' num2str(jj) ').' fn{ii}]); | ||
84 | end | ||
85 | end | ||
86 | % one or both not structures evaluate | ||
87 | elseif isstruct(s1) | ||
88 | % first variable is structure - second is not | ||
89 | if prt | ||
90 | fprintf('Error: %s is a structure and %s is not a structure\n',n1,n2); | ||
91 | end | ||
92 | if pse | ||
93 | uiwait(msgbox(sprintf('Error: %s is a structure and %s is not a structure\n',n1,n2))) | ||
94 | end | ||
95 | % flag purge | ||
96 | flag(1) = 1; | ||
97 | |||
98 | elseif isstruct(s2) | ||
99 | % second variable is structure - first is not | ||
100 | if prt | ||
101 | fprintf('Error: %s is not a structure and %s is a structure\n',n1,n2); | ||
102 | end | ||
103 | if pse; pause; end | ||
104 | % flag purge | ||
105 | flag(1) = 1; | ||
106 | else | ||
107 | % the same? | ||
108 | if ~isequal(s1,s2) | ||
109 | flag(1) = 1; | ||
110 | % not the same - differance? | ||
111 | % class error | ||
112 | if ~strcmp(class(s1),class(s2)) | ||
113 | % different classes | ||
114 | if prt | ||
115 | fprintf('Error: %s is class %s and %s class %s\n',n1,class(s1),n2,class(s2)); | ||
116 | end | ||
117 | if pse; pause; end | ||
118 | flag(1) = 1; | ||
119 | else | ||
120 | % tolerance error? | ||
121 | if min(size(s1) == size(s2)) && ... | ||
122 | (isa(s1,'single') || isa(s1,'double')) | ||
123 | % tolerance match? | ||
124 | if numel(find(abs(s1-s2) < tol)) == numel(s1) | ||
125 | flag(1) = 0; | ||
126 | end | ||
127 | else | ||
128 | % print and pause? | ||
129 | if prt > 1 | ||
130 | fprintf('%s is ',n1); disp(s1); | ||
131 | fprintf('\b, %s is ',n2); disp(s2); | ||
132 | end | ||
133 | if pse > 1; pause; end | ||
134 | end | ||
135 | end | ||
136 | end | ||
137 | end | ||
59 | % differances noted - parse | ||
60 | if isstruct(s1) && isstruct(s2) | ||
61 | % both structures - once sub structures are tested, do not | ||
62 | % modify the parrent | ||
63 | flag(2) = 1; | ||
64 | % both structures - get the field names for each structure | ||
65 | fn1 = fieldnames(s1); | ||
66 | fn2 = fieldnames(s2); | ||
67 | % missing fields? (common was a copy of s1 - so only s1 needs checking) | ||
68 | temp = find(~ismember(fn1,fn2)); | ||
69 | for ii = 1:numel(temp) | ||
70 | % drop unique fields | ||
71 | common = rmfield(common,fn1{temp(ii)}); | ||
72 | end | ||
73 | % get the common fields | ||
74 | fn = fieldnames(common); | ||
75 | % missing fields in set 1 | ||
76 | for ii = 1:numel(fn) | ||
77 | % common field - recurse and test | ||
78 | for jj = 1:min([numel(d1) numel(d2)]) | ||
79 | [common(jj).(fn{ii}) d1(jj).(fn{ii}) d2(jj).(fn{ii})] = ... | ||
80 | comp_struct(s1(jj).(fn{ii}),s2(jj).(fn{ii}), ... | ||
81 | prt,pse,tol, ... | ||
82 | [n1 '(' num2str(jj) ').' fn{ii}], ... | ||
83 | [n2 '(' num2str(jj) ').' fn{ii}]); | ||
84 | end | ||
85 | end | ||
86 | % one or both not structures evaluate | ||
87 | elseif isstruct(s1) | ||
88 | % first variable is structure - second is not | ||
89 | if prt | ||
90 | fprintf('Error: %s is a structure and %s is not a structure\n',n1,n2); | ||
91 | end | ||
92 | if pse | ||
93 | uiwait(msgbox(sprintf('Error: %s is a structure and %s is not a structure\n',n1,n2))) | ||
94 | end | ||
95 | % flag purge | ||
96 | flag(1) = 1; | ||
97 | |||
98 | elseif isstruct(s2) | ||
99 | % second variable is structure - first is not | ||
100 | if prt | ||
101 | fprintf('Error: %s is not a structure and %s is a structure\n',n1,n2); | ||
102 | end | ||
103 | if pse; pause; end | ||
104 | % flag purge | ||
105 | flag(1) = 1; | ||
106 | else | ||
107 | % the same? | ||
108 | if ~isequal(s1,s2) | ||
109 | flag(1) = 1; | ||
110 | % not the same - differance? | ||
111 | % class error | ||
112 | if ~strcmp(class(s1),class(s2)) | ||
113 | % different classes | ||
114 | if prt | ||
115 | fprintf('Error: %s is class %s and %s class %s\n',n1,class(s1),n2,class(s2)); | ||
116 | end | ||
117 | if pse; pause; end | ||
118 | flag(1) = 1; | ||
119 | else | ||
120 | % tolerance error? | ||
121 | if min(size(s1) == size(s2)) && ... | ||
122 | (isa(s1,'single') || isa(s1,'double')) | ||
123 | % tolerance match? | ||
124 | if numel(find(abs(s1-s2) < tol)) == numel(s1) | ||
125 | flag(1) = 0; | ||
126 | end | ||
127 | else | ||
128 | % print and pause? | ||
129 | if prt > 1 | ||
130 | fprintf('%s is ',n1); disp(s1); | ||
131 | fprintf('\b, %s is ',n2); disp(s2); | ||
132 | end | ||
133 | if pse > 1; pause; end | ||
134 | end | ||
135 | end | ||
136 | end | ||
137 | end | ||
138 | 138 | end | end |
139 | 139 | ||
140 | 140 | ||
141 | 141 | %% keep or delete | %% keep or delete |
142 | 142 | if flag(1) && ~flag(2) | if flag(1) && ~flag(2) |
143 | % denote error | ||
144 | common = []; | ||
143 | % denote error | ||
144 | common = []; | ||
145 | 145 | elseif ~flag(2) | elseif ~flag(2) |
146 | % remove from error structures | ||
147 | d1 = []; | ||
148 | d2 = []; | ||
146 | % remove from error structures | ||
147 | d1 = []; | ||
148 | d2 = []; | ||
149 | 149 | end | end |
150 | 150 | ||
151 | 151 | ||
152 | 152 | %% purge empty fields | %% purge empty fields |
153 | 153 | % test common | % test common |
154 | 154 | if isstruct(common) | if isstruct(common) |
155 | % fieldnames | ||
156 | fn = fieldnames(common); | ||
157 | for ii = 1:numel(fn) | ||
158 | temp = 1; | ||
159 | % test for empty field | ||
160 | for jj = 1:numel(common) | ||
161 | if ~isempty(common(jj).(fn{ii})); temp = 0; end | ||
162 | end | ||
163 | % purge if field was empty | ||
164 | if temp | ||
165 | common = rmfield(common,fn{ii}); | ||
166 | end | ||
167 | end | ||
155 | % fieldnames | ||
156 | fn = fieldnames(common); | ||
157 | for ii = 1:numel(fn) | ||
158 | temp = 1; | ||
159 | % test for empty field | ||
160 | for jj = 1:numel(common) | ||
161 | if ~isempty(common(jj).(fn{ii})); temp = 0; end | ||
162 | end | ||
163 | % purge if field was empty | ||
164 | if temp | ||
165 | common = rmfield(common,fn{ii}); | ||
166 | end | ||
167 | end | ||
168 | 168 | end | end |
169 | 169 | % test d1 | % test d1 |
170 | 170 | if isstruct(d1) | if isstruct(d1) |
171 | % fieldnames | ||
172 | fn = fieldnames(d1); | ||
173 | for ii = 1:numel(fn) | ||
174 | temp = 1; | ||
175 | % test for empty field | ||
176 | for jj = 1:numel(d1) | ||
177 | if ~isempty(d1(jj).(fn{ii})); temp = 0; end | ||
178 | end | ||
179 | % purge if field was empty | ||
180 | if temp | ||
181 | d1 = rmfield(d1,fn{ii}); | ||
182 | end | ||
183 | end | ||
171 | % fieldnames | ||
172 | fn = fieldnames(d1); | ||
173 | for ii = 1:numel(fn) | ||
174 | temp = 1; | ||
175 | % test for empty field | ||
176 | for jj = 1:numel(d1) | ||
177 | if ~isempty(d1(jj).(fn{ii})); temp = 0; end | ||
178 | end | ||
179 | % purge if field was empty | ||
180 | if temp | ||
181 | d1 = rmfield(d1,fn{ii}); | ||
182 | end | ||
183 | end | ||
184 | 184 | end | end |
185 | 185 | % test d2 | % test d2 |
186 | 186 | if isstruct(d2) | if isstruct(d2) |
187 | % fieldnames | ||
188 | fn = fieldnames(d2); | ||
189 | for ii = 1:numel(fn) | ||
190 | temp = 1; | ||
191 | % test for empty field | ||
192 | for jj = 1:numel(d2) | ||
193 | if ~isempty(d2(jj).(fn{ii})); temp = 0; end | ||
194 | end | ||
195 | % purge if field was empty | ||
196 | if temp | ||
197 | d2 = rmfield(d2,fn{ii}); | ||
198 | end | ||
199 | end | ||
187 | % fieldnames | ||
188 | fn = fieldnames(d2); | ||
189 | for ii = 1:numel(fn) | ||
190 | temp = 1; | ||
191 | % test for empty field | ||
192 | for jj = 1:numel(d2) | ||
193 | if ~isempty(d2(jj).(fn{ii})); temp = 0; end | ||
194 | end | ||
195 | % purge if field was empty | ||
196 | if temp | ||
197 | d2 = rmfield(d2,fn{ii}); | ||
198 | end | ||
199 | end | ||
200 | 200 | end | end |
201 | 201 | ||
202 | 202 | ||
203 | 203 | %% test for null fields | %% test for null fields |
204 | 204 | if isstruct(common) | if isstruct(common) |
205 | % fieldnames | ||
206 | if isempty(fieldnames(common)); common = []; end | ||
205 | % fieldnames | ||
206 | if isempty(fieldnames(common)); common = []; end | ||
207 | 207 | end | end |
208 | 208 | if isstruct(d1) | if isstruct(d1) |
209 | % fieldnames | ||
210 | if isempty(fieldnames(d1)); d1 = []; end | ||
209 | % fieldnames | ||
210 | if isempty(fieldnames(d1)); d1 = []; end | ||
211 | 211 | end | end |
212 | 212 | if isstruct(d2) | if isstruct(d2) |
213 | % fieldnames | ||
214 | if isempty(fieldnames(d2)); d2 = []; end | ||
213 | % fieldnames | ||
214 | if isempty(fieldnames(d2)); d2 = []; end | ||
215 | 215 | end | end |
File misc/3rdparty/comp_struct/comp_struct_old.m changed (mode: 100644) (index 34d9522..42d3967) | |||
... | ... | eval([char(n2) ' = s2;']); | |
57 | 57 | ner1 = numel(er1); ner2 = numel(er2); | ner1 = numel(er1); ner2 = numel(er2); |
58 | 58 | % check that same number of errors were listed in each cell | % check that same number of errors were listed in each cell |
59 | 59 | if ner1 ~= ner2 | if ner1 ~= ner2 |
60 | error(char('Something went very wrong in capturing errors.', ... | ||
61 | 'If possible, please email the two structures to moarant@gmail.com')); | ||
60 | error(char('Something went very wrong in capturing errors.', ... | ||
61 | 'If possible, please email the two structures to moarant@gmail.com')); | ||
62 | 62 | else | else |
63 | n = ner1; | ||
63 | n = ner1; | ||
64 | 64 | end | end |
65 | 65 | ||
66 | 66 | % populate the error list | % populate the error list |
67 | 67 | df = cell(n,3); | df = cell(n,3); |
68 | 68 | % loop the error lists | % loop the error lists |
69 | 69 | for ii = 1:n | for ii = 1:n |
70 | % capture the error text list | ||
71 | temp1 = er1{ii}; temp2 = er2{ii}; | ||
72 | |||
73 | % see if the second structure exists | ||
74 | if isempty(regexp(temp2,'is missing', 'once')) | ||
75 | % record text error | ||
76 | df{ii,1} = temp2; | ||
77 | % see if matching structure 1 is missing (struture 2 listed as unique) | ||
78 | if isempty(regexp(temp2,'is unique', 'once')) | ||
79 | % unique to structure 2 - record value | ||
80 | junk = regexp(temp2,' ','once'); | ||
81 | df{ii,3} = eval(temp2(1:junk-1)); | ||
82 | else | ||
83 | % exists in 1 and 2 - evaluate types | ||
84 | junk = regexp(temp2,' ','once'); temp2(junk:end) = []; | ||
85 | junk = strfind(temp2,'.'); trash = temp2(junk+1:end); temp2(junk:end) = []; | ||
86 | % if trash is empty, the field is a sub structure - list sub fields | ||
87 | if isempty(trash) | ||
88 | df{ii,3} = eval(['fieldnames(' temp2 ')'])'; | ||
89 | else | ||
90 | % if numel(temp2) is > 1, then this is an indexed field | ||
91 | % list the number if indexes and the type | ||
92 | if (numel(eval(temp2)) - 1) | ||
93 | df{ii,3} = sprintf('%s(#%g).%s is class %s', ... | ||
94 | temp2,numel(eval(temp2)),trash,class(eval([temp2 '.' trash]))); | ||
95 | else | ||
96 | % list the contents of the field | ||
97 | df{ii,3} = eval([temp2 '.' trash]); | ||
98 | end | ||
99 | end | ||
100 | end | ||
101 | end | ||
102 | if isempty(regexp(temp1,'is missing', 'once')) | ||
103 | % record text error | ||
104 | df{ii,1} = temp1; | ||
105 | % see if matching structure 1 is missing (struture 2 listed as unique) | ||
106 | if isempty(regexp(temp1,'is unique', 'once')) | ||
107 | % unique to structure 2 - record value | ||
108 | junk = regexp(temp1,' ','once'); | ||
109 | df{ii,2} = eval([temp1(1:junk-1)]); | ||
110 | else | ||
111 | % exists in 1 and 2 - evaluate types | ||
112 | junk = regexp(temp1,' ','once'); temp1(junk:end) = []; | ||
113 | junk = strfind(temp1,'.'); trash = temp1(junk+1:end); temp1(junk:end) = []; | ||
114 | % if trash is empty, the field is a sub structure - list sub fields | ||
115 | if isempty(trash) | ||
116 | df{ii,2} = eval(['fieldnames(' temp1 ')'])'; | ||
117 | else | ||
118 | % if numel(temp2) is > 1, then this is an indexed field | ||
119 | % list the number if indexes and the type | ||
120 | if (numel(eval(temp1)) - 1) | ||
121 | df{ii,2} = sprintf('%s(#%g).%s is class %s', ... | ||
122 | temp1,numel(eval(temp1)),trash,class(eval([temp1 '.' trash]))); | ||
123 | else | ||
124 | % list the contents of the field | ||
125 | df{ii,2} = eval([temp1 '.' trash]); | ||
126 | end | ||
127 | end | ||
128 | end | ||
129 | end | ||
70 | % capture the error text list | ||
71 | temp1 = er1{ii}; temp2 = er2{ii}; | ||
72 | |||
73 | % see if the second structure exists | ||
74 | if isempty(regexp(temp2,'is missing', 'once')) | ||
75 | % record text error | ||
76 | df{ii,1} = temp2; | ||
77 | % see if matching structure 1 is missing (struture 2 listed as unique) | ||
78 | if isempty(regexp(temp2,'is unique', 'once')) | ||
79 | % unique to structure 2 - record value | ||
80 | junk = regexp(temp2,' ','once'); | ||
81 | df{ii,3} = eval(temp2(1:junk-1)); | ||
82 | else | ||
83 | % exists in 1 and 2 - evaluate types | ||
84 | junk = regexp(temp2,' ','once'); temp2(junk:end) = []; | ||
85 | junk = strfind(temp2,'.'); trash = temp2(junk+1:end); temp2(junk:end) = []; | ||
86 | % if trash is empty, the field is a sub structure - list sub fields | ||
87 | if isempty(trash) | ||
88 | df{ii,3} = eval(['fieldnames(' temp2 ')'])'; | ||
89 | else | ||
90 | % if numel(temp2) is > 1, then this is an indexed field | ||
91 | % list the number if indexes and the type | ||
92 | if (numel(eval(temp2)) - 1) | ||
93 | df{ii,3} = sprintf('%s(#%g).%s is class %s', ... | ||
94 | temp2,numel(eval(temp2)),trash,class(eval([temp2 '.' trash]))); | ||
95 | else | ||
96 | % list the contents of the field | ||
97 | df{ii,3} = eval([temp2 '.' trash]); | ||
98 | end | ||
99 | end | ||
100 | end | ||
101 | end | ||
102 | if isempty(regexp(temp1,'is missing', 'once')) | ||
103 | % record text error | ||
104 | df{ii,1} = temp1; | ||
105 | % see if matching structure 1 is missing (struture 2 listed as unique) | ||
106 | if isempty(regexp(temp1,'is unique', 'once')) | ||
107 | % unique to structure 2 - record value | ||
108 | junk = regexp(temp1,' ','once'); | ||
109 | df{ii,2} = eval([temp1(1:junk-1)]); | ||
110 | else | ||
111 | % exists in 1 and 2 - evaluate types | ||
112 | junk = regexp(temp1,' ','once'); temp1(junk:end) = []; | ||
113 | junk = strfind(temp1,'.'); trash = temp1(junk+1:end); temp1(junk:end) = []; | ||
114 | % if trash is empty, the field is a sub structure - list sub fields | ||
115 | if isempty(trash) | ||
116 | df{ii,2} = eval(['fieldnames(' temp1 ')'])'; | ||
117 | else | ||
118 | % if numel(temp2) is > 1, then this is an indexed field | ||
119 | % list the number if indexes and the type | ||
120 | if (numel(eval(temp1)) - 1) | ||
121 | df{ii,2} = sprintf('%s(#%g).%s is class %s', ... | ||
122 | temp1,numel(eval(temp1)),trash,class(eval([temp1 '.' trash]))); | ||
123 | else | ||
124 | % list the contents of the field | ||
125 | df{ii,2} = eval([temp1 '.' trash]); | ||
126 | end | ||
127 | end | ||
128 | end | ||
129 | end | ||
130 | 130 | end | end |
131 | 131 | ||
132 | 132 | % optional text output | % optional text output |
133 | 133 | if prt | if prt |
134 | fprintf('\n Error table\n'); | ||
135 | for ii = 1:n | ||
136 | fprintf('\n%s \n',df{ii,1}); | ||
137 | fprintf('Structure 1: '); | ||
138 | if isempty(df{ii,2}); fprintf('\n'); else; disp(df{ii,2}); end | ||
139 | fprintf('Structure 2: '); | ||
140 | if isempty(df{ii,3}); fprintf('\n'); else; disp(df{ii,3}); end | ||
141 | end | ||
142 | fprintf('\n\n\n\n\n'); | ||
134 | fprintf('\n Error table\n'); | ||
135 | for ii = 1:n | ||
136 | fprintf('\n%s \n',df{ii,1}); | ||
137 | fprintf('Structure 1: '); | ||
138 | if isempty(df{ii,2}); fprintf('\n'); else; disp(df{ii,2}); end | ||
139 | fprintf('Structure 2: '); | ||
140 | if isempty(df{ii,3}); fprintf('\n'); else; disp(df{ii,3}); end | ||
141 | end | ||
142 | fprintf('\n\n\n\n\n'); | ||
143 | 143 | end | end |
144 | 144 | ||
145 | 145 | ||
... | ... | end | |
148 | 148 | function [match, er1, er2] = comp_struct_loop(s1,s2,prt,pse,tol,n1,n2,wbf) | function [match, er1, er2] = comp_struct_loop(s1,s2,prt,pse,tol,n1,n2,wbf) |
149 | 149 | ||
150 | 150 | % init outputs | % init outputs |
151 | match = {}; er1 = {}; er2 = {}; | ||
151 | match = {}; er1 = {}; er2 = {}; | ||
152 | 152 | ||
153 | 153 | % test to see if both are structures | % test to see if both are structures |
154 | 154 | if isstruct(s1) && isstruct(s2) | if isstruct(s1) && isstruct(s2) |
155 | % both structures - get the field names for each structure | ||
156 | fn1 = fieldnames(s1); | ||
157 | fn2 = fieldnames(s2); | ||
158 | % missing fields? get the common fields | ||
159 | temp1 = ismember(fn1,fn2); | ||
160 | temp2 = ismember(fn2,fn1); | ||
161 | % missing fields in set 1 | ||
162 | for ii = find(~temp2)' | ||
163 | er1{end+1} = sprintf('%s is missing field %s',n1,fn2{ii}); | ||
164 | er2{end+1} = sprintf('%s.%s is unique',n2,fn2{ii}); | ||
155 | % both structures - get the field names for each structure | ||
156 | fn1 = fieldnames(s1); | ||
157 | fn2 = fieldnames(s2); | ||
158 | % missing fields? get the common fields | ||
159 | temp1 = ismember(fn1,fn2); | ||
160 | temp2 = ismember(fn2,fn1); | ||
161 | % missing fields in set 1 | ||
162 | for ii = find(~temp2)' | ||
163 | er1{end+1} = sprintf('%s is missing field %s',n1,fn2{ii}); | ||
164 | er2{end+1} = sprintf('%s.%s is unique',n2,fn2{ii}); | ||
165 | 165 | % er2{end+1} = s2.(fn2{ii}); | % er2{end+1} = s2.(fn2{ii}); |
166 | if prt > 1; fprintf('%s\n',er1{end}); end; if pse; pause; end | ||
167 | end | ||
168 | % missing fields in set 2 | ||
169 | for ii = find(~temp1)' | ||
170 | er2{end+1} = sprintf('%s is missing field %s',n2,fn1{ii}); | ||
171 | er1{end+1} = sprintf('%s.%s is unique',n1,fn1{ii}); | ||
166 | if prt > 1; fprintf('%s\n',er1{end}); end; if pse; pause; end | ||
167 | end | ||
168 | % missing fields in set 2 | ||
169 | for ii = find(~temp1)' | ||
170 | er2{end+1} = sprintf('%s is missing field %s',n2,fn1{ii}); | ||
171 | er1{end+1} = sprintf('%s.%s is unique',n1,fn1{ii}); | ||
172 | 172 | % er1{end+1} = s1.(fn1{ii}); | % er1{end+1} = s1.(fn1{ii}); |
173 | if prt > 1; fprintf('%s\n',er2{end}); end; if pse; pause; end | ||
174 | end | ||
175 | % index sizes match? i.e. do both structures have the same # of indexes? | ||
176 | inda = numel(s1); indb = numel(s2); inder = inda-indb; | ||
177 | if inder < 0 | ||
178 | % struct 1 is smaller | ||
179 | for ii = inda+1:indb | ||
180 | er1{end+1} = sprintf('%s(%g) is missing',n1,ii); | ||
181 | er2{end+1} = sprintf('%s(%g) is unique',n2,ii); | ||
182 | if prt > 1; fprintf('%s\n',er1{end}); end; if pse; pause; end | ||
183 | end | ||
184 | elseif inder > 0 | ||
185 | % index 2 is smaller | ||
186 | for ii = indb+1:inda | ||
187 | er2{end+1} = sprintf('%s(%g) is missing',n2,ii); | ||
188 | er1{end+1} = sprintf('%s(%g) is unique',n1,ii); | ||
189 | if prt > 1; fprintf('%s\n',er2{end}); end; if pse; pause; end | ||
190 | end | ||
191 | end | ||
192 | % get common fields | ||
193 | fn = fn1(temp1); fnn = numel(fn); | ||
194 | % loop through structure 1 and match to structure 2 | ||
195 | ind = min([inda indb]); cnt = 0; | ||
196 | if wbf; wb = waitbar(0,'Comparing ....'); end | ||
197 | for ii = 1:ind | ||
198 | % loop each index | ||
199 | for jj = 1:fnn | ||
200 | % loop common field names | ||
201 | if wbf; cnt = cnt + 1; waitbar(cnt/(ind*fnn),wb); drawnow; end | ||
202 | % add index and field name to the structure name | ||
203 | n1p = sprintf('%s(%g).%s',n1,ii,fn{jj}); | ||
204 | n2p = sprintf('%s(%g).%s',n2,ii,fn{jj}); | ||
205 | % recurse - run the program again on the sub-set of the structure | ||
206 | [m e1 e2] = comp_struct_loop(s1(ii).(fn{jj}),s2(ii).(fn{jj}),prt,pse, ... | ||
207 | tol,n1p,n2p,wbf); | ||
208 | % add the sub-set (field name) results to the total results | ||
209 | match = [match m']; | ||
210 | if ~isempty(e1) || ~isempty(e2) | ||
211 | er1 = [er1 e1']; er2 = [er2 e2']; | ||
212 | end | ||
213 | end | ||
214 | end | ||
215 | if wbf; close(wb); end | ||
173 | if prt > 1; fprintf('%s\n',er2{end}); end; if pse; pause; end | ||
174 | end | ||
175 | % index sizes match? i.e. do both structures have the same # of indexes? | ||
176 | inda = numel(s1); indb = numel(s2); inder = inda-indb; | ||
177 | if inder < 0 | ||
178 | % struct 1 is smaller | ||
179 | for ii = inda+1:indb | ||
180 | er1{end+1} = sprintf('%s(%g) is missing',n1,ii); | ||
181 | er2{end+1} = sprintf('%s(%g) is unique',n2,ii); | ||
182 | if prt > 1; fprintf('%s\n',er1{end}); end; if pse; pause; end | ||
183 | end | ||
184 | elseif inder > 0 | ||
185 | % index 2 is smaller | ||
186 | for ii = indb+1:inda | ||
187 | er2{end+1} = sprintf('%s(%g) is missing',n2,ii); | ||
188 | er1{end+1} = sprintf('%s(%g) is unique',n1,ii); | ||
189 | if prt > 1; fprintf('%s\n',er2{end}); end; if pse; pause; end | ||
190 | end | ||
191 | end | ||
192 | % get common fields | ||
193 | fn = fn1(temp1); fnn = numel(fn); | ||
194 | % loop through structure 1 and match to structure 2 | ||
195 | ind = min([inda indb]); cnt = 0; | ||
196 | if wbf; wb = waitbar(0,'Comparing ....'); end | ||
197 | for ii = 1:ind | ||
198 | % loop each index | ||
199 | for jj = 1:fnn | ||
200 | % loop common field names | ||
201 | if wbf; cnt = cnt + 1; waitbar(cnt/(ind*fnn),wb); drawnow; end | ||
202 | % add index and field name to the structure name | ||
203 | n1p = sprintf('%s(%g).%s',n1,ii,fn{jj}); | ||
204 | n2p = sprintf('%s(%g).%s',n2,ii,fn{jj}); | ||
205 | % recurse - run the program again on the sub-set of the structure | ||
206 | [m e1 e2] = comp_struct_loop(s1(ii).(fn{jj}),s2(ii).(fn{jj}),prt,pse, ... | ||
207 | tol,n1p,n2p,wbf); | ||
208 | % add the sub-set (field name) results to the total results | ||
209 | match = [match m']; | ||
210 | if ~isempty(e1) || ~isempty(e2) | ||
211 | er1 = [er1 e1']; er2 = [er2 e2']; | ||
212 | end | ||
213 | end | ||
214 | end | ||
215 | if wbf; close(wb); end | ||
216 | 216 | else | else |
217 | % both are non-structures - compare | ||
218 | % get the varable class and test | ||
219 | c1 = class(s1); c2 = class(s2); | ||
220 | if strcmp(c1,c2); | ||
221 | % both are the same class | ||
222 | if isequal(s1,s2) | ||
223 | % results are equal | ||
224 | match{end+1} = sprintf('%s and %s match',n1,n2); | ||
225 | if prt == 3; fprintf('%s\n',match{end}); end | ||
226 | else | ||
227 | % same class but not equal | ||
228 | % calculate error if type is single or double | ||
229 | % test for function type match if function handle | ||
230 | switch c1 | ||
231 | case {'single', 'double'}, | ||
232 | if numel(s1) ~= numel(s2) || size(s1,1) ~= size(s2,1) | ||
233 | er = 1; | ||
234 | else | ||
235 | er = norm(s1-s2); | ||
236 | end | ||
237 | case {'function_handle'}, | ||
238 | s1f = functions(s1); s2f = functions(s2); | ||
239 | if strcmp(s1f.function,s2f.function) | ||
240 | % same function with different values - record deviation and exit | ||
241 | er = 0; | ||
242 | er1{end+1} = sprintf('%s and %s are both %s but have different values', ... | ||
243 | n1,n2,char(s1)); | ||
244 | er2{end+1} = er1{end}; | ||
245 | if prt > 1; fprintf('%s\n',er1{end}); end; | ||
246 | if pse > 1; pause; end | ||
247 | else | ||
248 | er = 1; | ||
249 | end | ||
250 | otherwise, er = 1; | ||
251 | end | ||
252 | % test error - error will be 0 (no error) or 1 (error) for all | ||
253 | % classes except double and single. double and single are the | ||
254 | % actual error which is tested against the tolerance | ||
255 | % this was done for cases where structures are run on different | ||
256 | % platforms and numerical precision errors are observed | ||
257 | if er > tol | ||
258 | % sets do not match | ||
259 | er1{end+1} = sprintf('%s and %s do not match',n1,n2); | ||
260 | er2{end+1} = sprintf('%s and %s do not match',n2,n1); | ||
261 | if prt > 1; fprintf('%s\n',er1{end}); end; | ||
262 | if pse > 1; pause; end | ||
263 | else | ||
264 | % sets are a tolerance match | ||
265 | match{end+1} = sprintf('%s and %s are tolerance match',n1,n2); | ||
266 | if prt > 2; fprintf('%s\n',match{end}); end | ||
267 | end | ||
268 | end | ||
269 | else | ||
270 | % fields are different classes | ||
271 | er1{end+1} = sprintf('%s is class %s, %s is class %s',n1,c1,n2,c2); | ||
272 | er2{end+1} = sprintf('%s is class %s, %s is class %s',n2,c2,n1,c1); | ||
273 | if prt > 1; fprintf('%s\n',er1{end}); end | ||
274 | if pse; pause; end | ||
275 | end | ||
217 | % both are non-structures - compare | ||
218 | % get the varable class and test | ||
219 | c1 = class(s1); c2 = class(s2); | ||
220 | if strcmp(c1,c2); | ||
221 | % both are the same class | ||
222 | if isequal(s1,s2) | ||
223 | % results are equal | ||
224 | match{end+1} = sprintf('%s and %s match',n1,n2); | ||
225 | if prt == 3; fprintf('%s\n',match{end}); end | ||
226 | else | ||
227 | % same class but not equal | ||
228 | % calculate error if type is single or double | ||
229 | % test for function type match if function handle | ||
230 | switch c1 | ||
231 | case {'single', 'double'}, | ||
232 | if numel(s1) ~= numel(s2) || size(s1,1) ~= size(s2,1) | ||
233 | er = 1; | ||
234 | else | ||
235 | er = norm(s1-s2); | ||
236 | end | ||
237 | case {'function_handle'}, | ||
238 | s1f = functions(s1); s2f = functions(s2); | ||
239 | if strcmp(s1f.function,s2f.function) | ||
240 | % same function with different values - record deviation and exit | ||
241 | er = 0; | ||
242 | er1{end+1} = sprintf('%s and %s are both %s but have different values', ... | ||
243 | n1,n2,char(s1)); | ||
244 | er2{end+1} = er1{end}; | ||
245 | if prt > 1; fprintf('%s\n',er1{end}); end; | ||
246 | if pse > 1; pause; end | ||
247 | else | ||
248 | er = 1; | ||
249 | end | ||
250 | otherwise, er = 1; | ||
251 | end | ||
252 | % test error - error will be 0 (no error) or 1 (error) for all | ||
253 | % classes except double and single. double and single are the | ||
254 | % actual error which is tested against the tolerance | ||
255 | % this was done for cases where structures are run on different | ||
256 | % platforms and numerical precision errors are observed | ||
257 | if er > tol | ||
258 | % sets do not match | ||
259 | er1{end+1} = sprintf('%s and %s do not match',n1,n2); | ||
260 | er2{end+1} = sprintf('%s and %s do not match',n2,n1); | ||
261 | if prt > 1; fprintf('%s\n',er1{end}); end; | ||
262 | if pse > 1; pause; end | ||
263 | else | ||
264 | % sets are a tolerance match | ||
265 | match{end+1} = sprintf('%s and %s are tolerance match',n1,n2); | ||
266 | if prt > 2; fprintf('%s\n',match{end}); end | ||
267 | end | ||
268 | end | ||
269 | else | ||
270 | % fields are different classes | ||
271 | er1{end+1} = sprintf('%s is class %s, %s is class %s',n1,c1,n2,c2); | ||
272 | er2{end+1} = sprintf('%s is class %s, %s is class %s',n2,c2,n1,c1); | ||
273 | if prt > 1; fprintf('%s\n',er1{end}); end | ||
274 | if pse; pause; end | ||
275 | end | ||
276 | 276 | end | end |
277 | 277 | ||
278 | 278 | % transpose outputs | % transpose outputs |
File misc/3rdparty/comp_struct/comp_struct_test.m changed (mode: 100644) (index 86bfac4..a8f0b83) | |||
... | ... | fprintf('\n\n\nCase 3\n') | |
119 | 119 | a.a = 1; b.a = 1; | a.a = 1; b.a = 1; |
120 | 120 | a.b = 2; b.b = 1; | a.b = 2; b.b = 1; |
121 | 121 | a.c.a = 1; a.c.b = 2; b.c = 1; | a.c.a = 1; a.c.b = 2; b.c = 1; |
122 | a.d = cellstr('test')'; b.d = cellstr('test')'; | ||
123 | a.e = cellstr('test')'; b.e = cellstr('a')'; | ||
122 | a.d = cellstr('test')'; b.d = cellstr('test')'; | ||
123 | a.e = cellstr('test')'; b.e = cellstr('a')'; | ||
124 | 124 | a.f = 'tt'; b.f = 'tt'; | a.f = 'tt'; b.f = 'tt'; |
125 | 125 | a.g = 'tt'; b.g = 't'; | a.g = 'tt'; b.g = 't'; |
126 | 126 | a.h.a = 1; b.h.b = 1; | a.h.a = 1; b.h.b = 1; |
127 | 127 | a.i.a = 1; | a.i.a = 1; |
128 | 128 | a.j.a = @sin; b.j.a = @sin; | a.j.a = @sin; b.j.a = @sin; |
129 | 129 | a.j.b = @sin; b.j.b = @cos; | a.j.b = @sin; b.j.b = @cos; |
130 | x = .1; a.j.c = @(x) sin(x); x = .5; b.j.c = @(x) sin(x); | ||
130 | x = .1; a.j.c = @(x) sin(x); x = .5; b.j.c = @(x) sin(x); | ||
131 | 131 | a(2) = a(1); b(2) = b(1); a(3) = a(1); | a(2) = a(1); b(2) = b(1); a(3) = a(1); |
132 | 132 | ||
133 | 133 | ||
... | ... | str = char(97:122); | |
151 | 151 | ||
152 | 152 | % build structure | % build structure |
153 | 153 | for ii = 1:26 | for ii = 1:26 |
154 | stu1.(str(ii)) = rand(ceil(5*rand(1)),ceil(5*rand(1))); | ||
154 | stu1.(str(ii)) = rand(ceil(5*rand(1)),ceil(5*rand(1))); | ||
155 | 155 | end | end |
156 | 156 | stu2 = stu1; | stu2 = stu1; |
157 | 157 | for ii = 1:26 | for ii = 1:26 |
158 | if round(rand(1)) | ||
159 | if rand(1) > 0.3 | ||
160 | if round(rand) | ||
161 | stu2.(str(ii)) = rand(size(stu2.(str(ii)))); | ||
162 | else | ||
163 | stu2.(str(ii)) = stu2.(str(ii)) + 1e-8; | ||
164 | end | ||
165 | else | ||
166 | stu2.(str(ii)) = rand(ceil(5*rand(1)),ceil(5*rand(1))); | ||
167 | end | ||
168 | end | ||
158 | if round(rand(1)) | ||
159 | if rand(1) > 0.3 | ||
160 | if round(rand) | ||
161 | stu2.(str(ii)) = rand(size(stu2.(str(ii)))); | ||
162 | else | ||
163 | stu2.(str(ii)) = stu2.(str(ii)) + 1e-8; | ||
164 | end | ||
165 | else | ||
166 | stu2.(str(ii)) = rand(ceil(5*rand(1)),ceil(5*rand(1))); | ||
167 | end | ||
168 | end | ||
169 | 169 | end | end |
170 | 170 | ||
171 | 171 | [match, er1, er2] = comp_struct(stu1,stu2); | [match, er1, er2] = comp_struct(stu1,stu2); |
File misc/3rdparty/comp_struct/list_struct.m changed (mode: 100644) (index cb708fe..8fa354d) | |||
... | ... | if nargin < 3; n1 = inputname(1); end | |
19 | 19 | %% is the variable a structures | %% is the variable a structures |
20 | 20 | if isstruct(s1) | if isstruct(s1) |
21 | 21 | % structure - get the field names | % structure - get the field names |
22 | fn1 = fieldnames(s1); | ||
22 | fn1 = fieldnames(s1); | ||
23 | 23 | % added loop for indexed structured variables | % added loop for indexed structured variables |
24 | for jj = 1:size(s1,2) | ||
24 | for jj = 1:size(s1,2) | ||
25 | 25 | % loop through structure 1 | % loop through structure 1 |
26 | for ii = 1:length(fn1) | ||
26 | for ii = 1:length(fn1) | ||
27 | 27 | % clean display - add index if needed | % clean display - add index if needed |
28 | if size(s1,2) == 1; | ||
29 | n1p = [n1 '.' char(fn1(ii))]; | ||
30 | else | ||
31 | n1p = [n1 '(' num2str(jj) ').' char(fn1(ii))]; | ||
32 | end | ||
33 | list_struct(getfield(s1(jj),char(fn1(ii))),v,n1p); | ||
34 | end | ||
35 | end | ||
28 | if size(s1,2) == 1; | ||
29 | n1p = [n1 '.' char(fn1(ii))]; | ||
30 | else | ||
31 | n1p = [n1 '(' num2str(jj) ').' char(fn1(ii))]; | ||
32 | end | ||
33 | list_struct(getfield(s1(jj),char(fn1(ii))),v,n1p); | ||
34 | end | ||
35 | end | ||
36 | 36 | else | else |
37 | 37 | % not structure - display | % not structure - display |
38 | if v | ||
39 | if ischar(s1); | ||
40 | fprintf('Field: %s = %s\n',n1,s1); | ||
41 | elseif iscell(s1) | ||
42 | if isstruct(s1{1}) | ||
43 | for ii = 1:numel(s1) | ||
44 | temp = s1{ii}; | ||
45 | fn1 = fieldnames(temp); | ||
46 | for jj = 1:numel(fn1) | ||
47 | list_struct(getfield(temp,char(fn1(jj))),v,[char(n1) '{' num2str(ii) '}.' char(fn1(jj))]); | ||
48 | end | ||
49 | end | ||
50 | else | ||
51 | %disp(sprintf('Field: %s = %s',n1,s1{1:end})) | ||
52 | fprintf('Field: %s = %s\n',n1,s1{1}); | ||
53 | fprintf(' %s\n',s1{2:end}); | ||
54 | end | ||
55 | elseif isnumeric(s1) | ||
56 | fprintf('Field: %s = \n',n1); disp(s1) | ||
57 | else | ||
58 | fprintf('Field: %s = [%s]\n',n1,num2str(s1)); | ||
59 | end | ||
60 | else | ||
61 | fprintf('Field: %s\n',n1); | ||
62 | end | ||
38 | if v | ||
39 | if ischar(s1); | ||
40 | fprintf('Field: %s = %s\n',n1,s1); | ||
41 | elseif iscell(s1) | ||
42 | if isstruct(s1{1}) | ||
43 | for ii = 1:numel(s1) | ||
44 | temp = s1{ii}; | ||
45 | fn1 = fieldnames(temp); | ||
46 | for jj = 1:numel(fn1) | ||
47 | list_struct(getfield(temp,char(fn1(jj))),v,[char(n1) '{' num2str(ii) '}.' char(fn1(jj))]); | ||
48 | end | ||
49 | end | ||
50 | else | ||
51 | %disp(sprintf('Field: %s = %s',n1,s1{1:end})) | ||
52 | fprintf('Field: %s = %s\n',n1,s1{1}); | ||
53 | fprintf(' %s\n',s1{2:end}); | ||
54 | end | ||
55 | elseif isnumeric(s1) | ||
56 | fprintf('Field: %s = \n',n1); disp(s1) | ||
57 | else | ||
58 | fprintf('Field: %s = [%s]\n',n1,num2str(s1)); | ||
59 | end | ||
60 | else | ||
61 | fprintf('Field: %s\n',n1); | ||
62 | end | ||
63 | 63 | end | end |
File misc/3rdparty/heatmap.m changed (mode: 100644) (index af7812d..ef15089) | |||
... | ... | function [hImage, hText, hXText] = heatmap(mat, xlab, ylab, textmat, varargin) | |
6 | 6 | % | % |
7 | 7 | % INPUTS: | % INPUTS: |
8 | 8 | % * HEATMAP displays "matrix" as an image whose color intensities reflect | % * HEATMAP displays "matrix" as an image whose color intensities reflect |
9 | % the magnitude of the values in "matrix". | ||
9 | % the magnitude of the values in "matrix". | ||
10 | 10 | % | % |
11 | 11 | % * "xlabels" (and "ylabels") can be either a numeric vector or cell array | % * "xlabels" (and "ylabels") can be either a numeric vector or cell array |
12 | 12 | % of strings that represent the columns (or rows) of the matrix. If either | % of strings that represent the columns (or rows) of the matrix. If either |
13 | % is not specified or empty, no labels will be drawn. | ||
13 | % is not specified or empty, no labels will be drawn. | ||
14 | 14 | % | % |
15 | 15 | % * "textmat" can either be: 1 (or true), in which case the "matrix" values will be | % * "textmat" can either be: 1 (or true), in which case the "matrix" values will be |
16 | 16 | % displayed in each square, a format string, in which case the matrix | % displayed in each square, a format string, in which case the matrix |
... | ... | function [hImage, hText, hXText] = heatmap(mat, xlab, ylab, textmat, varargin) | |
48 | 48 | % default MATLAB displays NaN values using the color assigned to the | % default MATLAB displays NaN values using the color assigned to the |
49 | 49 | % lowest value in the colormap. Specifying this option automatically sets | % lowest value in the colormap. Specifying this option automatically sets |
50 | 50 | % the 'UseFigureColormap' option to false because the color mapping must | % the 'UseFigureColormap' option to false because the color mapping must |
51 | % be computed prior to setting the nan color. | ||
51 | % be computed prior to setting the nan color. | ||
52 | 52 | % | % |
53 | 53 | % * 'MinColorValue': A scalar number corresponding to the value of the data | % * 'MinColorValue': A scalar number corresponding to the value of the data |
54 | % that is mapped to the lowest color of the colormap. By default this is | ||
55 | % the minimum value of the matrix input. | ||
54 | % that is mapped to the lowest color of the colormap. By default this is | ||
55 | % the minimum value of the matrix input. | ||
56 | 56 | % | % |
57 | 57 | % * 'MaxColorValue': A scalar number corresponding to the value of the data | % * 'MaxColorValue': A scalar number corresponding to the value of the data |
58 | % that is mapped to the highest color of the colormap. By default this is | ||
59 | % the maximum value of the matrix input. | ||
60 | % | ||
58 | % that is mapped to the highest color of the colormap. By default this is | ||
59 | % the maximum value of the matrix input. | ||
60 | % | ||
61 | 61 | % * 'Parent': Handle to an axes object | % * 'Parent': Handle to an axes object |
62 | 62 | % | % |
63 | 63 | % * 'TextColor': Either a color specification of all the text displayed on | % * 'TextColor': Either a color specification of all the text displayed on |
... | ... | end | |
172 | 172 | % ---------------------- Heatmap Creation Functions ---------------------- | % ---------------------- Heatmap Creation Functions ---------------------- |
173 | 173 | ||
174 | 174 | % Parse PV inputs & return structure of parameters | % Parse PV inputs & return structure of parameters |
175 | function param = parseInputs(mat, varargin) | ||
175 | function param = parseInputs(mat, varargin) | ||
176 | 176 | ||
177 | 177 | p = inputParser; | p = inputParser; |
178 | 178 | p.addParamValue('Colormap',[]); %#ok<*NVREPL> | p.addParamValue('Colormap',[]); %#ok<*NVREPL> |
... | ... | param.ExplicitlyComputeImage = ~all(isnan(param.NaNColor)) ... NaNColor is speci | |
218 | 218 | % if param.IsGraphics2 && ~param.UseFigureColormap && ~isempty(param.ColorBar) % graphics v2 | % if param.IsGraphics2 && ~param.UseFigureColormap && ~isempty(param.ColorBar) % graphics v2 |
219 | 219 | % warning('heatmap:graphics2figurecolormap', 'The UseFigureColormap false option with colorbar is not supported in versions R2014b and above. In most such cases UseFigureColormap false is unnecessary'); | % warning('heatmap:graphics2figurecolormap', 'The UseFigureColormap false option with colorbar is not supported in versions R2014b and above. In most such cases UseFigureColormap false is unnecessary'); |
220 | 220 | % end | % end |
221 | |||
221 | |||
222 | 222 | ||
223 | 223 | end | end |
224 | 224 | ||
... | ... | else | |
312 | 312 | tickAxis = 'X'; | tickAxis = 'X'; |
313 | 313 | end | end |
314 | 314 | end | end |
315 | |||
315 | |||
316 | 316 | if ~isempty(ticks) | if ~isempty(ticks) |
317 | |||
317 | |||
318 | 318 | if ischar(textmat) % If format string, format colorbar ticks in the same way | if ischar(textmat) % If format string, format colorbar ticks in the same way |
319 | 319 | ticklabels = arrayfun(@(x){sprintf(textmat,x)},ticks); | ticklabels = arrayfun(@(x){sprintf(textmat,x)},ticks); |
320 | 320 | else | else |
... | ... | if ~isempty(ticks) | |
325 | 325 | else | else |
326 | 326 | set(c, [tickAxis 'TickLabel'], ticklabels); | set(c, [tickAxis 'TickLabel'], ticklabels); |
327 | 327 | end | end |
328 | |||
328 | |||
329 | 329 | end | end |
330 | 330 | ||
331 | 331 | ||
... | ... | else | |
360 | 360 | if ischar(ylab) | if ischar(ylab) |
361 | 361 | ylab = cellstr(ylab); | ylab = cellstr(ylab); |
362 | 362 | end | end |
363 | ytick = get(p.hAxes, 'YTick'); | ||
363 | ytick = get(p.hAxes, 'YTick'); | ||
364 | 364 | ytick(ytick<1|ytick>length(ylab)) = []; | ytick(ytick<1|ytick>length(ylab)) = []; |
365 | 365 | if p.ShowAllTicks || length(ytick) > length(ylab) | if p.ShowAllTicks || length(ytick) > length(ylab) |
366 | 366 | ytick = 1:length(ylab); | ytick = 1:length(ylab); |
... | ... | function hXText = createXTicks(hAxes, tickAngle, xticks, xticklabels, texInterpr | |
411 | 411 | ||
412 | 412 | axXLim = get(hAxes, 'XLim'); | axXLim = get(hAxes, 'XLim'); |
413 | 413 | [xPos, yPos] = calculateTextTickPositions(hAxes, axXLim, xticks); | [xPos, yPos] = calculateTextTickPositions(hAxes, axXLim, xticks); |
414 | |||
414 | |||
415 | 415 | if texInterpreter | if texInterpreter |
416 | 416 | interpreter = 'tex'; | interpreter = 'tex'; |
417 | 417 | else | else |
... | ... | function hXText = createXTicks(hAxes, tickAngle, xticks, xticklabels, texInterpr | |
421 | 421 | 'Parent', hAxes, 'FontSize', get(hAxes,'FontSize'), ... | 'Parent', hAxes, 'FontSize', get(hAxes,'FontSize'), ... |
422 | 422 | 'HorizontalAlignment', 'right', 'Rotation', tickAngle,... | 'HorizontalAlignment', 'right', 'Rotation', tickAngle,... |
423 | 423 | 'Interpreter', interpreter); | 'Interpreter', interpreter); |
424 | |||
424 | |||
425 | 425 | set(hAxes, 'XTick', xticks, 'XTickLabel', ''); | set(hAxes, 'XTick', xticks, 'XTickLabel', ''); |
426 | 426 | ||
427 | 427 | end | end |
... | ... | function adjustAxesToAccommodateTickLabels(hAxes, hXText) | |
449 | 449 | [axPosP, axPosN, axOPP, axOPN, coPosP, textPosP] = ... | [axPosP, axPosN, axOPP, axOPN, coPosP, textPosP] = ... |
450 | 450 | getGraphicsObjectsPositions(hAxes, hXText); %#ok<ASGLU> | getGraphicsObjectsPositions(hAxes, hXText); %#ok<ASGLU> |
451 | 451 | ||
452 | header = axOPP(4) + axOPP(2) - axPosP(4) - axPosP(2); % Distance between top of axes and container in pixels; | ||
452 | header = axOPP(4) + axOPP(2) - axPosP(4) - axPosP(2); % Distance between top of axes and container in pixels; | ||
453 | 453 | delta = 5; % To adjust for overlap between area designated for regular ticks and area occupied by rotated ticks | delta = 5; % To adjust for overlap between area designated for regular ticks and area occupied by rotated ticks |
454 | 454 | axHeightP = axOPP(4) - header - delta - textPosP(4); | axHeightP = axOPP(4) - header - delta - textPosP(4); |
455 | 455 | ||
456 | 456 | % Fudge axis position if labels are taking up too much room | % Fudge axis position if labels are taking up too much room |
457 | 457 | if textPosP(4)/(textPosP(4)+axHeightP) > .7 % It's taking up more than 70% of total height | if textPosP(4)/(textPosP(4)+axHeightP) > .7 % It's taking up more than 70% of total height |
458 | axHeightP = (1/.7-1) * textPosP(4); % Minimum axis | ||
458 | axHeightP = (1/.7-1) * textPosP(4); % Minimum axis | ||
459 | 459 | end | end |
460 | 460 | axHeightN = max(0.0001, axHeightP / coPosP(4)); | axHeightN = max(0.0001, axHeightP / coPosP(4)); |
461 | 461 | ||
... | ... | if axesLimitsChanged && ~isempty(axInfo.displayText) % If limits change & text l | |
527 | 527 | set(p.hText(ind), 'Visible', 'on'); | set(p.hText(ind), 'Visible', 'on'); |
528 | 528 | set(p.hText(~ind), 'Visible', 'off'); | set(p.hText(~ind), 'Visible', 'off'); |
529 | 529 | end | end |
530 | |||
530 | |||
531 | 531 | % Modify Y Tick Labels | % Modify Y Tick Labels |
532 | 532 | ||
533 | 533 | if ~isempty(axInfo.ylab) | if ~isempty(axInfo.ylab) |
... | ... | if ~isempty(axInfo.ylab) | |
544 | 544 | ylabels(1:length(axInfo.ylab)) = axInfo.ylab; | ylabels(1:length(axInfo.ylab)) = axInfo.ylab; |
545 | 545 | set(hAxes, 'YTick', yticks, 'YTickLabel', ylabels(yticks)); | set(hAxes, 'YTick', yticks, 'YTickLabel', ylabels(yticks)); |
546 | 546 | end | end |
547 | |||
548 | if ~isempty(axInfo.xlab) | ||
549 | |||
547 | |||
548 | if ~isempty(axInfo.xlab) | ||
549 | |||
550 | 550 | axXLim = get(hAxes, 'XLim'); | axXLim = get(hAxes, 'XLim'); |
551 | 551 | ||
552 | 552 | if p.ShowAllTicks | if p.ShowAllTicks |
... | ... | if ~isempty(axInfo.xlab) | |
559 | 559 | end | end |
560 | 560 | xlabels = repmat({''},1,max(xticks)); | xlabels = repmat({''},1,max(xticks)); |
561 | 561 | xlabels(1:length(axInfo.xlab)) = axInfo.xlab; | xlabels(1:length(axInfo.xlab)) = axInfo.xlab; |
562 | |||
562 | |||
563 | 563 | if ~isempty(axInfo.hXText) % Rotated X tick labels exist | if ~isempty(axInfo.hXText) % Rotated X tick labels exist |
564 | 564 | try delete(axInfo.hXText); end %#ok<TRYNC> | try delete(axInfo.hXText); end %#ok<TRYNC> |
565 | 565 | axInfo.hXText = createXTicks(hAxes, p.TickAngle, xticks, xlabels(xticks), p.TickTexInterpreter); | axInfo.hXText = createXTicks(hAxes, p.TickAngle, xticks, xlabels(xticks), p.TickTexInterpreter); |
... | ... | if ~isempty(axInfo.xlab) | |
567 | 567 | else | else |
568 | 568 | set(hAxes, 'XTick', xticks, 'XTickLabel', xlabels(xticks)); | set(hAxes, 'XTick', xticks, 'XTickLabel', xlabels(xticks)); |
569 | 569 | end | end |
570 | |||
570 | |||
571 | 571 | %adjustAxesToAccommodateTickLabels(hAxes, axInfo.hXText) | %adjustAxesToAccommodateTickLabels(hAxes, axInfo.hXText) |
572 | 572 | end | end |
573 | 573 | ||
... | ... | axInfo = getHeatmapAxesInfo(hAxes); | |
581 | 581 | pos = eventdata.Position; | pos = eventdata.Position; |
582 | 582 | ||
583 | 583 | if ~isempty(axInfo) | if ~isempty(axInfo) |
584 | |||
584 | |||
585 | 585 | try | try |
586 | 586 | val = axInfo.displayText{pos(2), pos(1)}; | val = axInfo.displayText{pos(2), pos(1)}; |
587 | 587 | catch %#ok<CTCH> | catch %#ok<CTCH> |
... | ... | if ~isempty(axInfo) | |
590 | 590 | if isempty(axInfo.xlab), i = int2str(pos(1)); else i = axInfo.xlab{pos(1)}; end | if isempty(axInfo.xlab), i = int2str(pos(1)); else i = axInfo.xlab{pos(1)}; end |
591 | 591 | if isempty(axInfo.ylab), j = int2str(pos(2)); else j = axInfo.ylab{pos(2)}; end | if isempty(axInfo.ylab), j = int2str(pos(2)); else j = axInfo.ylab{pos(2)}; end |
592 | 592 | output_txt = sprintf('X: %s\nY: %s\nVal: %s', i, j, val); | output_txt = sprintf('X: %s\nY: %s\nVal: %s', i, j, val); |
593 | |||
593 | |||
594 | 594 | else | else |
595 | 595 | if length(pos) == 2 | if length(pos) == 2 |
596 | 596 | output_txt = sprintf('X: %0.4g\nY: %0.4g', pos(1), pos(2)); | output_txt = sprintf('X: %0.4g\nY: %0.4g', pos(1), pos(2)); |
... | ... | end | |
604 | 604 | function resize(obj, evd) | function resize(obj, evd) |
605 | 605 | hAxes = findobj(obj, 'type', 'axes'); | hAxes = findobj(obj, 'type', 'axes'); |
606 | 606 | for i = 1:length(hAxes) | for i = 1:length(hAxes) |
607 | updateLabels(hAxes(i), false); | ||
607 | updateLabels(hAxes(i), false); | ||
608 | 608 | end | end |
609 | 609 | end | end |
610 | 610 | ||
... | ... | if isempty(textmat) | |
632 | 632 | factor = 0; | factor = 0; |
633 | 633 | return | return |
634 | 634 | end | end |
635 | |||
635 | |||
636 | 636 | if isscalar(textmat) && textmat % If true convert mat to text | if isscalar(textmat) && textmat % If true convert mat to text |
637 | 637 | displaytext = arrayfun(@(x){num2str(x)},mat); | displaytext = arrayfun(@(x){num2str(x)},mat); |
638 | 638 | elseif ischar(textmat) % If a format string, convert mat to text with specific format | elseif ischar(textmat) % If a format string, convert mat to text with specific format |
... | ... | function cmap = resamplecmap(cmap, clevels, xi) | |
754 | 754 | ||
755 | 755 | t = cmap; | t = cmap; |
756 | 756 | if nargin < 3 | if nargin < 3 |
757 | xi = linspace(1,clevels,size(t,1)); | ||
757 | xi = linspace(1,clevels,size(t,1)); | ||
758 | 758 | end | end |
759 | xi([1 end]) = [1 clevels]; % These need to be exact for the interpolation to | ||
759 | xi([1 end]) = [1 clevels]; % These need to be exact for the interpolation to | ||
760 | 760 | % work and we don't want machine precision messing it up | % work and we don't want machine precision messing it up |
761 | 761 | cmap = [interp1(xi, t(:,1), 1:clevels);... | cmap = [interp1(xi, t(:,1), 1:clevels);... |
762 | 762 | interp1(xi, t(:,2), 1:clevels);... | interp1(xi, t(:,2), 1:clevels);... |
... | ... | elseif zeroInd >= clevels, % Just red | |
779 | 779 | g = interp1([1 clevels], [0 1], 1:clevels); | g = interp1([1 clevels], [0 1], 1:clevels); |
780 | 780 | r = interp1([1 clevels], [1 1], 1:clevels); | r = interp1([1 clevels], [1 1], 1:clevels); |
781 | 781 | else | else |
782 | b = interp1([1 zeroInd clevels], [0 1 0], 1:clevels); | ||
782 | b = interp1([1 zeroInd clevels], [0 1 0], 1:clevels); | ||
783 | 783 | g = interp1([1 zeroInd clevels], [0 1 1], 1:clevels); | g = interp1([1 zeroInd clevels], [0 1 1], 1:clevels); |
784 | 784 | r = interp1([1 zeroInd clevels], [1 1 0], 1:clevels); | r = interp1([1 zeroInd clevels], [1 1 0], 1:clevels); |
785 | 785 | end | end |
... | ... | end | |
790 | 790 | % Generate Red-White color map | % Generate Red-White color map |
791 | 791 | function cmap = red(levels) | function cmap = red(levels) |
792 | 792 | r = ones(levels, 1); | r = ones(levels, 1); |
793 | g = linspace(1, 0, levels)'; | ||
793 | g = linspace(1, 0, levels)'; | ||
794 | 794 | cmap = [r g g]; | cmap = [r g g]; |
795 | 795 | end | end |
796 | 796 |
File misc/3rdparty/isalmost.m changed (mode: 100644) (index 4b20ba3..fb9af0f) | |||
... | ... | function test = isalmost(a,b,tol) | |
2 | 2 | % | % |
3 | 3 | % usage: test = isalmost(a,b,tol) | % usage: test = isalmost(a,b,tol) |
4 | 4 | % | % |
5 | % tests if matrix a is approximately equal to b within a specified | ||
5 | % tests if matrix a is approximately equal to b within a specified | ||
6 | 6 | % tolerance interval (b-tol <= a <= b+tol) | % tolerance interval (b-tol <= a <= b+tol) |
7 | 7 | % | % |
8 | 8 | % note: if b is given as a scalar, all values in a are compared against | % note: if b is given as a scalar, all values in a are compared against |
... | ... | function test = isalmost(a,b,tol) | |
23 | 23 | % test(i,j) = 0 -> a(i,j) is not equal to b(i,j) (or is NaN) | % test(i,j) = 0 -> a(i,j) is not equal to b(i,j) (or is NaN) |
24 | 24 | % test(i,j) = 1 -> a(i,j) is approximately equal to b(i,j) | % test(i,j) = 1 -> a(i,j) is approximately equal to b(i,j) |
25 | 25 | % | % |
26 | % author : James Crawford | ||
26 | % author : James Crawford | ||
27 | 27 | % created 01/08/2007 | % created 01/08/2007 |
28 | 28 | % | % |
29 | 29 | % history: v1.0 (01/08/2007) | % history: v1.0 (01/08/2007) |
File misc/3rdparty/kde2d.m changed (mode: 100644) (index 567ddc3..f700ea7) | |||
... | ... | p_02=func([0,2],t_star);p_20=func([2,0],t_star); p_11=func([1,1],t_star); | |
97 | 97 | t_y=(p_02^(3/4)/(4*pi*N*p_20^(3/4)*(p_11+sqrt(p_20*p_02))))^(1/3); | t_y=(p_02^(3/4)/(4*pi*N*p_20^(3/4)*(p_11+sqrt(p_20*p_02))))^(1/3); |
98 | 98 | t_x=(p_20^(3/4)/(4*pi*N*p_02^(3/4)*(p_11+sqrt(p_20*p_02))))^(1/3); | t_x=(p_20^(3/4)/(4*pi*N*p_02^(3/4)*(p_11+sqrt(p_20*p_02))))^(1/3); |
99 | 99 | % smooth the discrete cosine transform of initial data using t_star | % smooth the discrete cosine transform of initial data using t_star |
100 | a_t=exp(-(0:n-1)'.^2*pi^2*t_x/2)*exp(-(0:n-1).^2*pi^2*t_y/2).*a; | ||
100 | a_t=exp(-(0:n-1)'.^2*pi^2*t_x/2)*exp(-(0:n-1).^2*pi^2*t_y/2).*a; | ||
101 | 101 | % now apply the inverse discrete cosine transform | % now apply the inverse discrete cosine transform |
102 | 102 | if nargout>1 | if nargout>1 |
103 | 103 | density=idct2d(a_t)*(numel(a_t)/prod(scaling)); | density=idct2d(a_t)*(numel(a_t)/prod(scaling)); |
104 | density(density<0)=eps; % remove any negative density values | ||
104 | density(density<0)=eps; % remove any negative density values | ||
105 | 105 | [X,Y]=meshgrid(MIN_XY(1):scaling(1)/(n-1):MAX_XY(1),MIN_XY(2):scaling(2)/(n-1):MAX_XY(2)); | [X,Y]=meshgrid(MIN_XY(1):scaling(1)/(n-1):MAX_XY(1),MIN_XY(2):scaling(2)/(n-1):MAX_XY(2)); |
106 | 106 | end | end |
107 | bandwidth=sqrt([t_x,t_y]).*scaling; | ||
107 | bandwidth=sqrt([t_x,t_y]).*scaling; | ||
108 | 108 | end | end |
109 | 109 | %####################################### | %####################################### |
110 | 110 | function [out,time]=evolve(t) | function [out,time]=evolve(t) |
... | ... | while flag==0 | |
210 | 210 | end | end |
211 | 211 | end | end |
212 | 212 | end | end |
213 | |||
214 | |||
215 | |||
216 | |||
217 | |||
218 | |||
219 | |||
220 | |||
221 | |||
222 | |||
223 | |||
224 | |||
225 | |||
226 | |||
227 | |||
228 | |||
229 | |||
230 | |||
231 |
File misc/3rdparty/ndhist.m changed (mode: 100644) (index 32e2658..b9af632) | |||
1 | 1 | % Add logx,logy,loglog | % Add logx,logy,loglog |
2 | % | ||
2 | % | ||
3 | 3 | ||
4 | 4 | % Displays a 2d histogram for your data, it will set the bins appropriately | % Displays a 2d histogram for your data, it will set the bins appropriately |
5 | % | ||
5 | % | ||
6 | 6 | % NDHIST(x,y); where x and y are equal length vectors. It will choose | % NDHIST(x,y); where x and y are equal length vectors. It will choose |
7 | 7 | % reasonable axis bounds and bins to present your data. The | % reasonable axis bounds and bins to present your data. The |
8 | 8 | % default parameters may leave some data off the chart. | % default parameters may leave some data off the chart. |
9 | % | ||
9 | % | ||
10 | 10 | % NDHIST(XY); where XY = [x y] and x,y are vectors | % NDHIST(XY); where XY = [x y] and x,y are vectors |
11 | % | ||
11 | % | ||
12 | 12 | % NDHIST(z); where z is a vector of complex numbers, (x+1i*y) or amplitude*exp(1i*theta) | % NDHIST(z); where z is a vector of complex numbers, (x+1i*y) or amplitude*exp(1i*theta) |
13 | % | ||
13 | % | ||
14 | 14 | % NDHIST(y); where y is a vector of real numbers will plot a 2d histogram | % NDHIST(y); where y is a vector of real numbers will plot a 2d histogram |
15 | 15 | % of the points, as if it were a line-chart. It is equivalent | % of the points, as if it were a line-chart. It is equivalent |
16 | 16 | % to calling ndhist(1:length(y),y); | % to calling ndhist(1:length(y),y); |
17 | % | ||
17 | % | ||
18 | 18 | % N = NDHIST(x,y); returns a matrix N containing the counts for each bin | % N = NDHIST(x,y); returns a matrix N containing the counts for each bin |
19 | 19 | % determined by the histogram. | % determined by the histogram. |
20 | % | ||
20 | % | ||
21 | 21 | % [edgesX2,edgesY2,N,h] = NDHIST(x,y); which returns a matrix N containing | % [edgesX2,edgesY2,N,h] = NDHIST(x,y); which returns a matrix N containing |
22 | 22 | % the counts for each bin determined by the histogram. You can | % the counts for each bin determined by the histogram. You can |
23 | 23 | % plot it with sanePColor(edgesX2,edgesY2,N); (from Matlabcentral) | % plot it with sanePColor(edgesX2,edgesY2,N); (from Matlabcentral) |
24 | 24 | % h is the plot handle. | % h is the plot handle. |
25 | % | ||
25 | % | ||
26 | 26 | % NDHIST(...,'param','value','param','value', ... ); Run ndhist with specific | % NDHIST(...,'param','value','param','value', ... ); Run ndhist with specific |
27 | 27 | % parameters | % parameters |
28 | % | ||
29 | % List of special parameters: | ||
30 | % | ||
28 | % | ||
29 | % List of special parameters: | ||
30 | % | ||
31 | 31 | % 'filter' : This will apply a gaussian filter to the final histogram data. | % 'filter' : This will apply a gaussian filter to the final histogram data. |
32 | 32 | % The default filter width is 5 bins wide. If you pass a number | % The default filter width is 5 bins wide. If you pass a number |
33 | 33 | % then that will be used. Even numbered filter parameters will be | % then that will be used. Even numbered filter parameters will be |
34 | 34 | % changed to odd numbers to keep the filter perfectly symetrical. | % changed to odd numbers to keep the filter perfectly symetrical. |
35 | 35 | % 'filt','filtering','smooth' | % 'filt','filtering','smooth' |
36 | % | ||
36 | % | ||
37 | 37 | % 'log' : Change the colormap to be on a log scale to represent data | % 'log' : Change the colormap to be on a log scale to represent data |
38 | % over a large dynamic range. | ||
38 | % over a large dynamic range. | ||
39 | 39 | % 'logplot' | % 'logplot' |
40 | % | ||
40 | % | ||
41 | 41 | % 'bins' : Change the size of the bins. For example '2' will create a | % 'bins' : Change the size of the bins. For example '2' will create a |
42 | 42 | % plot with twice the default number of bins; 0.5 will have half | % plot with twice the default number of bins; 0.5 will have half |
43 | 43 | % the default number of bins. The default uses Scott's normal | % the default number of bins. The default uses Scott's normal |
46 | 46 | % subfunction hist3. Feel free to implement it as an additional | % subfunction hist3. Feel free to implement it as an additional |
47 | 47 | % parameter 'edgdes','edgesx' or 'edgesy' | % parameter 'edgdes','edgesx' or 'edgesy' |
48 | 48 | % 'f','numbins' | % 'f','numbins' |
49 | % | ||
49 | % | ||
50 | 50 | % 'binsx' : Change the size of only the x bins. 'fx' | % 'binsx' : Change the size of only the x bins. 'fx' |
51 | 51 | % 'binsy' : Change the size of only the y bins. 'fy' | % 'binsy' : Change the size of only the y bins. 'fy' |
52 | % | ||
52 | % | ||
53 | 53 | % axis : This is to set the range of the plot, [xmin xmax ymin ymax] | % axis : This is to set the range of the plot, [xmin xmax ymin ymax] |
54 | 54 | % The default range is set to 3*std(x) and 3*std(y) where the | % The default range is set to 3*std(x) and 3*std(y) where the |
55 | 55 | % parameter stdTimes=3 is hard-coded in this version and | % parameter stdTimes=3 is hard-coded in this version and |
56 | 56 | % potentially added as a parameter in a later version. | % potentially added as a parameter in a later version. |
57 | % | ||
57 | % | ||
58 | 58 | % max : This is to set the range of the plot to be such that every | % max : This is to set the range of the plot to be such that every |
59 | 59 | % point will be contained within the plot. | % point will be contained within the plot. |
60 | 60 | % 'themax' | % 'themax' |
61 | % | ||
61 | % | ||
62 | 62 | % intbins : Set the bins to be intiger widths. For both x and y | % intbins : Set the bins to be intiger widths. For both x and y |
63 | 63 | % 'int' | % 'int' |
64 | % | ||
64 | % | ||
65 | 65 | % intbinsx : Set the x bins to be intiger widths. 'intx' | % intbinsx : Set the x bins to be intiger widths. 'intx' |
66 | 66 | % intbinsy : Set the y bins to be intiger widths. 'inty' | % intbinsy : Set the y bins to be intiger widths. 'inty' |
67 | % | ||
67 | % | ||
68 | 68 | %normalizex: Normalize the plot so that the sum of all the y values in each | %normalizex: Normalize the plot so that the sum of all the y values in each |
69 | 69 | % x bin sum to one. | % x bin sum to one. |
70 | % 'normx','nx' | ||
71 | % | ||
70 | % 'normx','nx' | ||
71 | % | ||
72 | 72 | %normalizey: Normalize the plot so that the sum of all the x values in each | %normalizey: Normalize the plot so that the sum of all the x values in each |
73 | 73 | % y bin sum to one. | % y bin sum to one. |
74 | 74 | % 'normy','ny' | % 'normy','ny' |
75 | % | ||
75 | % | ||
76 | 76 | %normalizeR: Normalize the plot so that the you can clearly see how the | %normalizeR: Normalize the plot so that the you can clearly see how the |
77 | 77 | % distribution vary's over angle. It weights points in the outer | % distribution vary's over angle. It weights points in the outer |
78 | 78 | % radius by the diameter at that radius. | % radius by the diameter at that radius. |
79 | 79 | % 'nr' | % 'nr' |
80 | 80 | % points: Plot the points on top of the colored histogram. | % points: Plot the points on top of the colored histogram. |
81 | % | ||
81 | % | ||
82 | 82 | % 3D: Use a 3D column graph instead of a colored heatmap | % 3D: Use a 3D column graph instead of a colored heatmap |
83 | 83 | % 'threeD','3d','columns' | % 'threeD','3d','columns' |
84 | % | ||
84 | % | ||
85 | 85 | % PARTIALLY IMPLEMENTED | % PARTIALLY IMPLEMENTED |
86 | 86 | % radial : Set the axis to be equal and add a polar grid 'r' | % radial : Set the axis to be equal and add a polar grid 'r' |
87 | % | ||
87 | % | ||
88 | 88 | % NOT IMPLEMENTED YET | % NOT IMPLEMENTED YET |
89 | 89 | %'samebins': NOT IMPLEMENTED YET. Would set the width of the x and y bins | %'samebins': NOT IMPLEMENTED YET. Would set the width of the x and y bins |
90 | 90 | % to be equal to each other and the axis equal too. | % to be equal to each other and the axis equal too. |
91 | 91 | ||
92 | % | ||
92 | % | ||
93 | 93 | % user parameters: | % user parameters: |
94 | 94 | % filter: This will filter the data, you may choose to follow it with a | % filter: This will filter the data, you may choose to follow it with a |
95 | 95 | % number. This number will represent the radius of the circular | % number. This number will represent the radius of the circular |
96 | 96 | % gaussian filter. Other ways to call it: 'filt','filtering','f' | % gaussian filter. Other ways to call it: 'filt','filtering','f' |
97 | % | ||
98 | % | ||
97 | % | ||
98 | % | ||
99 | 99 | % examples | % examples |
100 | % | ||
100 | % | ||
101 | 101 | % To test the function you may use this example: | % To test the function you may use this example: |
102 | 102 | % z=2*randn(1,100000)+1i*(randn(1,100000)); | % z=2*randn(1,100000)+1i*(randn(1,100000)); |
103 | % | ||
103 | % | ||
104 | 104 | % If you have amplitude and angle measures then pass this: | % If you have amplitude and angle measures then pass this: |
105 | 105 | % z = amp*exp(1i*ang); | % z = amp*exp(1i*ang); |
106 | % | ||
106 | % | ||
107 | 107 | % NDHIST(z) | % NDHIST(z) |
108 | 108 | % NDHIST(z,'lansey') | % NDHIST(z,'lansey') |
109 | 109 | % NDHIST(z,'filter') | % NDHIST(z,'filter') |
110 | % | ||
110 | % | ||
111 | 111 | % % Note | % % Note |
112 | 112 | % The name of this function comes because really its a 2d hist, but since I | % The name of this function comes because really its a 2d hist, but since I |
113 | 113 | % already have an 'nhist' I thought I might name it this. | % already have an 'nhist' I thought I might name it this. |
114 | % | ||
114 | % | ||
115 | 115 | % SEE ALSO: HIST, HIST3 | % SEE ALSO: HIST, HIST3 |
116 | 116 | %% | %% |
117 | 117 | function [edgesX2,edgesY2,N,h] = ndhist(z,varargin) | function [edgesX2,edgesY2,N,h] = ndhist(z,varargin) |
... | ... | end | |
134 | 134 | if isreal(z) | if isreal(z) |
135 | 135 | if size(z,2)==2 % we have a [x y] case | if size(z,2)==2 % we have a [x y] case |
136 | 136 | [edgesX2,edgesY2,N] = ndhist(z(:,1)+1i*z(:,2),varargin{:}); | [edgesX2,edgesY2,N] = ndhist(z(:,1)+1i*z(:,2),varargin{:}); |
137 | else % we've got either | ||
137 | else % we've got either | ||
138 | 138 | if isempty(varargin) % just one value passed | if isempty(varargin) % just one value passed |
139 | 139 | display('your data are all ''real'' so we intepreted it as a timeseries'); | display('your data are all ''real'' so we intepreted it as a timeseries'); |
140 | 140 | idx = (1:length(z))'; | idx = (1:length(z))'; |
... | ... | if isreal(z) | |
161 | 161 | if nargout==2 | if nargout==2 |
162 | 162 | warning('you are being passed out ''edgesX2,edgesY2'' is that really what you want from this function?'); | warning('you are being passed out ''edgesX2,edgesY2'' is that really what you want from this function?'); |
163 | 163 | end | end |
164 | |||
164 | |||
165 | 165 | return; | return; |
166 | 166 | end | end |
167 | 167 | % great we can continue | % great we can continue |
... | ... | while k <= nargin-1 | |
272 | 272 | case {'bins','numbins','f'} % 'f' comes from the binfactor of nhist | case {'bins','numbins','f'} % 'f' comes from the binfactor of nhist |
273 | 273 | binFactorY=varargin{k+1}; | binFactorY=varargin{k+1}; |
274 | 274 | binFactorX=varargin{k+1}; | binFactorX=varargin{k+1}; |
275 | k = k + 1; | ||
275 | k = k + 1; | ||
276 | 276 | case {'binsx','fx'} % 'f' comes from the binfactor of nhist | case {'binsx','fx'} % 'f' comes from the binfactor of nhist |
277 | 277 | binFactorX=varargin{k+1}; | binFactorX=varargin{k+1}; |
278 | k = k + 1; | ||
278 | k = k + 1; | ||
279 | 279 | case {'binsy','fy'} % 'f' comes from the binfactor of nhist | case {'binsy','fy'} % 'f' comes from the binfactor of nhist |
280 | 280 | binFactorY=varargin{k+1}; | binFactorY=varargin{k+1}; |
281 | k = k + 1; | ||
281 | k = k + 1; | ||
282 | 282 | case {'intbins','int'} % 'f' comes from the binfactor of nhist | case {'intbins','int'} % 'f' comes from the binfactor of nhist |
283 | 283 | intbinsFlagX = 1; | intbinsFlagX = 1; |
284 | 284 | intbinsFlagY = 1; | intbinsFlagY = 1; |
... | ... | while k <= nargin-1 | |
309 | 309 | end | end |
310 | 310 | end | end |
311 | 311 | case {'lansey','normalizer','nr'} % this guy weights the values based on radius | case {'lansey','normalizer','nr'} % this guy weights the values based on radius |
312 | userParam=1; | ||
312 | userParam=1; | ||
313 | 313 | case {'log','logplot'} | case {'log','logplot'} |
314 | 314 | logColorFlag = 1; | logColorFlag = 1; |
315 | 315 | case {'normalizex','normx','nx'} | case {'normalizex','normx','nx'} |
... | ... | while k <= nargin-1 | |
329 | 329 | error('stdTimes must be a number') | error('stdTimes must be a number') |
330 | 330 | end | end |
331 | 331 | ||
332 | otherwise | ||
332 | otherwise | ||
333 | 333 | warning(['you have passed a strange parameter: ''' varargin{k} ''' please roll again']); | warning(['you have passed a strange parameter: ''' varargin{k} ''' please roll again']); |
334 | 334 | end | end |
335 | 335 | else | else |
... | ... | if normalizeFlagX && normalizeFlagY | |
343 | 343 | warning('Only normalize X was used'); | warning('Only normalize X was used'); |
344 | 344 | normalizeFlagY = 0; | normalizeFlagY = 0; |
345 | 345 | end | end |
346 | |||
346 | |||
347 | 347 | ||
348 | 348 | %% set the bin widths | %% set the bin widths |
349 | 349 | % Using Scott's normal reference rule, unclear if it is ideal for 2D histograms ... | % Using Scott's normal reference rule, unclear if it is ideal for 2D histograms ... |
... | ... | if intbinsFlagX | |
379 | 379 | axisXY(1)=round(axisXY(1))-.5; % subtract 1/2 to make the bin peaks appear on the numbers. | axisXY(1)=round(axisXY(1))-.5; % subtract 1/2 to make the bin peaks appear on the numbers. |
380 | 380 | axisXY(2)=round(axisXY(2))+.5; | axisXY(2)=round(axisXY(2))+.5; |
381 | 381 | binWidthX=max(round(binWidthX),1); | binWidthX=max(round(binWidthX),1); |
382 | |||
382 | |||
383 | 383 | % numBinsX = rangeX/binWidthX; % Approx number of bins | % numBinsX = rangeX/binWidthX; % Approx number of bins |
384 | |||
385 | |||
384 | |||
385 | |||
386 | 386 | end | end |
387 | 387 | if intbinsFlagY | if intbinsFlagY |
388 | 388 | axisXY(3)=round(axisXY(3))-.5; % subtract 1/2 to make the bin peaks appear on the numbers. | axisXY(3)=round(axisXY(3))-.5; % subtract 1/2 to make the bin peaks appear on the numbers. |
389 | 389 | axisXY(4)=round(axisXY(4))+.5; | axisXY(4)=round(axisXY(4))+.5; |
390 | 390 | binWidthY=max(round(binWidthY),1); | binWidthY=max(round(binWidthY),1); |
391 | |||
391 | |||
392 | 392 | % numBinsY = rangeY/binWidthY; % Approx number of bins | % numBinsY = rangeY/binWidthY; % Approx number of bins |
393 | 393 | ||
394 | 394 | ||
395 | |||
395 | |||
396 | 396 | end | end |
397 | 397 | ||
398 | 398 | % finally set the bins | % finally set the bins |
... | ... | N = hist3(x,y,edgesX,edgesY); | |
409 | 409 | if filtering | if filtering |
410 | 410 | N2 = smooth2(N,filtering); | N2 = smooth2(N,filtering); |
411 | 411 | N = N2; | N = N2; |
412 | |||
412 | |||
413 | 413 | % % if you have the image processing toolbox then you could use this: | % % if you have the image processing toolbox then you could use this: |
414 | 414 | % H = fspecial('disk',filtering); | % H = fspecial('disk',filtering); |
415 | 415 | % filtN = imfilter(N,H,'replicate'); | % filtN = imfilter(N,H,'replicate'); |
... | ... | end | |
497 | 497 | ||
498 | 498 | % if ~hold_state, hold off; end; | % if ~hold_state, hold off; end; |
499 | 499 | ||
500 | end % ndhist function over | ||
500 | end % ndhist function over | ||
501 | 501 | ||
502 | 502 | ||
503 | 503 | %% | %% |
... | ... | minError=eps*100; % the minimum average difference from integers they can be. | |
545 | 545 | L=0; % double until proven integer | L=0; % double until proven integer |
546 | 546 | if ~isempty(varargin) | if ~isempty(varargin) |
547 | 547 | minError=varargin{1}; | minError=varargin{1}; |
548 | end | ||
548 | end | ||
549 | 549 | if isinteger(x)||islogical(x) % your done, duh, its an int. | if isinteger(x)||islogical(x) % your done, duh, its an int. |
550 | 550 | L=1; | L=1; |
551 | return; | ||
551 | return; | ||
552 | 552 | else | else |
553 | 553 | if sum(abs(x-round(x)))/length(x)<minError | if sum(abs(x-round(x)))/length(x)<minError |
554 | 554 | L=1; | L=1; |
... | ... | end | |
562 | 562 | ||
563 | 563 | %% | %% |
564 | 564 | % This version is for plotting a certain figure. | % This version is for plotting a certain figure. |
565 | % | ||
565 | % | ||
566 | 566 | % myPolar: Polar coordinate plot, draws a polar grid onto the axis | % myPolar: Polar coordinate plot, draws a polar grid onto the axis |
567 | % | ||
567 | % | ||
568 | 568 | % myPolar(); % just adds the grid to the axis | % myPolar(); % just adds the grid to the axis |
569 | 569 | % myPolar(theta,rho) % makes a plot using polar coordinates of | % myPolar(theta,rho) % makes a plot using polar coordinates of |
570 | 570 | % the angle THETA, in radians, versus the radius RHO | % the angle THETA, in radians, versus the radius RHO |
... | ... | end | |
572 | 572 | % myPolar(THETA,RHO,S) uses the linestyle specified in string, like 'z' | % myPolar(THETA,RHO,S) uses the linestyle specified in string, like 'z' |
573 | 573 | % myPolar(THETA,RHO,'linespec','parameter',...) uses the linestyle | % myPolar(THETA,RHO,'linespec','parameter',...) uses the linestyle |
574 | 574 | % specified by the linspec functions of plot | % specified by the linspec functions of plot |
575 | % | ||
576 | % | ||
575 | % | ||
576 | % | ||
577 | 577 | % Here are the specific list of improvements from Matlab's function: | % Here are the specific list of improvements from Matlab's function: |
578 | 578 | % The ability to add a polar grid to any other plot you make | % The ability to add a polar grid to any other plot you make |
579 | 579 | % the ability to use all linspec parameters, like 'linewidth' and 'color' | % the ability to use all linspec parameters, like 'linewidth' and 'color' |
... | ... | end | |
581 | 581 | % The plot is still square, it does not gray out anything. | % The plot is still square, it does not gray out anything. |
582 | 582 | % Grid axis ticks go to two decimal places | % Grid axis ticks go to two decimal places |
583 | 583 | % | % |
584 | % | ||
584 | % | ||
585 | 585 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
586 | 586 | % Jonathan Lansey May 2009, questions to Lansey at gmail.com % | % Jonathan Lansey May 2009, questions to Lansey at gmail.com % |
587 | 587 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
... | ... | hold_state = ishold; | |
592 | 592 | ||
593 | 593 | nCircles=3; | nCircles=3; |
594 | 594 | nDegrees=30; | nDegrees=30; |
595 | |||
595 | |||
596 | 596 | if nargin==0 % plot the grid now! | if nargin==0 % plot the grid now! |
597 | 597 | ||
598 | 598 | addPolarGrid(nCircles,nDegrees); | addPolarGrid(nCircles,nDegrees); |
599 | 599 | addPolarText(nCircles,nDegrees); | addPolarText(nCircles,nDegrees); |
600 | |||
600 | |||
601 | 601 | else | else |
602 | 602 | if ~isreal(varargin{1})% if its complex | if ~isreal(varargin{1})% if its complex |
603 | 603 | % we just get x and y from the complex data | % we just get x and y from the complex data |
... | ... | end % myPolar over | |
707 | 707 | % This function creates an Nx3 array of N [R B G] colors | % This function creates an Nx3 array of N [R B G] colors |
708 | 708 | % These can be used to plot lots of lines with distinguishable and nice | % These can be used to plot lots of lines with distinguishable and nice |
709 | 709 | % looking colors. | % looking colors. |
710 | % | ||
710 | % | ||
711 | 711 | % lineStyles = linspecer(N); makes N colors for you to use: lineStyles(ii,:) | % lineStyles = linspecer(N); makes N colors for you to use: lineStyles(ii,:) |
712 | % | ||
713 | % colormap(linspecer); set your colormap to have easily distinguishable | ||
712 | % | ||
713 | % colormap(linspecer); set your colormap to have easily distinguishable | ||
714 | 714 | % colors and a pleasing aesthetic | % colors and a pleasing aesthetic |
715 | % | ||
715 | % | ||
716 | 716 | % lineStyles = linspecer(N,'qualitative'); forces the colors to all be distinguishable (up to 12) | % lineStyles = linspecer(N,'qualitative'); forces the colors to all be distinguishable (up to 12) |
717 | % lineStyles = linspecer(N,'sequential'); forces the colors to vary along a spectrum | ||
718 | % | ||
717 | % lineStyles = linspecer(N,'sequential'); forces the colors to vary along a spectrum | ||
718 | % | ||
719 | 719 | % % Examples demonstrating the colors. | % % Examples demonstrating the colors. |
720 | % | ||
720 | % | ||
721 | 721 | % LINE COLORS | % LINE COLORS |
722 | 722 | % N=6; | % N=6; |
723 | % X = linspace(0,pi*3,1000); | ||
724 | % Y = bsxfun(@(x,n)sin(x+2*n*pi/N), X.', 1:N); | ||
723 | % X = linspace(0,pi*3,1000); | ||
724 | % Y = bsxfun(@(x,n)sin(x+2*n*pi/N), X.', 1:N); | ||
725 | 725 | % C = linspecer(N); | % C = linspecer(N); |
726 | 726 | % axes('NextPlot','replacechildren', 'ColorOrder',C); | % axes('NextPlot','replacechildren', 'ColorOrder',C); |
727 | 727 | % plot(X,Y,'linewidth',5) | % plot(X,Y,'linewidth',5) |
728 | 728 | % ylim([-1.1 1.1]); | % ylim([-1.1 1.1]); |
729 | % | ||
729 | % | ||
730 | 730 | % SIMPLER LINE COLOR EXAMPLE | % SIMPLER LINE COLOR EXAMPLE |
731 | 731 | % N = 6; X = linspace(0,pi*3,1000); | % N = 6; X = linspace(0,pi*3,1000); |
732 | 732 | % C = linspecer(N) | % C = linspecer(N) |
... | ... | end % myPolar over | |
736 | 736 | % plot(X,Y,'color',C(ii,:),'linewidth',3); | % plot(X,Y,'color',C(ii,:),'linewidth',3); |
737 | 737 | % hold on; | % hold on; |
738 | 738 | % end | % end |
739 | % | ||
739 | % | ||
740 | 740 | % COLORMAP EXAMPLE | % COLORMAP EXAMPLE |
741 | 741 | % A = rand(15); | % A = rand(15); |
742 | 742 | % figure; imagesc(A); % default colormap | % figure; imagesc(A); % default colormap |
743 | 743 | % figure; imagesc(A); colormap(linspecer); % linspecer colormap | % figure; imagesc(A); colormap(linspecer); % linspecer colormap |
744 | % | ||
744 | % | ||
745 | 745 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
746 | 746 | % by Jonathan Lansey, March 2009-2013 � Lansey at gmail.com % | % by Jonathan Lansey, March 2009-2013 � Lansey at gmail.com % |
747 | 747 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
748 | % | ||
748 | % | ||
749 | 749 | %% credits and where the function came from | %% credits and where the function came from |
750 | 750 | % The colors are largely taken from: | % The colors are largely taken from: |
751 | 751 | % http://colorbrewer2.org and Cynthia Brewer, Mark Harrower and The Pennsylvania State University | % http://colorbrewer2.org and Cynthia Brewer, Mark Harrower and The Pennsylvania State University |
752 | % | ||
753 | % | ||
752 | % | ||
753 | % | ||
754 | 754 | % She studied this from a phsychometric perspective and crafted the colors | % She studied this from a phsychometric perspective and crafted the colors |
755 | 755 | % beautifully. | % beautifully. |
756 | % | ||
756 | % | ||
757 | 757 | % I made choices from the many there to decide the nicest once for plotting | % I made choices from the many there to decide the nicest once for plotting |
758 | 758 | % lines in Matlab. I also made a small change to one of the colors I | % lines in Matlab. I also made a small change to one of the colors I |
759 | 759 | % thought was a bit too bright. In addition some interpolation is going on | % thought was a bit too bright. In addition some interpolation is going on |
760 | 760 | % for the sequential line styles. | % for the sequential line styles. |
761 | % | ||
762 | % | ||
761 | % | ||
762 | % | ||
763 | 763 | %% | %% |
764 | 764 | ||
765 | 765 | function lineStyles=linspecer(N,varargin) | function lineStyles=linspecer(N,varargin) |
... | ... | if ~isempty(varargin)>0 % you set a parameter? | |
809 | 809 | otherwise | otherwise |
810 | 810 | warning(['parameter ''' varargin{1} ''' not recognized']); | warning(['parameter ''' varargin{1} ''' not recognized']); |
811 | 811 | end | end |
812 | end | ||
813 | |||
812 | end | ||
813 | |||
814 | 814 | % predefine some colormaps | % predefine some colormaps |
815 | 815 | set3 = colorBrew2mat({[141, 211, 199];[ 255, 237, 111];[ 190, 186, 218];[ 251, 128, 114];[ 128, 177, 211];[ 253, 180, 98];[ 179, 222, 105];[ 188, 128, 189];[ 217, 217, 217];[ 204, 235, 197];[ 252, 205, 229];[ 255, 255, 179]}'); | set3 = colorBrew2mat({[141, 211, 199];[ 255, 237, 111];[ 190, 186, 218];[ 251, 128, 114];[ 128, 177, 211];[ 253, 180, 98];[ 179, 222, 105];[ 188, 128, 189];[ 217, 217, 217];[ 204, 235, 197];[ 252, 205, 229];[ 255, 255, 179]}'); |
816 | 816 | set1JL = brighten(colorBrew2mat({[228, 26, 28];[ 55, 126, 184];[ 77, 175, 74];[ 255, 127, 0];[ 255, 237, 111]*.95;[ 166, 86, 40];[ 247, 129, 191];[ 153, 153, 153];[ 152, 78, 163]}')); | set1JL = brighten(colorBrew2mat({[228, 26, 28];[ 55, 126, 184];[ 77, 175, 74];[ 255, 127, 0];[ 255, 237, 111]*.95;[ 166, 86, 40];[ 247, 129, 191];[ 153, 153, 153];[ 152, 78, 163]}')); |
... | ... | end | |
841 | 841 | function varIn = colorBrew2mat(varIn) | function varIn = colorBrew2mat(varIn) |
842 | 842 | for ii=1:length(varIn) % just divide by 255 | for ii=1:length(varIn) % just divide by 255 |
843 | 843 | varIn{ii}=varIn{ii}/255; | varIn{ii}=varIn{ii}/255; |
844 | end | ||
844 | end | ||
845 | 845 | end | end |
846 | 846 | ||
847 | 847 | function varIn = brighten(varIn,varargin) % increase the brightness | function varIn = brighten(varIn,varargin) % increase the brightness |
848 | 848 | ||
849 | 849 | if isempty(varargin), | if isempty(varargin), |
850 | frac = .9; | ||
850 | frac = .9; | ||
851 | 851 | else | else |
852 | frac = varargin{1}; | ||
852 | frac = varargin{1}; | ||
853 | 853 | end | end |
854 | 854 | ||
855 | 855 | for ii=1:length(varIn) | for ii=1:length(varIn) |
856 | 856 | varIn{ii}=varIn{ii}*frac+(1-frac); | varIn{ii}=varIn{ii}*frac+(1-frac); |
857 | end | ||
857 | end | ||
858 | 858 | end | end |
859 | 859 | ||
860 | 860 | function varIn = dim(varIn,f) | function varIn = dim(varIn,f) |
... | ... | end | |
947 | 947 | ||
948 | 948 | % This is a fast smooth function that will return a smoothed | % This is a fast smooth function that will return a smoothed |
949 | 949 | % version of the original that you pass it. | % version of the original that you pass it. |
950 | % | ||
950 | % | ||
951 | 951 | % Hey now the default is actually going to be a gaussian filter not a | % Hey now the default is actually going to be a gaussian filter not a |
952 | 952 | % moving average filter | % moving average filter |
953 | % | ||
953 | % | ||
954 | 954 | % It will be the same length as the original, and it will be centered on | % It will be the same length as the original, and it will be centered on |
955 | 955 | % the original function. To padd the edges it extends the average of the | % the original function. To padd the edges it extends the average of the |
956 | 956 | % last 'n' values on the end out further. | % last 'n' values on the end out further. |
957 | % | ||
957 | % | ||
958 | 958 | % Note that it uses a convolution which uses the | % Note that it uses a convolution which uses the |
959 | 959 | % cool fft trick to do it effeciently. | % cool fft trick to do it effeciently. |
960 | %% set things up if you want to test it as a script | ||
960 | %% set things up if you want to test it as a script | ||
961 | 961 | % N=301; | % N=301; |
962 | 962 | % % y = rand(N,1); | % % y = rand(N,1); |
963 | 963 | % y=-1./[1:N]; | % y=-1./[1:N]; |
... | ... | if length(n)==1 | |
978 | 978 | yout = A; | yout = A; |
979 | 979 | return; | return; |
980 | 980 | end | end |
981 | |||
981 | |||
982 | 982 | % forcing you to have an odd 'n' | % forcing you to have an odd 'n' |
983 | 983 | if double(~logical(round(n/2)-n/2)); | if double(~logical(round(n/2)-n/2)); |
984 | 984 | n = n+1; | n = n+1; |
985 | 985 | end | end |
986 | |||
986 | |||
987 | 987 | bee = linspace(-1.96,1.96,n); % normal distribution with 95% confidence bounds | bee = linspace(-1.96,1.96,n); % normal distribution with 95% confidence bounds |
988 | 988 | [BX, BY] = meshgrid(bee); | [BX, BY] = meshgrid(bee); |
989 | 989 | R2 = BX.^2+BY.^2; | R2 = BX.^2+BY.^2; |
990 | 990 | toConvolve = exp(-R2)/sum(exp(-R2(:))); | toConvolve = exp(-R2)/sum(exp(-R2(:))); |
991 | |||
991 | |||
992 | 992 | % toConvolve = exp(-bee.^2)/sum(exp(-bee.^2)); | % toConvolve = exp(-bee.^2)/sum(exp(-bee.^2)); |
993 | % old moving average computation: | ||
993 | % old moving average computation: | ||
994 | 994 | % toConvolve = ones(n,1)/n; | % toConvolve = ones(n,1)/n; |
995 | 995 | else | else |
996 | 996 | toConvolve = n; | toConvolve = n; |
... | ... | A = [padTop; A; padBot]; | |
1024 | 1024 | ||
1025 | 1025 | % the main event | % the main event |
1026 | 1026 | As=conv2(A,toConvolve); | As=conv2(A,toConvolve); |
1027 | % % % % % % % % % % % % % | ||
1027 | % % % % % % % % % % % % % | ||
1028 | 1028 | % clf; | % clf; |
1029 | 1029 | ||
1030 | 1030 | % sanePColor(As); | % sanePColor(As); |
... | ... | Y = [0 Y 100]; | |
1053 | 1053 | yi = interp1(Y,x,p); | yi = interp1(Y,x,p); |
1054 | 1054 | ||
1055 | 1055 | end | end |
1056 | |||
1057 | |||
1058 | |||
1059 | |||
1060 | |||
1061 | |||
1062 | |||
1063 | |||
1064 | |||
1065 |
File misc/3rdparty/ntitle.m changed (mode: 100644) (index 8e198b6..e4d1493) | |||
1 | 1 | function [ h ] = ntitle(titlestring,varargin) | function [ h ] = ntitle(titlestring,varargin) |
2 | 2 | % ntitle(titlestring,varargin) places a title within the plot instead of on | % ntitle(titlestring,varargin) places a title within the plot instead of on |
3 | 3 | % top. In the spirit of Edward Tufte, this is intended to keep the title | % top. In the spirit of Edward Tufte, this is intended to keep the title |
4 | % close to the data it describes and minimize wasted space. The ntitle function | ||
5 | % may prove particularly useful for figures with several subplots, where titles | ||
6 | % can sometimes become confused with xlabels above them. | ||
7 | % | ||
4 | % close to the data it describes and minimize wasted space. The ntitle function | ||
5 | % may prove particularly useful for figures with several subplots, where titles | ||
6 | % can sometimes become confused with xlabels above them. | ||
7 | % | ||
8 | 8 | % By default, ntitle centers the title at the top of the plot, but any of | % By default, ntitle centers the title at the top of the plot, but any of |
9 | 9 | % the location coordinates (e.g., north, southwest, etc.) can be used with | % the location coordinates (e.g., north, southwest, etc.) can be used with |
10 | % the argument 'location'. Output h provides the handle for the ntitle. | ||
11 | % | ||
12 | % Created by Chad A. Greene on the fifth of June, 2013. | ||
10 | % the argument 'location'. Output h provides the handle for the ntitle. | ||
11 | % | ||
12 | % Created by Chad A. Greene on the fifth of June, 2013. | ||
13 | 13 | % | % |
14 | % % Example: | ||
15 | % | ||
16 | % % First make a plot: | ||
17 | % x = -50:.1:50; | ||
18 | % y = 10*sin(x)+.1*x.^2; | ||
14 | % % Example: | ||
15 | % | ||
16 | % % First make a plot: | ||
17 | % x = -50:.1:50; | ||
18 | % y = 10*sin(x)+.1*x.^2; | ||
19 | 19 | % plot(x,y); | % plot(x,y); |
20 | 20 | % axis([-50 50 -50 300]) | % axis([-50 50 -50 300]) |
21 | 21 | % box off | % box off |
22 | % | ||
23 | % % Then here are 9 obnoxious examples of how to use ntitle: | ||
22 | % | ||
23 | % % Then here are 9 obnoxious examples of how to use ntitle: | ||
24 | 24 | % ntitle('Title 1'); | % ntitle('Title 1'); |
25 | 25 | % ntitle('{\it Title 2}','location','northwest'); | % ntitle('{\it Title 2}','location','northwest'); |
26 | 26 | % ntitle('Title 3 ','location','northeast','fontsize',10,'edgecolor','b'); | % ntitle('Title 3 ','location','northeast','fontsize',10,'edgecolor','b'); |
... | ... | for n=1:2:length(varargin) | |
42 | 42 | if strcmpi(varargin{n},'location') | if strcmpi(varargin{n},'location') |
43 | 43 | if strcmpi(varargin{n+1},'northwest') | if strcmpi(varargin{n+1},'northwest') |
44 | 44 | set(h,'horizontalalignment','left','verticalalignment','top','position',[0 1 0]) | set(h,'horizontalalignment','left','verticalalignment','top','position',[0 1 0]) |
45 | |||
45 | |||
46 | 46 | elseif strcmpi(varargin{n+1},'north') | elseif strcmpi(varargin{n+1},'north') |
47 | 47 | % This case is default and has already been set. | % This case is default and has already been set. |
48 | |||
48 | |||
49 | 49 | elseif strcmpi(varargin{n+1},'northeast') | elseif strcmpi(varargin{n+1},'northeast') |
50 | 50 | set(h,'horizontalalignment','right','verticalalignment','top','position',[1 1 0]) | set(h,'horizontalalignment','right','verticalalignment','top','position',[1 1 0]) |
51 | |||
51 | |||
52 | 52 | elseif strcmpi(varargin{n+1},'west') | elseif strcmpi(varargin{n+1},'west') |
53 | 53 | set(h,'horizontalalignment','left','verticalalignment','middle','position',[0 .5 0]) | set(h,'horizontalalignment','left','verticalalignment','middle','position',[0 .5 0]) |
54 | |||
54 | |||
55 | 55 | elseif strcmpi(varargin{n+1},'center') | elseif strcmpi(varargin{n+1},'center') |
56 | 56 | set(h,'horizontalalignment','center','verticalalignment','middle','position',[.5 .5 0]) | set(h,'horizontalalignment','center','verticalalignment','middle','position',[.5 .5 0]) |
57 | |||
57 | |||
58 | 58 | elseif strcmpi(varargin{n+1},'east') | elseif strcmpi(varargin{n+1},'east') |
59 | 59 | set(h,'horizontalalignment','right','verticalalignment','middle','position',[1 .5 0]) | set(h,'horizontalalignment','right','verticalalignment','middle','position',[1 .5 0]) |
60 | |||
60 | |||
61 | 61 | elseif strcmpi(varargin{n+1},'southwest') | elseif strcmpi(varargin{n+1},'southwest') |
62 | 62 | set(h,'horizontalalignment','left','verticalalignment','bottom','position',[0 0 0]) | set(h,'horizontalalignment','left','verticalalignment','bottom','position',[0 0 0]) |
63 | |||
63 | |||
64 | 64 | elseif strcmpi(varargin{n+1},'south') | elseif strcmpi(varargin{n+1},'south') |
65 | 65 | set(h,'horizontalalignment','center','verticalalignment','bottom','position',[.5 0 0]) | set(h,'horizontalalignment','center','verticalalignment','bottom','position',[.5 0 0]) |
66 | |||
66 | |||
67 | 67 | elseif strcmpi(varargin{n+1},'southeast') | elseif strcmpi(varargin{n+1},'southeast') |
68 | 68 | set(h,'horizontalalignment','right','verticalalignment','bottom','position',[1 0 0]) | set(h,'horizontalalignment','right','verticalalignment','bottom','position',[1 0 0]) |
69 | |||
69 | |||
70 | 70 | end | end |
71 | |||
71 | |||
72 | 72 | else | else |
73 | 73 | set(h,varargin{n},varargin{n+1}) | set(h,varargin{n},varargin{n+1}) |
74 | 74 | end | end |
75 | 75 | end | end |
76 | 76 | ||
77 | % Return the title handle only if it is desired: | ||
77 | % Return the title handle only if it is desired: | ||
78 | 78 | if nargout==0 | if nargout==0 |
79 | clear h; | ||
79 | clear h; | ||
80 | 80 | end | end |
81 | 81 | ||
82 | 82 | ||
83 | 83 | end | end |
84 |
File misc/3rdparty/num2eng.m changed (mode: 100644) (index 1b8aae6..ab351cd) | |||
... | ... | function str=num2eng(num); | |
4 | 4 | % notation string using International System of Units (SI) prefixes. | % notation string using International System of Units (SI) prefixes. |
5 | 5 | % | % |
6 | 6 | % Examples: | % Examples: |
7 | % num2eng(23e8) produces the string | ||
7 | % num2eng(23e8) produces the string | ||
8 | 8 | % '2.3G' | % '2.3G' |
9 | 9 | % | % |
10 | % num2eng(0.0000004) produces the string | ||
10 | % num2eng(0.0000004) produces the string | ||
11 | 11 | % '400n' | % '400n' |
12 | 12 | ||
13 | 13 | % Copyright (c) by Federico Forte | % Copyright (c) by Federico Forte |
14 | % Date: 2006/10/20 | ||
14 | % Date: 2006/10/20 | ||
15 | 15 | ||
16 | 16 | if abs(num)<=eps | if abs(num)<=eps |
17 | str = '0'; | ||
17 | str = '0'; | ||
18 | 18 | elseif isequal(num,inf) | elseif isequal(num,inf) |
19 | str = 'inf'; | ||
19 | str = 'inf'; | ||
20 | 20 | elseif isequal(num,-inf) | elseif isequal(num,-inf) |
21 | str = '-inf'; | ||
21 | str = '-inf'; | ||
22 | 22 | else | else |
23 | suffix_str='yzafpnum kMGTPEZY'; | ||
24 | k=1; | ||
25 | while abs(num)>=10^(3*(k-8)) && k<=16, | ||
26 | k=k+1; | ||
27 | end | ||
28 | if k~=9, | ||
29 | suff=suffix_str(k); | ||
30 | else | ||
31 | suff=''; | ||
32 | end | ||
23 | suffix_str='yzafpnum kMGTPEZY'; | ||
24 | k=1; | ||
25 | while abs(num)>=10^(3*(k-8)) && k<=16, | ||
26 | k=k+1; | ||
27 | end | ||
28 | if k~=9, | ||
29 | suff=suffix_str(k); | ||
30 | else | ||
31 | suff=''; | ||
32 | end | ||
33 | 33 | ||
34 | str=[num2str(num/10^(3*(k-9))),suff]; | ||
34 | str=[num2str(num/10^(3*(k-9))),suff]; | ||
35 | 35 | end | end |
File misc/3rdparty/printstruct.m changed (mode: 100644) (index e729af0..f08f3bf) | |||
1 | 1 | function pS = printstruct(S, varargin) | function pS = printstruct(S, varargin) |
2 | 2 | % PRINTSTRUCT Recursively print hierarchical outline of structure contents | % PRINTSTRUCT Recursively print hierarchical outline of structure contents |
3 | % | ||
3 | % | ||
4 | 4 | % This is a minor adaptation of the File Exchange contribution "Structure | % This is a minor adaptation of the File Exchange contribution "Structure |
5 | 5 | % outline" written by B. Roossien <roossien@ecn.nl> and available here: | % outline" written by B. Roossien <roossien@ecn.nl> and available here: |
6 | 6 | % http://mathworks.com/matlabcentral/fileexchange/13500-structure-outline | % http://mathworks.com/matlabcentral/fileexchange/13500-structure-outline |
7 | 7 | % __________________________________________________________________________ | % __________________________________________________________________________ |
8 | 8 | % USAGE: pS = printstruct(S, varargin) | % USAGE: pS = printstruct(S, varargin) |
9 | % | ||
9 | % | ||
10 | 10 | % IN: S = structure variable to print | % IN: S = structure variable to print |
11 | 11 | % OUT*: pS = cell array containing printed structure | % OUT*: pS = cell array containing printed structure |
12 | % | ||
12 | % | ||
13 | 13 | % *If defined, result will NOT display in command window | % *If defined, result will NOT display in command window |
14 | 14 | % __________________________________________________________________________ | % __________________________________________________________________________ |
15 | 15 | % OPTIONAL VARARGIN* [entered as 'name', value pairs]: | % OPTIONAL VARARGIN* [entered as 'name', value pairs]: |
16 | 16 | % *Run printstruct w/no arguments to see default values | % *Run printstruct w/no arguments to see default values |
17 | % | ||
18 | % NLEVELS: N levels to print. If negative, all levels printed. | ||
17 | % | ||
18 | % NLEVELS: N levels to print. If negative, all levels printed. | ||
19 | 19 | % NINDENT: number of tab indents for each line of printed struct | % NINDENT: number of tab indents for each line of printed struct |
20 | 20 | % STRUCTNAME: top level name (if empty, variable name will be used) | % STRUCTNAME: top level name (if empty, variable name will be used) |
21 | 21 | % PRINTCONTENTS: flag to print field values/contents as well | % PRINTCONTENTS: flag to print field values/contents as well |
22 | 22 | % MAXARRAYLENGTH: for fields with array data, max length of values to | % MAXARRAYLENGTH: for fields with array data, max length of values to |
23 | 23 | % print. Values of a 2-D (m,n) array are printed if the number of | % print. Values of a 2-D (m,n) array are printed if the number of |
24 | 24 | % elements (m x n) is smaller or equal to maxarraylength. This is ignored | % elements (m x n) is smaller or equal to maxarraylength. This is ignored |
25 | % if printvalues is 0. | ||
25 | % if printvalues is 0. | ||
26 | 26 | % _______________________________ | % _______________________________ |
27 | 27 | % EXAMPLES | % EXAMPLES |
28 | % | ||
29 | % pS = printstruct(S, 'maxarray', 100); | ||
28 | % | ||
29 | % pS = printstruct(S, 'maxarray', 100); | ||
30 | 30 | % printstruct(S, 'nlevels', 2, 'printcontents', 0, 'nindent', 3) | % printstruct(S, 'nlevels', 2, 'printcontents', 0, 'nindent', 3) |
31 | % | ||
31 | % | ||
32 | 32 | ||
33 | 33 | % ---------------------- Copyright (C) 2015 Bob Spunt ---------------------- | % ---------------------- Copyright (C) 2015 Bob Spunt ---------------------- |
34 | 34 | % Created: 2015-08-13 | % Created: 2015-08-13 |
35 | 35 | % Email: spunt@caltech.edu | % Email: spunt@caltech.edu |
36 | 36 | % __________________________________________________________________________ | % __________________________________________________________________________ |
37 | def = { ... | ||
38 | 'nlevels', -1, ... | ||
39 | 'printcontents', 1, ... | ||
37 | def = { ... | ||
38 | 'nlevels', -1, ... | ||
39 | 'printcontents', 1, ... | ||
40 | 40 | 'nindent', 0, ... | 'nindent', 0, ... |
41 | 41 | 'structname', '', ... | 'structname', '', ... |
42 | 42 | 'maxarraylength', 10 ... | 'maxarraylength', 10 ... |
43 | }; | ||
43 | }; | ||
44 | 44 | vals = setargs(def, varargin); | vals = setargs(def, varargin); |
45 | 45 | if nargin==0, mfile_showhelp; fprintf('\t| - VARARGIN DEFAULTS - |\n'); disp(vals); return; end | if nargin==0, mfile_showhelp; fprintf('\t| - VARARGIN DEFAULTS - |\n'); disp(vals); return; end |
46 | 46 | if nlevels==0, nlevels = -1; end; | if nlevels==0, nlevels = -1; end; |
... | ... | if length(S)==1 | |
49 | 49 | str = recFieldPrint(S, nindent, nlevels, printcontents, maxarraylength, structname); | str = recFieldPrint(S, nindent, nlevels, printcontents, maxarraylength, structname); |
50 | 50 | str = [cellstr(structname); str]; | str = [cellstr(structname); str]; |
51 | 51 | else | else |
52 | str = []; | ||
52 | str = []; | ||
53 | 53 | for i = 1:length(S) | for i = 1:length(S) |
54 | 54 | tmpstr = recFieldPrint(S(i), nindent, nlevels, printcontents, maxarraylength, structname); | tmpstr = recFieldPrint(S(i), nindent, nlevels, printcontents, maxarraylength, structname); |
55 | 55 | str = [str; cellstr(sprintf('%s(%d)', structname, i)); tmpstr]; | str = [str; cellstr(sprintf('%s(%d)', structname, i)); tmpstr]; |
... | ... | end | |
59 | 59 | if nargout==0 | if nargout==0 |
60 | 60 | for i = 1:length(str), disp(cell2mat(str(i, 1))); end | for i = 1:length(str), disp(cell2mat(str(i, 1))); end |
61 | 61 | else | else |
62 | pS = str; | ||
62 | pS = str; | ||
63 | 63 | end | end |
64 | 64 | end | end |
65 | 65 | % ========================================================================== | % ========================================================================== |
... | ... | end | |
69 | 69 | % ========================================================================== | % ========================================================================== |
70 | 70 | function argstruct = setargs(defaults, optargs) | function argstruct = setargs(defaults, optargs) |
71 | 71 | % SETARGS Name/value parsing and assignment of varargin with default values | % SETARGS Name/value parsing and assignment of varargin with default values |
72 | % | ||
72 | % | ||
73 | 73 | % This is a utility for setting the value of optional arguments to a | % This is a utility for setting the value of optional arguments to a |
74 | 74 | % function. The first argument is required and should be a cell array of | % function. The first argument is required and should be a cell array of |
75 | 75 | % "name, default value" pairs for all optional arguments. The second | % "name, default value" pairs for all optional arguments. The second |
76 | 76 | % argument is optional and should be a cell array of "name, custom value" | % argument is optional and should be a cell array of "name, custom value" |
77 | 77 | % pairs for at least one of the optional arguments. | % pairs for at least one of the optional arguments. |
78 | % | ||
79 | % USAGE: argstruct = setargs(defaults, args) | ||
78 | % | ||
79 | % USAGE: argstruct = setargs(defaults, args) | ||
80 | 80 | % __________________________________________________________________________ | % __________________________________________________________________________ |
81 | 81 | % OUTPUT | % OUTPUT |
82 | % | ||
82 | % | ||
83 | 83 | % argstruct: structure containing the final argument values | % argstruct: structure containing the final argument values |
84 | 84 | % __________________________________________________________________________ | % __________________________________________________________________________ |
85 | 85 | % INPUTS | % INPUTS |
86 | % | ||
87 | % defaults: | ||
86 | % | ||
87 | % defaults: | ||
88 | 88 | % cell array of "name, default value" pairs for all optional arguments | % cell array of "name, default value" pairs for all optional arguments |
89 | % | ||
90 | % optargs [optional] | ||
89 | % | ||
90 | % optargs [optional] | ||
91 | 91 | % cell array of "name, custom value" pairs for at least one of the | % cell array of "name, custom value" pairs for at least one of the |
92 | % optional arguments. this will typically be the "varargin" array. | ||
92 | % optional arguments. this will typically be the "varargin" array. | ||
93 | 93 | % __________________________________________________________________________ | % __________________________________________________________________________ |
94 | 94 | % USAGE EXAMPLE (WITHIN FUNCTION) | % USAGE EXAMPLE (WITHIN FUNCTION) |
95 | % | ||
96 | % defaults = {'arg1', 0, 'arg2', 'words', 'arg3', rand}; | ||
95 | % | ||
96 | % defaults = {'arg1', 0, 'arg2', 'words', 'arg3', rand}; | ||
97 | 97 | % argstruct = setargs(defaults, varargin) | % argstruct = setargs(defaults, varargin) |
98 | 98 | % | % |
99 | 99 | ||
... | ... | function argstruct = setargs(defaults, optargs) | |
101 | 101 | % ---------------------- Copyright (C) 2015 Bob Spunt ---------------------- | % ---------------------- Copyright (C) 2015 Bob Spunt ---------------------- |
102 | 102 | % Created: 2015-03-11 | % Created: 2015-03-11 |
103 | 103 | % Email: spunt@caltech.edu | % Email: spunt@caltech.edu |
104 | % | ||
104 | % | ||
105 | 105 | % This program is free software: you can redistribute it and/or modify | % This program is free software: you can redistribute it and/or modify |
106 | 106 | % it under the terms of the GNU General Public License as published by | % it under the terms of the GNU General Public License as published by |
107 | 107 | % the Free Software Foundation, either version 3 of the License, or (at | % the Free Software Foundation, either version 3 of the License, or (at |
... | ... | function argstruct = setargs(defaults, optargs) | |
115 | 115 | % __________________________________________________________________________ | % __________________________________________________________________________ |
116 | 116 | if nargin < 1, mfile_showhelp; return; end | if nargin < 1, mfile_showhelp; return; end |
117 | 117 | if nargin < 2, optargs = []; end | if nargin < 2, optargs = []; end |
118 | defaults = reshape(defaults, 2, length(defaults)/2)'; | ||
118 | defaults = reshape(defaults, 2, length(defaults)/2)'; | ||
119 | 119 | if ~isempty(optargs) | if ~isempty(optargs) |
120 | 120 | if mod(length(optargs), 2) | if mod(length(optargs), 2) |
121 | error('Optional inputs must be entered as Name, Value pairs, e.g., myfunction(''name'', value)'); | ||
121 | error('Optional inputs must be entered as Name, Value pairs, e.g., myfunction(''name'', value)'); | ||
122 | 122 | end | end |
123 | 123 | arg = reshape(optargs, 2, length(optargs)/2)'; | arg = reshape(optargs, 2, length(optargs)/2)'; |
124 | 124 | for i = 1:size(arg,1) | for i = 1:size(arg,1) |
... | ... | if ~isempty(optargs) | |
129 | 129 | error('Input "%s" does not match a valid input.', arg{i,1}); | error('Input "%s" does not match a valid input.', arg{i,1}); |
130 | 130 | else | else |
131 | 131 | defaults{idx,2} = arg{i,2}; | defaults{idx,2} = arg{i,2}; |
132 | end | ||
132 | end | ||
133 | 133 | end | end |
134 | 134 | end | end |
135 | 135 | for i = 1:size(defaults,1), assignin('caller', defaults{i,1}, defaults{i,2}); end | for i = 1:size(defaults,1), assignin('caller', defaults{i,1}, defaults{i,2}); end |
... | ... | function mfile_showhelp(varargin) | |
139 | 139 | % MFILE_SHOWHELP | % MFILE_SHOWHELP |
140 | 140 | ST = dbstack('-completenames'); | ST = dbstack('-completenames'); |
141 | 141 | if isempty(ST), fprintf('\nYou must call this within a function\n\n'); return; end | if isempty(ST), fprintf('\nYou must call this within a function\n\n'); return; end |
142 | eval(sprintf('help %s', ST(2).file)); | ||
142 | eval(sprintf('help %s', ST(2).file)); | ||
143 | 143 | end | end |
144 | 144 | % | ADAPTED FROM FROM STRUCDISP | % | ADAPTED FROM FROM STRUCDISP |
145 | 145 | function listStr = recFieldPrint(Structure, indent, depth, printValues, maxArrayLength, structname) | function listStr = recFieldPrint(Structure, indent, depth, printValues, maxArrayLength, structname) |
146 | 146 | % RECFIELDPRINT Recursive printing of a structure variable | % RECFIELDPRINT Recursive printing of a structure variable |
147 | 147 | % This function and its dependencies were taken from: | % This function and its dependencies were taken from: |
148 | % STRUCDISP.m by | ||
148 | % STRUCDISP.m by | ||
149 | 149 | % Contact author: B. Roossien <roossien@ecn.nl> | % Contact author: B. Roossien <roossien@ecn.nl> |
150 | 150 | % (c) ECN 2007-2008 | % (c) ECN 2007-2008 |
151 | 151 | % Version 1.3.0 | % Version 1.3.0 |
... | ... | if length(Structure) > 1 | |
157 | 157 | varStr = createArraySize(Structure, structname); | varStr = createArraySize(Structure, structname); |
158 | 158 | listStr = [{' '}; {[structname, varStr]}]; | listStr = [{' '}; {[structname, varStr]}]; |
159 | 159 | body = recFieldPrint(Structure(1), indent, depth, ... | body = recFieldPrint(Structure(1), indent, depth, ... |
160 | printValues, maxArrayLength); | ||
160 | printValues, maxArrayLength); | ||
161 | 161 | listStr = [listStr; body]; | listStr = [listStr; body]; |
162 | 162 | else | else |
163 | 163 | for iStruc = 1 : length(Structure) | for iStruc = 1 : length(Structure) |
... | ... | strIndent = getIndentation(indent + 1); | |
176 | 176 | listStr = [listStr; {strIndent}]; | listStr = [listStr; {strIndent}]; |
177 | 177 | strIndent = getIndentation(indent); | strIndent = getIndentation(indent); |
178 | 178 | for iField = 1 : length(strucFields) | for iField = 1 : length(strucFields) |
179 | |||
179 | |||
180 | 180 | fieldName = cell2mat(strucFields(iField)); | fieldName = cell2mat(strucFields(iField)); |
181 | 181 | Field = Structure.(fieldName); | Field = Structure.(fieldName); |
182 | |||
182 | |||
183 | 183 | % Empty structure | % Empty structure |
184 | 184 | if isempty(Field) | if isempty(Field) |
185 | 185 | strSize = createArraySize(Field, 'Structure'); | strSize = createArraySize(Field, 'Structure'); |
... | ... | for iField = 1 : length(strucFields) | |
197 | 197 | else | else |
198 | 198 | listStr = [listStr; {line}]; | listStr = [listStr; {line}]; |
199 | 199 | end | end |
200 | % Short vector structure of which the values should be printed | ||
200 | % Short vector structure of which the values should be printed | ||
201 | 201 | elseif (isvector(Field)) && ... | elseif (isvector(Field)) && ... |
202 | 202 | (printValues > 0) && ... | (printValues > 0) && ... |
203 | 203 | (length(Field) < maxArrayLength) && ... | (length(Field) < maxArrayLength) && ... |
... | ... | for iField = 1 : length(strucFields) | |
224 | 224 | listStr = [listStr; {line}; lines]; | listStr = [listStr; {line}; lines]; |
225 | 225 | end | end |
226 | 226 | % Some extra blank lines to increase readability | % Some extra blank lines to increase readability |
227 | listStr = [listStr; {[strIndent ' | ']}]; | ||
228 | |||
227 | listStr = [listStr; {[strIndent ' | ']}]; | ||
228 | |||
229 | 229 | end % End iField for-loop | end % End iField for-loop |
230 | 230 | %% Field Filler | %% Field Filler |
231 | 231 | % To properly align the field names, a filler is required. To know how long | % To properly align the field names, a filler is required. To know how long |
... | ... | otherFields = fields(isOther == 1); | |
291 | 291 | % - Vectors are printed as long as they are shorter than maxArrayLength | % - Vectors are printed as long as they are shorter than maxArrayLength |
292 | 292 | % - Matrices are printed if they have less elements than maxArrayLength | % - Matrices are printed if they have less elements than maxArrayLength |
293 | 293 | % - The values of cells are not printed | % - The values of cells are not printed |
294 | % Start with printing strings and characters. To avoid the display screen | ||
295 | % becoming a mess, the part of the string that is printed is limited to 31 | ||
294 | % Start with printing strings and characters. To avoid the display screen | ||
295 | % becoming a mess, the part of the string that is printed is limited to 31 | ||
296 | 296 | % characters. In the future this might become an optional parameter in this | % characters. In the future this might become an optional parameter in this |
297 | 297 | % function, but for now, it is placed in the code itself. | % function, but for now, it is placed in the code itself. |
298 | 298 | % if the string is longer than 31 characters, only the first 31 characters | % if the string is longer than 31 characters, only the first 31 characters |
... | ... | for iField = 1 : length(matrixFields) | |
373 | 373 | filler2 = char(ones(1, maxFieldLength + 6) * 32); | filler2 = char(ones(1, maxFieldLength + 6) * 32); |
374 | 374 | dashes = char(ones(1, 12 * matrixSize(2) + 1) * 45); | dashes = char(ones(1, 12 * matrixSize(2) + 1) * 45); |
375 | 375 | varCell = {[strIndent ' |' filler2 dashes]}; | varCell = {[strIndent ' |' filler2 dashes]}; |
376 | |||
376 | |||
377 | 377 | % first line with field name | % first line with field name |
378 | 378 | varStr = sprintf('%#10.2e |', Structure.(Field)(1, :)); | varStr = sprintf('%#10.2e |', Structure.(Field)(1, :)); |
379 | 379 | varCell = [varCell; {[strIndent ' |' filler ' ' ... | varCell = [varCell; {[strIndent ' |' filler ' ' ... |
... | ... | for iField = 1 : length(matrixFields) | |
384 | 384 | varCell = [varCell; {[strIndent ' |' filler2 '|' varStr]}]; | varCell = [varCell; {[strIndent ' |' filler2 '|' varStr]}]; |
385 | 385 | end | end |
386 | 386 | varCell = [varCell; {[strIndent ' |' filler2 dashes]}]; | varCell = [varCell; {[strIndent ' |' filler2 dashes]}]; |
387 | |||
387 | |||
388 | 388 | end | end |
389 | |||
389 | |||
390 | 390 | listStr = [listStr; varCell]; | listStr = [listStr; varCell]; |
391 | 391 | end | end |
392 | 392 | % Print cell array information, i.e. the size of the cell array. The | % Print cell array information, i.e. the size of the cell array. The |
... | ... | end | |
408 | 408 | function str = getIndentation(indent) | function str = getIndentation(indent) |
409 | 409 | x = ' | '; | x = ' | '; |
410 | 410 | str = ''; | str = ''; |
411 | |||
411 | |||
412 | 412 | for i = 1 : indent | for i = 1 : indent |
413 | 413 | str = cat(2, str, x); | str = cat(2, str, x); |
414 | 414 | end | end |
... | ... | function varStr = createArraySize(varName, type) | |
418 | 418 | ||
419 | 419 | arraySizeStr = sprintf('%gx', varSize); | arraySizeStr = sprintf('%gx', varSize); |
420 | 420 | arraySizeStr(length(arraySizeStr)) = []; | arraySizeStr(length(arraySizeStr)) = []; |
421 | |||
421 | |||
422 | 422 | varStr = [' [' arraySizeStr ' ' type ']']; | varStr = [' [' arraySizeStr ' ' type ']']; |
423 | 423 | end | end |
File misc/3rdparty/ringdown.m changed (mode: 100644) (index b28883c..c26516d) | |||
... | ... | function res_rd=ringdown(res,noiseLevel,plots,verbose) | |
23 | 23 | % NOISELEVEL sets a threshold level for the data analysis. Only data for | % NOISELEVEL sets a threshold level for the data analysis. Only data for |
24 | 24 | % which the amplitude is greater than NOISELEVEL*MAX(data) will be used. | % which the amplitude is greater than NOISELEVEL*MAX(data) will be used. |
25 | 25 | % Default is 0.1 (i.e., 10%). | % Default is 0.1 (i.e., 10%). |
26 | % | ||
26 | % | ||
27 | 27 | % Use PLOTS (0|1|2) and VERBOSE (0|1|2) to set the number of plots and the | % Use PLOTS (0|1|2) and VERBOSE (0|1|2) to set the number of plots and the |
28 | 28 | % number of messages. | % number of messages. |
29 | 29 | % | % |
... | ... | function res_rd=ringdown(res,noiseLevel,plots,verbose) | |
43 | 43 | % ringdown: Data after t=2.275 ignored (signal < 0.9) | % ringdown: Data after t=2.275 ignored (signal < 0.9) |
44 | 44 | % ringdown: Min. search function value: 0.001 | % ringdown: Min. search function value: 0.001 |
45 | 45 | % | % |
46 | % r = | ||
47 | % | ||
46 | % r = | ||
47 | % | ||
48 | 48 | % trace1: [1x1 struct] | % trace1: [1x1 struct] |
49 | 49 | % f0: 3.3241 | % f0: 3.3241 |
50 | 50 | % Q: 10.4441 | % Q: 10.4441 |
... | ... | if plots >= 1, datafig=figure; end | |
99 | 99 | else | else |
100 | 100 | fprintf(1,'ringdown: Error: no data trace from oscilloscope.\n'); | fprintf(1,'ringdown: Error: no data trace from oscilloscope.\n'); |
101 | 101 | end | end |
102 | |||
102 | |||
103 | 103 | % determine sample interval | % determine sample interval |
104 | 104 | time_length=t(end)-t(1); | time_length=t(end)-t(1); |
105 | 105 | sample_int=time_length/(length(t)-1); | sample_int=time_length/(length(t)-1); |
... | ... | Qest=mean([Qestu Qestl]); | |
243 | 243 | % plot Q estimated results | % plot Q estimated results |
244 | 244 | if plots >= 2 | if plots >= 2 |
245 | 245 | figure(fftfig); subplot(1,2,2); | figure(fftfig); subplot(1,2,2); |
246 | plot(tuefit,real(log(Vuefit)),'.-r'); | ||
246 | plot(tuefit,real(log(Vuefit)),'.-r'); | ||
247 | 247 | hold on; | hold on; |
248 | 248 | plot(tlefit,real(log(Vlefit)),'.-g'); | plot(tlefit,real(log(Vlefit)),'.-g'); |
249 | 249 | title('Envelope & Log Fit'); | title('Envelope & Log Fit'); |
File misc/3rdparty/suptitle.m changed (mode: 100644) (index efce003..6cf01da) | |||
... | ... | axes(haold); %#ok<MAXES> | |
109 | 109 | if nargout, | if nargout, |
110 | 110 | hout=ht; | hout=ht; |
111 | 111 | end | end |
112 | |||
113 | |||
114 |
File misc/3rdparty/textprogressbar.m changed (mode: 100644) (index 87ba5ff..082b9d9) | |||
1 | 1 | function textprogressbar(c) | function textprogressbar(c) |
2 | % This function creates a text progress bar. It should be called with a | ||
3 | % STRING argument to initialize and terminate. Otherwise the number correspoding | ||
2 | % This function creates a text progress bar. It should be called with a | ||
3 | % STRING argument to initialize and terminate. Otherwise the number correspoding | ||
4 | 4 | % to progress in % should be supplied. | % to progress in % should be supplied. |
5 | % INPUTS: C Either: Text string to initialize or terminate | ||
6 | % Percentage number to show progress | ||
5 | % INPUTS: C Either: Text string to initialize or terminate | ||
6 | % Percentage number to show progress | ||
7 | 7 | % OUTPUTS: N/A | % OUTPUTS: N/A |
8 | 8 | % Example: Please refer to demo_textprogressbar.m | % Example: Please refer to demo_textprogressbar.m |
9 | 9 | ||
... | ... | persistent strCR; % Carriage return pesistent variable | |
20 | 20 | strPercentageLength = 10; % Length of percentage string (must be >5) | strPercentageLength = 10; % Length of percentage string (must be >5) |
21 | 21 | strDotsMaximum = 10; % The total number of dots in a progress bar | strDotsMaximum = 10; % The total number of dots in a progress bar |
22 | 22 | ||
23 | %% Main | ||
23 | %% Main | ||
24 | 24 | ||
25 | 25 | if isempty(strCR) && ~ischar(c), | if isempty(strCR) && ~ischar(c), |
26 | 26 | % Progress bar must be initialized with a string | % Progress bar must be initialized with a string |
... | ... | elseif isempty(strCR) && ischar(c), | |
31 | 31 | strCR = -1; | strCR = -1; |
32 | 32 | elseif ~isempty(strCR) && ischar(c), | elseif ~isempty(strCR) && ischar(c), |
33 | 33 | % Progress bar - termination | % Progress bar - termination |
34 | strCR = []; | ||
34 | strCR = []; | ||
35 | 35 | fprintf([c '\n']); | fprintf([c '\n']); |
36 | 36 | elseif isnumeric(c) | elseif isnumeric(c) |
37 | 37 | % Progress bar - normal progress | % Progress bar - normal progress |
... | ... | elseif isnumeric(c) | |
41 | 41 | nDots = floor(c/100*strDotsMaximum); | nDots = floor(c/100*strDotsMaximum); |
42 | 42 | dotOut = ['[' repmat('.',1,nDots) repmat(' ',1,strDotsMaximum-nDots) ']']; | dotOut = ['[' repmat('.',1,nDots) repmat(' ',1,strDotsMaximum-nDots) ']']; |
43 | 43 | strOut = [percentageOut dotOut]; | strOut = [percentageOut dotOut]; |
44 | |||
44 | |||
45 | 45 | % Print it on the screen | % Print it on the screen |
46 | 46 | if strCR == -1, | if strCR == -1, |
47 | 47 | % Don't do carriage return during first run | % Don't do carriage return during first run |
... | ... | elseif isnumeric(c) | |
50 | 50 | % Do it during all the other runs | % Do it during all the other runs |
51 | 51 | fprintf([strCR strOut]); | fprintf([strCR strOut]); |
52 | 52 | end | end |
53 | |||
53 | |||
54 | 54 | % Update carriage return | % Update carriage return |
55 | 55 | strCR = repmat('\b',1,length(strOut)-1); | strCR = repmat('\b',1,length(strOut)-1); |
56 | |||
56 | |||
57 | 57 | else | else |
58 | 58 | % Any other unexpected input | % Any other unexpected input |
59 | 59 | error('Unsupported argument type'); | error('Unsupported argument type'); |
File misc/checkdim.m changed (mode: 100644) (index aa8c3c8..06d4465) | |||
... | ... | if ~isempty(H) | |
35 | 35 | if h1~=d1, warning('H and D must have same number of rows');h=0; end | if h1~=d1, warning('H and D must have same number of rows');h=0; end |
36 | 36 | if g2~=d2, warning('G and D must have same number of columns');h=0; end | if g2~=d2, warning('G and D must have same number of columns');h=0; end |
37 | 37 | end | end |
38 | |||
38 | |||
39 | 39 | % check measurement vector | % check measurement vector |
40 | 40 | if ~isempty(z) | if ~isempty(z) |
41 | 41 | [z1,z2]=size(z); | [z1,z2]=size(z); |
File misc/convenience/class_conveniences.m changed (mode: 100644) (index 818ace4..2dfa447) | |||
1 | 1 | classdef class_conveniences < matlab.mixin.Copyable | classdef class_conveniences < matlab.mixin.Copyable |
2 | %% class_conveniences is a convenience superclass which inherits from matlab.mixin.Copyable | ||
3 | %% it implements some methods and properties which are useful for several other classes | ||
4 | properties(Constant, Hidden) | ||
5 | hbar = 1.0545718e-34; | ||
6 | kB = 1.38064852e-23; | ||
7 | end | ||
8 | properties(Dependent, Hidden) | ||
2 | %% class_conveniences is a convenience superclass which inherits from matlab.mixin.Copyable | ||
3 | %% it implements some methods and properties which are useful for several other classes | ||
4 | properties(Constant, Hidden) | ||
5 | hbar = 1.0545718e-34; | ||
6 | kB = 1.38064852e-23; | ||
7 | end | ||
8 | properties(Dependent, Hidden) | ||
9 | 9 | software_version % stores path and id of current commit for every git repository on MATLAB path at query time | software_version % stores path and id of current commit for every git repository on MATLAB path at query time |
10 | 10 | end | end |
11 | |||
12 | properties(Hidden) | ||
11 | |||
12 | properties(Hidden) | ||
13 | 13 | software_version_private | software_version_private |
14 | end | ||
14 | end | ||
15 | 15 | ||
16 | 16 | methods | methods |
17 | 17 | function software_version = get.software_version(obj) | function software_version = get.software_version(obj) |
... | ... | classdef class_conveniences < matlab.mixin.Copyable | |
24 | 24 | end | end |
25 | 25 | ||
26 | 26 | function obj = parseVararginForMissingFields(obj, varargin) | function obj = parseVararginForMissingFields(obj, varargin) |
27 | %obj = parseVararginForMissingFields(obj, varargin) attempts to fill empty | ||
28 | %properties of obj from the varargin-list... | ||
29 | % it checks varargin for for key-value-pairs of the form 'property', value | ||
30 | % where 'property' is the name of a property which is either empty or | ||
31 | % has a default value and then sets obj.('property') to value | ||
27 | %obj = parseVararginForMissingFields(obj, varargin) attempts to fill empty | ||
28 | %properties of obj from the varargin-list... | ||
29 | % it checks varargin for for key-value-pairs of the form 'property', value | ||
30 | % where 'property' is the name of a property which is either empty or | ||
31 | % has a default value and then sets obj.('property') to value | ||
32 | 32 | ||
33 | assert(isa(obj, 'handle'),... | ||
34 | 'Expecting handle object'); | ||
33 | assert(isa(obj, 'handle'),... | ||
34 | 'Expecting handle object'); | ||
35 | 35 | ||
36 | %% find empty properties which are not dependent | ||
37 | props = properties(obj); | ||
36 | %% find empty properties which are not dependent | ||
37 | props = properties(obj); | ||
38 | 38 | ||
39 | empty_or_default_props = {}; | ||
40 | empty_or_default_props_no = 0; | ||
39 | empty_or_default_props = {}; | ||
40 | empty_or_default_props_no = 0; | ||
41 | 41 | ||
42 | for k=1:length(props) | ||
43 | prop = props{k}; | ||
44 | prop_attributes = findprop(obj, prop); | ||
45 | if ~prop_attributes.Dependent | ||
46 | % don't mess with dependent properties | ||
47 | if isempty(obj.(prop)) || prop_attributes.HasDefault | ||
48 | % check empty properties or properties with default values | ||
49 | empty_or_default_props_no = empty_or_default_props_no +1; | ||
50 | empty_or_default_props{ empty_or_default_props_no } = prop; %#ok<*AGROW> | ||
51 | end | ||
52 | end | ||
53 | end | ||
42 | for k=1:length(props) | ||
43 | prop = props{k}; | ||
44 | prop_attributes = findprop(obj, prop); | ||
45 | if ~prop_attributes.Dependent | ||
46 | % don't mess with dependent properties | ||
47 | if isempty(obj.(prop)) || prop_attributes.HasDefault | ||
48 | % check empty properties or properties with default values | ||
49 | empty_or_default_props_no = empty_or_default_props_no +1; | ||
50 | empty_or_default_props{ empty_or_default_props_no } = prop; %#ok<*AGROW> | ||
51 | end | ||
52 | end | ||
53 | end | ||
54 | 54 | ||
55 | %% parse varargin for the names of such properties | ||
56 | % and set property to the following argument | ||
57 | for k=1:2:length(varargin) | ||
58 | if any(ismember(empty_or_default_props,varargin{k})) | ||
59 | obj.(varargin{k}) = varargin{k+1}; | ||
60 | end | ||
61 | end | ||
62 | end | ||
55 | %% parse varargin for the names of such properties | ||
56 | % and set property to the following argument | ||
57 | for k=1:2:length(varargin) | ||
58 | if any(ismember(empty_or_default_props,varargin{k})) | ||
59 | obj.(varargin{k}) = varargin{k+1}; | ||
60 | end | ||
61 | end | ||
62 | end | ||
63 | 63 | ||
64 | 64 | end | end |
65 | 65 | end | end |
File misc/covmats/beam_splitter.m changed (mode: 100644) (index 8f89a95..70b2487) | |||
... | ... | function bs_sympmat = beam_splitter( r) | |
7 | 7 | ||
8 | 8 | id = eye(2); | id = eye(2); |
9 | 9 | bs_sympmat = [ r*id, sqrt(1-r^2)*id;... | bs_sympmat = [ r*id, sqrt(1-r^2)*id;... |
10 | sqrt(1-r^2)*id, -r*id]; | ||
10 | sqrt(1-r^2)*id, -r*id]; |
File misc/covmats/combineCMs_traceOutCM_test.m changed (mode: 100644) (index 75ad403..b04c16b) | |||
1 | 1 | function test_suite = combineCMs_traceOutCM_test %#ok<STOUT> | function test_suite = combineCMs_traceOutCM_test %#ok<STOUT> |
2 | initTestSuite; | ||
2 | initTestSuite; | ||
3 | 3 | ||
4 | 4 | function combine_traceout_randommat_test | function combine_traceout_randommat_test |
5 | 5 | mat1 = randn(6,6); | mat1 = randn(6,6); |
File misc/covmats/fidelity_test.m changed (mode: 100644) (index cb2f9cc..d28f710) | |||
1 | 1 | % fid = fidelity(X1,X2,cm1,cm2) | % fid = fidelity(X1,X2,cm1,cm2) |
2 | 2 | function test_suite = fidelity_test %#ok<STOUT> | function test_suite = fidelity_test %#ok<STOUT> |
3 | initTestSuite; | ||
3 | initTestSuite; | ||
4 | 4 | ||
5 | 5 | function smss_test | function smss_test |
6 | 6 | cm = smss(1)+0.001*eye(2); %need some noise to pass physicality-test | cm = smss(1)+0.001*eye(2); %need some noise to pass physicality-test |
File misc/covmats/gausseof.m changed (mode: 100644) (index 033a856..0e01bb8) | |||
... | ... | disp(sqrt((m2 - 1)/(n2 - 1))); | |
26 | 26 | ||
27 | 27 | ||
28 | 28 | eof = 0; | eof = 0; |
29 | % %% | ||
29 | % %% | ||
30 | 30 | % if ~isequal(size(sfparams), [1, 4]) | % if ~isequal(size(sfparams), [1, 4]) |
31 | 31 | % warning('Expecting a vector of 4 real parameters!'); | % warning('Expecting a vector of 4 real parameters!'); |
32 | 32 | % eof = 0; | % eof = 0; |
... | ... | eof = 0; | |
44 | 44 | % b2 = sfparams(2); | % b2 = sfparams(2); |
45 | 45 | % c = sfparams(3); | % c = sfparams(3); |
46 | 46 | % d = abs(sfparams(4)); %caution: we take abs already here | % d = abs(sfparams(4)); %caution: we take abs already here |
47 | % | ||
48 | % %% | ||
47 | % | ||
48 | % %% | ||
49 | 49 | % % a0, a4 | % % a0, a4 |
50 | 50 | % tc = b1*b2 - c^2; | % tc = b1*b2 - c^2; |
51 | 51 | % td = b1*b2 - d^2; | % td = b1*b2 - d^2; |
52 | % | ||
52 | % | ||
53 | 53 | % a0 = td*(b1*td - b2/4)*(b2*td - b1/4); | % a0 = td*(b1*td - b2/4)*(b2*td - b1/4); |
54 | 54 | % a4 = tc*(b1*tc - b2/4)*(b2*tc - b1/4); | % a4 = tc*(b1*tc - b2/4)*(b2*tc - b1/4); |
55 | % | ||
55 | % | ||
56 | 56 | % % a1, a3 | % % a1, a3 |
57 | 57 | % oc = c*td + d/4; | % oc = c*td + d/4; |
58 | 58 | % od = d*tc + c/4; | % od = d*tc + c/4; |
59 | % | ||
59 | % | ||
60 | 60 | % a1 = -oc*( oc*(b1 - b2)^2 + 2*b1*b2*(c-d)*(td - 1/4)); | % a1 = -oc*( oc*(b1 - b2)^2 + 2*b1*b2*(c-d)*(td - 1/4)); |
61 | 61 | % a3 = -od*( od*(b1 - b2)^2 + 2*b1*b2*(d-c)*(tc - 1/4)); | % a3 = -od*( od*(b1 - b2)^2 + 2*b1*b2*(d-c)*(tc - 1/4)); |
62 | % | ||
62 | % | ||
63 | 63 | % % a2 | % % a2 |
64 | 64 | % detV = tc*td; %checked | % detV = tc*td; %checked |
65 | 65 | % cd = c*d; | % cd = c*d; |
66 | % | ||
66 | % | ||
67 | 67 | % bigZ = b1^2 + b2^2 + 2*cd; | % bigZ = b1^2 + b2^2 + 2*cd; |
68 | 68 | % bigD = 1/16 - (b1^2)/4 - (b2^2)/4 + b1*b2*tc - cd/2 - b1*b2*d^2 + cd^2; | % bigD = 1/16 - (b1^2)/4 - (b2^2)/4 + b1*b2*tc - cd/2 - b1*b2*d^2 + cd^2; |
69 | % | ||
69 | % | ||
70 | 70 | % a2 = ((b1*c - b2*d)*(b1*d - b2*c) + cd*bigZ)*(detV + 1/16) - cd*detV - 2*((b1^2)*(b2^2) - cd^2)*bigD; | % a2 = ((b1*c - b2*d)*(b1*d - b2*c) + cd*bigZ)*(detV + 1/16) - cd*detV - 2*((b1^2)*(b2^2) - cd^2)*bigD; |
71 | % | ||
71 | % | ||
72 | 72 | % %% | % %% |
73 | 73 | % % scriptz = a^2+b^2+2*cp*cm; | % % scriptz = a^2+b^2+2*cp*cm; |
74 | 74 | % % detSF = (a^2)*(b^2)-a*b*cm^2-a*b*cp^2+(cm^2)*(cp^2); | % % detSF = (a^2)*(b^2)-a*b*cm^2-a*b*cp^2+(cm^2)*(cp^2); |
75 | % % | ||
75 | % % | ||
76 | 76 | % % scriptd = a^2*(-(1/4)+b^2)-a*b*(cm^2+cp^2)+ (1/16)*(-4*b^2+(1 - 4*cm*cp)^2); | % % scriptd = a^2*(-(1/4)+b^2)-a*b*(cm^2+cp^2)+ (1/16)*(-4*b^2+(1 - 4*cm*cp)^2); |
77 | 77 | % % scriptdtilda = detSF - (1/4)*(a^2 + b^2 +2*cp*abs(cm)) + 1/16; | % % scriptdtilda = detSF - (1/4)*(a^2 + b^2 +2*cp*abs(cm)) + 1/16; |
78 | % | ||
78 | % | ||
79 | 79 | % % a1 = -(cp*(a*b -cm^2) + abs(cm)/4)*((a-b)^2*(cp*(a*b -cm^2)+ abs(cm)/4)+2*a*b*(cp - abs(cm))*(a*b -cm^2 -1/4)); | % % a1 = -(cp*(a*b -cm^2) + abs(cm)/4)*((a-b)^2*(cp*(a*b -cm^2)+ abs(cm)/4)+2*a*b*(cp - abs(cm))*(a*b -cm^2 -1/4)); |
80 | 80 | % % a2 = ((a*cp - b*abs(cm))*(a*abs(cm) - b*cp) + cp*abs(cm)*scriptz)*(detSF+1/16)-2*((a^2)*(b^2) - (cp^2)*(cm^2))*scriptz - cp*abs(cm)*detSF; | % % a2 = ((a*cp - b*abs(cm))*(a*abs(cm) - b*cp) + cp*abs(cm)*scriptz)*(detSF+1/16)-2*((a^2)*(b^2) - (cp^2)*(cm^2))*scriptz - cp*abs(cm)*detSF; |
81 | 81 | % % a3 = (-(cp/4)-(a*b-cp^2)*abs(cm))*(2*a*b*(-(1/4)+a*b-cp^2)*(-cp+abs(cm))+((a-b)^2)*(cp/4+(a*b-cp^2)*abs(cm))); | % % a3 = (-(cp/4)-(a*b-cp^2)*abs(cm))*(2*a*b*(-(1/4)+a*b-cp^2)*(-cp+abs(cm))+((a-b)^2)*(cp/4+(a*b-cp^2)*abs(cm))); |
82 | 82 | % % a4 = (a*b-cp^2)*(-(b/4)+a*(a*b-cp^2))*(-(a/4)+b*(a*b-cp^2)); | % % a4 = (a*b-cp^2)*(-(b/4)+a*(a*b-cp^2))*(-(a/4)+b*(a*b-cp^2)); |
83 | % | ||
83 | % | ||
84 | 84 | % %% | % %% |
85 | 85 | % aCoeffs = [a4 a3 a2 a1 a0]; | % aCoeffs = [a4 a3 a2 a1 a0]; |
86 | 86 | % polyval(aCoeffs,1) %MUST BE NEGATIVE ACCORDING TO MARIAN AND MARIAN!!! | % polyval(aCoeffs,1) %MUST BE NEGATIVE ACCORDING TO MARIAN AND MARIAN!!! |
87 | % | ||
87 | % | ||
88 | 88 | % pCandidates = roots(aCoeffs); | % pCandidates = roots(aCoeffs); |
89 | 89 | % pm = max(pCandidates(~imag(pCandidates))); %choose maximum within real roots | % pm = max(pCandidates(~imag(pCandidates))); %choose maximum within real roots |
90 | % | ||
90 | % | ||
91 | 91 | % % If[pm<1,(*Print["No pm bigger than one. | % % If[pm<1,(*Print["No pm bigger than one. |
92 | 92 | % % Is the CM inseparable? Is it a two-mode-squeezed thermal state?"];*)0, | % % Is the CM inseparable? Is it a two-mode-squeezed thermal state?"];*)0, |
93 | % | ||
93 | % | ||
94 | 94 | % %% | % %% |
95 | 95 | % b0 = -scriptdtilda*pm; | % b0 = -scriptdtilda*pm; |
96 | 96 | % b1 = -2*sqrt(pm)*((abs(cm)*(a*b -cp^2) + cp/4)*pm + (cp*(a*b - cm^2) + abs(cm)/4)); | % b1 = -2*sqrt(pm)*((abs(cm)*(a*b -cp^2) + cp/4)*pm + (cp*(a*b - cm^2) + abs(cm)/4)); |
97 | 97 | % b2 = (a*b - cp^2)*pm^2 + scriptz*pm+(a*b -cm^2); | % b2 = (a*b - cp^2)*pm^2 + scriptz*pm+(a*b -cm^2); |
98 | % | ||
98 | % | ||
99 | 99 | % %% | % %% |
100 | 100 | % yCandidates = roots([b2 b1 b0]); | % yCandidates = roots([b2 b1 b0]); |
101 | 101 | % ym = min(yCandidates(~imag(yCandidates))); | % ym = min(yCandidates(~imag(yCandidates))); |
File misc/covmats/gausssfcm.m changed (mode: 100644) (index 85ff29a..620fbd8) | |||
... | ... | sfcm = [a, 0, cplus, 0;... | |
22 | 22 | cplus, 0, b, 0;... | cplus, 0, b, 0;... |
23 | 23 | 0, cminus, 0, b]; | 0, cminus, 0, b]; |
24 | 24 | end | end |
25 |
File misc/covmats/gausssfcm2.m changed (mode: 100644) (index 8f07eae..8e937c3) | |||
... | ... | sfcm = [n1, 0, c1, 0;... | |
25 | 25 | c1, 0, m1, 0;... | c1, 0, m1, 0;... |
26 | 26 | 0, c2, 0, m2]; | 0, c2, 0, m2]; |
27 | 27 | end | end |
28 |
File misc/covmats/gausssfparams.m changed (mode: 100644) (index a13866c..7ec8181) | |||
... | ... | if ~isreal(sfparams) | |
33 | 33 | end | end |
34 | 34 | ||
35 | 35 | end | end |
36 |
File misc/covmats/gausssfparams2.m changed (mode: 100644) (index 0e0fcf0..ae6a2f6) | |||
... | ... | m = sfparams1(2); | |
18 | 18 | c = sfparams1(3); | c = sfparams1(3); |
19 | 19 | cprime = sfparams1(4); | cprime = sfparams1(4); |
20 | 20 | ||
21 | %% calculate parameters for standard form 2 | ||
21 | %% calculate parameters for standard form 2 | ||
22 | 22 | if ( n == m )&& (abs(c) == abs(cprime)) | if ( n == m )&& (abs(c) == abs(cprime)) |
23 | r = [1, 1]; | ||
23 | r = [1, 1]; | ||
24 | 24 | else % solve the system described by auxfct1 | else % solve the system described by auxfct1 |
25 | 25 | r = fsolve(@auxfct1, [1, 1]); | r = fsolve(@auxfct1, [1, 1]); |
26 | 26 | end | end |
... | ... | function [x] = auxfct1(r) | |
29 | 29 | x(1) = ( n/r(1) - 1 )/(n*r(1) - 1) - (m/r(2) - 1)/(m*r(2) - 1); | x(1) = ( n/r(1) - 1 )/(n*r(1) - 1) - (m/r(2) - 1)/(m*r(2) - 1); |
30 | 30 | x(2) = sqrt(r(1)*r(2))*abs(c)-abs(cprime)/sqrt(r(1)*r(2)) - sqrt((n*r(1) - 1)*(m*r(2) - 1)) + sqrt((n/r(1) - 1)*(m/r(2) - 1)); | x(2) = sqrt(r(1)*r(2))*abs(c)-abs(cprime)/sqrt(r(1)*r(2)) - sqrt((n*r(1) - 1)*(m*r(2) - 1)) + sqrt((n/r(1) - 1)*(m/r(2) - 1)); |
31 | 31 | end | end |
32 | %% calculate parameters for standard form 2 | ||
32 | %% calculate parameters for standard form 2 | ||
33 | 33 | n1 = n*r(1); | n1 = n*r(1); |
34 | 34 | n2 = n/r(1); | n2 = n/r(1); |
35 | 35 | m1 = m*r(2); | m1 = m*r(2); |
File misc/covmats/isphyscov.m changed (mode: 100644) (index d3c189e..ce3e7f5) | |||
1 | 1 | function bool = isphyscov(mat,varargin) | function bool = isphyscov(mat,varargin) |
2 | 2 | % bool = isphyscov(M,...) | % bool = isphyscov(M,...) |
3 | % | ||
3 | % | ||
4 | 4 | % Test if M+I*Σ/2 ≥ 0, where Σ is | % Test if M+I*Σ/2 ≥ 0, where Σ is |
5 | 5 | % the symplectic matrix. | % the symplectic matrix. |
6 | 6 | % | % |
File misc/covmats/logneg.m changed (mode: 100644) (index 4fc07b0..b2bd46c) | |||
... | ... | function ln = logneg(cm, varargin) | |
16 | 16 | checkCMdimensions(cm, 'multimode'); | checkCMdimensions(cm, 'multimode'); |
17 | 17 | modeindices_unspecified = true; | modeindices_unspecified = true; |
18 | 18 | for k=1:2:length(varargin) | for k=1:2:length(varargin) |
19 | switch varargin{k} | ||
20 | case 'modeindices' | ||
21 | modeindices = varargin{k+1}; | ||
19 | switch varargin{k} | ||
20 | case 'modeindices' | ||
21 | modeindices = varargin{k+1}; | ||
22 | 22 | modeindices_unspecified = false; | modeindices_unspecified = false; |
23 | otherwise | ||
24 | error('Unrecognized varargin-input.') | ||
25 | end | ||
23 | otherwise | ||
24 | error('Unrecognized varargin-input.') | ||
25 | end | ||
26 | 26 | end | end |
27 | 27 | ||
28 | 28 | mode_no = length(cm)/2; | mode_no = length(cm)/2; |
29 | 29 | if mode_no==2 | if mode_no==2 |
30 | % for definition of logarithmic negativity see | ||
31 | % Adesso & Illuminati, doi:10.1088/1751-8113/40/28/S01, eq. (80) | ||
30 | % for definition of logarithmic negativity see | ||
31 | % Adesso & Illuminati, doi:10.1088/1751-8113/40/28/S01, eq. (80) | ||
32 | 32 | ||
33 | d = det(cm(1:2,1:2)) + det(cm(3:4,3:4)) - 2*det(cm(1:2,3:4)); | ||
34 | m = 1/sqrt(det(cm)); | ||
35 | % corrected by a factor of 2 due to commutation relations | ||
36 | ln = -log(sqrt(d-sqrt(d^2-4/m^2))/sqrt(2)*2); | ||
33 | d = det(cm(1:2,1:2)) + det(cm(3:4,3:4)) - 2*det(cm(1:2,3:4)); | ||
34 | m = 1/sqrt(det(cm)); | ||
35 | % corrected by a factor of 2 due to commutation relations | ||
36 | ln = -log(sqrt(d-sqrt(d^2-4/m^2))/sqrt(2)*2); | ||
37 | 37 | ||
38 | 38 | elseif mode_no>2 | elseif mode_no>2 |
39 | 39 | % for definition of logarithmic negativity see | % for definition of logarithmic negativity see |
40 | % Adesso & Illuminati, doi:10.1088/1751-8113/40/28/S01, eq. (68) | ||
40 | % Adesso & Illuminati, doi:10.1088/1751-8113/40/28/S01, eq. (68) | ||
41 | 41 | if modeindices_unspecified | if modeindices_unspecified |
42 | 42 | if mod(mode_no,2)==0 | if mod(mode_no,2)==0 |
43 | 43 | %default choice for even no of modes: split symmetrically | %default choice for even no of modes: split symmetrically |
... | ... | elseif mode_no>2 | |
49 | 49 | end | end |
50 | 50 | end | end |
51 | 51 | ||
52 | sympevalvec = symevals(partialtranspose(cm, modeindices)); | ||
52 | sympevalvec = symevals(partialtranspose(cm, modeindices)); | ||
53 | 53 | ||
54 | 54 | negativeSympEvals = sympevalvec(sympevalvec<0.5); | negativeSympEvals = sympevalvec(sympevalvec<0.5); |
55 | 55 | if ~isempty(negativeSympEvals) | if ~isempty(negativeSympEvals) |
... | ... | elseif mode_no>2 | |
58 | 58 | % NOTE: if all symplectic eigenvalues are larger than 0.5, we have an AMBIGUITY (in the multimode case) | % NOTE: if all symplectic eigenvalues are larger than 0.5, we have an AMBIGUITY (in the multimode case) |
59 | 59 | % * do we take only the smallest symplectic eigenvalue? | % * do we take only the smallest symplectic eigenvalue? |
60 | 60 | % * or do we sum over a certain subset or all symplectic eigenvalues? | % * or do we sum over a certain subset or all symplectic eigenvalues? |
61 | % Whether we see curves of log.neg. vs other parameters which are continuous across 0 | ||
61 | % Whether we see curves of log.neg. vs other parameters which are continuous across 0 | ||
62 | 62 | % or not depends on this arbitrary choice! | % or not depends on this arbitrary choice! |
63 | 63 | % We choose to take only the smallest symplectic eigenvalue into account | % We choose to take only the smallest symplectic eigenvalue into account |
64 | 64 | % since in our application most of the times at most one symplectic eigenvalue is below 0.5 | % since in our application most of the times at most one symplectic eigenvalue is below 0.5 |
File misc/covmats/logneg_test.m changed (mode: 100644) (index ce07591..d18cb7a) | |||
1 | 1 | function test_suite = logneg_test %#ok<STOUT> | function test_suite = logneg_test %#ok<STOUT> |
2 | initTestSuite; | ||
2 | initTestSuite; | ||
3 | 3 | ||
4 | 4 | % test cases: | % test cases: |
5 | 5 | % - vacuum state: | % - vacuum state: |
... | ... | function twomode_tmss_test | |
22 | 22 | % r=.5; tmssOnModes1and3 = combineCMs(tmss(r),[1,3]); logneg(tmssOnModes1and3 , 'modeindices', [1]) % equals 2*r | % r=.5; tmssOnModes1and3 = combineCMs(tmss(r),[1,3]); logneg(tmssOnModes1and3 , 'modeindices', [1]) % equals 2*r |
23 | 23 | ||
24 | 24 | function multimode_vac_test | function multimode_vac_test |
25 | N = 8; | ||
25 | N = 8; | ||
26 | 26 | vac = eye(2*N)/2; | vac = eye(2*N)/2; |
27 | assertEqual(logneg(vac, 'modeindices', [1, 2]), 0) | ||
28 | assertEqual(logneg(vac, 'modeindices', [1, 2, 3, 4]), 0) | ||
29 | assertEqual(logneg(vac), 0) | ||
30 | assertEqual(logneg(eye(2*3)/2), 0) | ||
27 | assertEqual(logneg(vac, 'modeindices', [1, 2]), 0) | ||
28 | assertEqual(logneg(vac, 'modeindices', [1, 2, 3, 4]), 0) | ||
29 | assertEqual(logneg(vac), 0) | ||
30 | assertEqual(logneg(eye(2*3)/2), 0) | ||
31 | 31 | ||
32 | 32 | function multimode_tmss_test | function multimode_tmss_test |
33 | 33 | r = 1; | r = 1; |
34 | tmssOnModes1and4 = combineCMs(tmss(r),[1,4]); | ||
34 | tmssOnModes1and4 = combineCMs(tmss(r),[1,4]); | ||
35 | 35 | assertAlmostEqual(logneg(tmssOnModes1and4 , 'modeindices', [1]), 2*r) | assertAlmostEqual(logneg(tmssOnModes1and4 , 'modeindices', [1]), 2*r) |
36 | assertAlmostEqual(logneg(tmssOnModes1and4 , 'modeindices', [1, 2]), 2*r) | ||
37 | %% check equality for different, but equivalent ways of specifying the partition | ||
38 | assertEqual(logneg(tmssOnModes1and4 , 'modeindices', [1, 2]),... | ||
39 | logneg(tmssOnModes1and4 , 'modeindices', [3, 4])) | ||
40 | assertEqual(logneg(tmssOnModes1and4 , 'modeindices', [1, 2]),... | ||
41 | logneg(tmssOnModes1and4)) | ||
36 | assertAlmostEqual(logneg(tmssOnModes1and4 , 'modeindices', [1, 2]), 2*r) | ||
37 | %% check equality for different, but equivalent ways of specifying the partition | ||
38 | assertEqual(logneg(tmssOnModes1and4 , 'modeindices', [1, 2]),... | ||
39 | logneg(tmssOnModes1and4 , 'modeindices', [3, 4])) | ||
40 | assertEqual(logneg(tmssOnModes1and4 , 'modeindices', [1, 2]),... | ||
41 | logneg(tmssOnModes1and4)) |
File misc/covmats/ptSymEvals.m changed (mode: 100644) (index 5014c0a..6200cd3) | |||
... | ... | function [ptSympEvals] = ptSymEvals( cm, modeIndices) | |
7 | 7 | ptSympEvals = symevals(partialtranspose(cm, modeIndices)); | ptSympEvals = symevals(partialtranspose(cm, modeIndices)); |
8 | 8 | ||
9 | 9 | end | end |
10 |
File misc/covmats/purity_test.m changed (mode: 100644) (index 2d7953e..8785a23) | |||
1 | 1 | function test_suite = purity_test %#ok<STOUT> | function test_suite = purity_test %#ok<STOUT> |
2 | initTestSuite; | ||
2 | initTestSuite; | ||
3 | 3 | ||
4 | 4 | function smss_test | function smss_test |
5 | 5 | r = 5; | r = 5; |
File misc/covmats/quadIndicesFromModeIndices.m changed (mode: 100644) (index a5566d1..7f52fd4) | |||
... | ... | function quadIndices = quadIndicesFromModeIndices(modeIndices) | |
5 | 5 | qIndices = pIndices - 1; | qIndices = pIndices - 1; |
6 | 6 | quadIndices = sort([pIndices, qIndices]); | quadIndices = sort([pIndices, qIndices]); |
7 | 7 | end | end |
8 |
File misc/covmats/smss.m changed (mode: 100644) (index 591950d..20a94b3) | |||
... | ... | s = sinh(2*r); | |
10 | 10 | cm = (1/2)*[c, s; | cm = (1/2)*[c, s; |
11 | 11 | s, c]; | s, c]; |
12 | 12 | end | end |
13 |
File misc/covmats/states_test.m changed (mode: 100644) (index 6260690..892c30e) | |||
1 | 1 | function test_suite = states_test %#ok<STOUT> | function test_suite = states_test %#ok<STOUT> |
2 | initTestSuite; | ||
2 | initTestSuite; | ||
3 | 3 | ||
4 | 4 | function smss_vac_test | function smss_vac_test |
5 | 5 | vac = eye(2)/2; | vac = eye(2)/2; |
File misc/covmats/symevals.m changed (mode: 100644) (index 0c54671..4feb215) | |||
... | ... | function symevalvector = symevals(cm) | |
2 | 2 | % symevalvector = symevals(cm) takes a covariance matrix and returns the vector of symplectic eigenvalues | % symevalvector = symevals(cm) takes a covariance matrix and returns the vector of symplectic eigenvalues |
3 | 3 | N = length(cm); | N = length(cm); |
4 | 4 | assert(N>2&&mod(N,2)==0&&all(size(cm)==[N,N]),... | assert(N>2&&mod(N,2)==0&&all(size(cm)==[N,N]),... |
5 | 'Expecting NxN covariance matrix with N>2'); | ||
5 | 'Expecting NxN covariance matrix with N>2'); | ||
6 | 6 | ||
7 | 7 | symevalvector = sort(abs(eig(complex(0,1)*symform(N)*cm))); | symevalvector = sort(abs(eig(complex(0,1)*symform(N)*cm))); |
8 | 8 | % for definition of symplectic eigenvalues see | % for definition of symplectic eigenvalues see |
File misc/covmats/test_symplectic_functions.m changed (mode: 100644) (index 8ee4f0e..29572d1) | |||
1 | 1 | function test_symplectic_functions( cm ) | function test_symplectic_functions( cm ) |
2 | % test_symplectic_functions( cm ) takes a cm, | ||
2 | % test_symplectic_functions( cm ) takes a cm, | ||
3 | 3 | % performs a number of symplectic operations on them | % performs a number of symplectic operations on them |
4 | 4 | % and pretty-prints the results. | % and pretty-prints the results. |
5 | 5 | % | % |
6 | % This can be used to test the implementation of the | ||
6 | % This can be used to test the implementation of the | ||
7 | 7 | % functions operating on covariance matrices. | % functions operating on covariance matrices. |
8 | 8 | % | % |
9 | test_symplectic_functions2(cm); | ||
10 | |||
11 | input('Continue? [Enter to confirm]') | ||
12 | disp([10,'Second round for the matrix obtained by mixing mode 2 of your input ',... | ||
13 | 'with the single-mode vacuum on a 50:50 beam splitter.',10]) | ||
14 | disp('The beam splitter matrix:') | ||
15 | bs = blkdiag(eye(2),beam_splitter(sqrt(0.5))); | ||
16 | disp(bs) | ||
17 | cm_bs = bs*blkdiag(cm, diag([0.5,0.5]))*bs'; | ||
18 | test_symplectic_functions2(cm_bs); | ||
19 | |||
20 | input('Continue? [Enter to confirm]') | ||
21 | disp([10,'Third round for the matrix obtained by tracing out all but mode 1 of your CM ',10]) | ||
22 | cm_1 = traceOutCM(cm, [1]); | ||
23 | test_symplectic_functions2(cm_1); | ||
9 | test_symplectic_functions2(cm); | ||
10 | |||
11 | input('Continue? [Enter to confirm]') | ||
12 | disp([10,'Second round for the matrix obtained by mixing mode 2 of your input ',... | ||
13 | 'with the single-mode vacuum on a 50:50 beam splitter.',10]) | ||
14 | disp('The beam splitter matrix:') | ||
15 | bs = blkdiag(eye(2),beam_splitter(sqrt(0.5))); | ||
16 | disp(bs) | ||
17 | cm_bs = bs*blkdiag(cm, diag([0.5,0.5]))*bs'; | ||
18 | test_symplectic_functions2(cm_bs); | ||
19 | |||
20 | input('Continue? [Enter to confirm]') | ||
21 | disp([10,'Third round for the matrix obtained by tracing out all but mode 1 of your CM ',10]) | ||
22 | cm_1 = traceOutCM(cm, [1]); | ||
23 | test_symplectic_functions2(cm_1); | ||
24 | 24 | ||
25 | 25 | end | end |
26 | 26 | ||
27 | 27 | ||
28 | %% test_symplectic_functions2: the actual function | ||
28 | %% test_symplectic_functions2: the actual function | ||
29 | 29 | %(can be called with several inputs from main function) | %(can be called with several inputs from main function) |
30 | 30 | function test_symplectic_functions2(cm) | function test_symplectic_functions2(cm) |
31 | home | ||
32 | mode_no = length(cm)/2; | ||
31 | home | ||
32 | mode_no = length(cm)/2; | ||
33 | 33 | ||
34 | disp([10,'***********************************',10,... | ||
35 | 'MUT (matrix under test):']) | ||
36 | disp(cm) | ||
34 | disp([10,'***********************************',10,... | ||
35 | 'MUT (matrix under test):']) | ||
36 | disp(cm) | ||
37 | 37 | ||
38 | disp('is physical?') | ||
39 | disp(isphyscov(cm)) | ||
38 | disp('is physical?') | ||
39 | disp(isphyscov(cm)) | ||
40 | 40 | ||
41 | disp([10,'Symplectic eigenvalues:']) | ||
42 | se = symp_evals(cm); | ||
43 | disp(se') | ||
41 | disp([10,'Symplectic eigenvalues:']) | ||
42 | se = symp_evals(cm); | ||
43 | disp(se') | ||
44 | 44 | ||
45 | disp([10,'Williamson normal form:']) | ||
46 | wf = williamson_form(cm); | ||
47 | disp(wf) | ||
45 | disp([10,'Williamson normal form:']) | ||
46 | wf = williamson_form(cm); | ||
47 | disp(wf) | ||
48 | 48 | ||
49 | disp([10,'Williamson diagonalizing matrix wd:']) | ||
50 | wd = williamson_diagonalization(cm); | ||
51 | disp(wd) | ||
49 | disp([10,'Williamson diagonalizing matrix wd:']) | ||
50 | wd = williamson_diagonalization(cm); | ||
51 | disp(wd) | ||
52 | 52 | ||
53 | disp([10,'symplecticity check: wd*symplForm*wd''']) | ||
54 | disp(wd*symplectic_form(mode_no)*wd') | ||
53 | disp([10,'symplecticity check: wd*symplForm*wd''']) | ||
54 | disp(wd*symplectic_form(mode_no)*wd') | ||
55 | 55 | ||
56 | disp([10,'wd*cm*wd''']) | ||
57 | disp(wd*cm*wd') | ||
56 | disp([10,'wd*cm*wd''']) | ||
57 | disp(wd*cm*wd') | ||
58 | 58 | end | end |
59 |
File misc/covmats/tmss.m changed (mode: 100644) (index d010640..313a0dc) | |||
... | ... | cm = (1/2)*[c, 0, s, 0;... | |
12 | 12 | s, 0, c, 0;... | s, 0, c, 0;... |
13 | 13 | 0, -s, 0, c]; | 0, -s, 0, c]; |
14 | 14 | end | end |
15 |
File misc/covmats/traceOutCM_test.m changed (mode: 100644) (index 2134c10..91068c9) | |||
1 | 1 | function test_suite = traceOutCM_test %#ok<STOUT> | function test_suite = traceOutCM_test %#ok<STOUT> |
2 | initTestSuite; | ||
2 | initTestSuite; | ||
3 | 3 | ||
4 | 4 | function single_remaining_mode_test | function single_remaining_mode_test |
5 | 5 | CMfull = magic(8); | CMfull = magic(8); |
File misc/covmats/wigner.m changed (mode: 100644) (index 26df61e..292e489) | |||
1 | 1 | function wrf = wigner(Xpos,X,CM) | function wrf = wigner(Xpos,X,CM) |
2 | 2 | % wrf = wigner(X,X0,CM) | % wrf = wigner(X,X0,CM) |
3 | % | ||
3 | % | ||
4 | 4 | % Wigner function for a Gaussian state at position X with given mean | % Wigner function for a Gaussian state at position X with given mean |
5 | 5 | % X0 and covariance matrix CM. X and X0 must be row vectors, e.g., | % X0 and covariance matrix CM. X and X0 must be row vectors, e.g., |
6 | 6 | % X=(x1,y1,x2,y2). | % X=(x1,y1,x2,y2). |
7 | |||
7 | |||
8 | 8 | % See e.g. Olivares, arXiv:1111.0786v2, eq. 13 | % See e.g. Olivares, arXiv:1111.0786v2, eq. 13 |
9 | 9 | ||
10 | 10 | %% test for proper dimensions | %% test for proper dimensions |
11 | if size(Xpos,1)~=size(X,1) || size(CM,1)~=size(CM,2) || size(CM,1)~=size(X,1) | ||
11 | if size(Xpos,1)~=size(X,1) || size(CM,1)~=size(CM,2) || size(CM,1)~=size(X,1) | ||
12 | 12 | error('State dimensions are not consistent'); | error('State dimensions are not consistent'); |
13 | 13 | end | end |
14 | 14 |
File misc/covmats/williamson_diagonalization.m changed (mode: 100644) (index 8fb085b..dbc5eb6) | |||
... | ... | root_W = diag(sqrt(sym_spectrum)); | |
47 | 47 | ||
48 | 48 | % (5) Compute R=Gamma*U^† | % (5) Compute R=Gamma*U^† |
49 | 49 | Gamma = (1/sqrt(2))*kron(eye(mode_no),... | Gamma = (1/sqrt(2))*kron(eye(mode_no),... |
50 | [sqrt(-1), -sqrt(-1);... | ||
51 | 1, 1]); | ||
50 | [sqrt(-1), -sqrt(-1);... | ||
51 | 1, 1]); | ||
52 | 52 | R = Gamma*eig_vecs_X.'; | R = Gamma*eig_vecs_X.'; |
53 | 53 | ||
54 | 54 | % (6) Compute diagonalizing_mat = W^1/2 * R * V^−1/2 | % (6) Compute diagonalizing_mat = W^1/2 * R * V^−1/2 |
File misc/covmats/williamson_test.m changed (mode: 100644) (index 52fa376..46abd9a) | |||
1 | 1 | function test_suite = williamson_test %#ok<STOUT> | function test_suite = williamson_test %#ok<STOUT> |
2 | initTestSuite; | ||
2 | initTestSuite; | ||
3 | 3 | ||
4 | 4 | function smss_test | function smss_test |
5 | 5 | cm = smss(2); | cm = smss(2); |
File misc/covupdate.m changed (mode: 100644) (index 744bbf6..a854c02) | |||
1 | 1 | function cov = covupdate(m1,c1,N1,m2,c2,N2) | function cov = covupdate(m1,c1,N1,m2,c2,N2) |
2 | 2 | % cov = covupdate(mean_1,cov_1,N_1,mean_2,cov_2,N_2) | % cov = covupdate(mean_1,cov_1,N_1,mean_2,cov_2,N_2) |
3 | % | ||
3 | % | ||
4 | 4 | % Calculate update covariance matrix from two samples of same | % Calculate update covariance matrix from two samples of same |
5 | 5 | % distribution, where mean mean_i, cov_i and N_i are the mean, | % distribution, where mean mean_i, cov_i and N_i are the mean, |
6 | 6 | % covariance and sample size of each sample respectively. mean_i can | % covariance and sample size of each sample respectively. mean_i can |
File misc/dfilt2ess.m changed (mode: 100644) (index 09ded92..b9ed1e4) | |||
... | ... | function esm=dfilt2ess(Hd,h) | |
2 | 2 | % esm=dfilt2ess(Hd,h) | % esm=dfilt2ess(Hd,h) |
3 | 3 | % | % |
4 | 4 | % Converts Hd object to ess object, h time step | % Converts Hd object to ess object, h time step |
5 | % | ||
5 | % | ||
6 | 6 | % uses convert for conversion (accepts many filter implementations) | % uses convert for conversion (accepts many filter implementations) |
7 | 7 | ||
8 | 8 |
File misc/filtervarargs.m changed (mode: 100644) (index ab0ff40..5be3fc6) | |||
... | ... | function argsin = filtervarargs(argsin,filtnames) | |
6 | 6 | ||
7 | 7 | for ii = 1:numel(filtnames) | for ii = 1:numel(filtnames) |
8 | 8 | % key/value pair has to be filtered = | % key/value pair has to be filtered = |
9 | % delete two consecutive positiions | ||
9 | % delete two consecutive positiions | ||
10 | 10 | idx = strcmp(filtnames{ii},argsin); % find occurence | idx = strcmp(filtnames{ii},argsin); % find occurence |
11 | 11 | idx = circshift(idx,[0,1]) | idx; % create mask | idx = circshift(idx,[0,1]) | idx; % create mask |
12 | 12 | argsin(idx) = []; % delete elements | argsin(idx) = []; % delete elements |
File misc/gui/boundedline.m changed (mode: 100644) (index 3fd9f6c..a088e9c) | |||
... | ... | function varargout = boundedline(varargin) | |
47 | 47 | % 0.2. | % 0.2. |
48 | 48 | % | % |
49 | 49 | % orient: 'vert': add bounds in vertical (y) direction (default) | % orient: 'vert': add bounds in vertical (y) direction (default) |
50 | % 'horiz': add bounds in horizontal (x) direction | ||
50 | % 'horiz': add bounds in horizontal (x) direction | ||
51 | 51 | % | % |
52 | 52 | % cmap: n x 3 colormap array. If included, lines will be colored | % cmap: n x 3 colormap array. If included, lines will be colored |
53 | 53 | % (in order of plotting) according to this colormap, | % (in order of plotting) according to this colormap, |
54 | % overriding any linespec or default colors. | ||
54 | % overriding any linespec or default colors. | ||
55 | 55 | % | % |
56 | 56 | % Output variables: | % Output variables: |
57 | 57 | % | % |
... | ... | function varargout = boundedline(varargin) | |
66 | 66 | % y2 = cos(x); | % y2 = cos(x); |
67 | 67 | % e1 = rand(size(y1))*.5+.5; | % e1 = rand(size(y1))*.5+.5; |
68 | 68 | % e2 = [.25 .5]; | % e2 = [.25 .5]; |
69 | % | ||
69 | % | ||
70 | 70 | % ax(1) = subplot(2,2,1); | % ax(1) = subplot(2,2,1); |
71 | 71 | % [l,p] = boundedline(x, y1, e1, '-b*', x, y2, e2, '--ro'); | % [l,p] = boundedline(x, y1, e1, '-b*', x, y2, e2, '--ro'); |
72 | 72 | % outlinebounds(l,p); | % outlinebounds(l,p); |
73 | 73 | % title('Opaque bounds, with outline'); | % title('Opaque bounds, with outline'); |
74 | % | ||
74 | % | ||
75 | 75 | % ax(2) = subplot(2,2,2); | % ax(2) = subplot(2,2,2); |
76 | 76 | % boundedline(x, [y1;y2], rand(length(y1),2,2)*.5+.5, 'alpha'); | % boundedline(x, [y1;y2], rand(length(y1),2,2)*.5+.5, 'alpha'); |
77 | 77 | % title('Transparent bounds'); | % title('Transparent bounds'); |
78 | % | ||
78 | % | ||
79 | 79 | % ax(3) = subplot(2,2,3); | % ax(3) = subplot(2,2,3); |
80 | 80 | % boundedline([y1;y2], x, e1(1), 'orientation', 'horiz') | % boundedline([y1;y2], x, e1(1), 'orientation', 'horiz') |
81 | 81 | % title('Horizontal bounds'); | % title('Horizontal bounds'); |
82 | % | ||
82 | % | ||
83 | 83 | % ax(4) = subplot(2,2,4); | % ax(4) = subplot(2,2,4); |
84 | 84 | % boundedline(x, repmat(y1, 4,1), permute(0.5:-0.1:0.2, [3 1 2]), ... | % boundedline(x, repmat(y1, 4,1), permute(0.5:-0.1:0.2, [3 1 2]), ... |
85 | 85 | % 'cmap', cool(4), 'transparency', 0.5); | % 'cmap', cool(4), 'transparency', 0.5); |
... | ... | while ~isempty(varargin) | |
166 | 166 | varargin(1) = []; | varargin(1) = []; |
167 | 167 | else | else |
168 | 168 | linespec = [linespec {[]}]; | linespec = [linespec {[]}]; |
169 | end | ||
170 | end | ||
169 | end | ||
170 | end | ||
171 | 171 | ||
172 | 172 | %-------------------- | %-------------------- |
173 | 173 | % Reformat x and y | % Reformat x and y |
... | ... | plotdata = cell(0,7); | |
181 | 181 | ||
182 | 182 | htemp = figure('visible', 'off'); | htemp = figure('visible', 'off'); |
183 | 183 | for ix = 1:length(x) | for ix = 1:length(x) |
184 | |||
184 | |||
185 | 185 | % Get full x, y, and linespec data for each line (easier to let plot | % Get full x, y, and linespec data for each line (easier to let plot |
186 | 186 | % check for properly-sized x and y and expand values than to try to do | % check for properly-sized x and y and expand values than to try to do |
187 | % it myself) | ||
188 | |||
187 | % it myself) | ||
188 | |||
189 | 189 | try | try |
190 | 190 | if isempty(linespec{ix}) | if isempty(linespec{ix}) |
191 | 191 | hltemp = plot(x{ix}, y{ix}); | hltemp = plot(x{ix}, y{ix}); |
... | ... | for ix = 1:length(x) | |
196 | 196 | close(htemp); | close(htemp); |
197 | 197 | error('X and Y matrices and/or linespec not appropriate for line plot'); | error('X and Y matrices and/or linespec not appropriate for line plot'); |
198 | 198 | end | end |
199 | |||
199 | |||
200 | 200 | linedata = get(hltemp, {'xdata', 'ydata', 'marker', 'linestyle', 'color'}); | linedata = get(hltemp, {'xdata', 'ydata', 'marker', 'linestyle', 'color'}); |
201 | |||
201 | |||
202 | 202 | nline = size(linedata,1); | nline = size(linedata,1); |
203 | |||
203 | |||
204 | 204 | % Expand bounds matrix if necessary | % Expand bounds matrix if necessary |
205 | |||
205 | |||
206 | 206 | if nline > 1 | if nline > 1 |
207 | 207 | if ndims(err{ix}) == 3 | if ndims(err{ix}) == 3 |
208 | 208 | err2 = squeeze(num2cell(err{ix},[1 2])); | err2 = squeeze(num2cell(err{ix},[1 2])); |
... | ... | for ix = 1:length(x) | |
212 | 212 | else | else |
213 | 213 | err2 = err(ix); | err2 = err(ix); |
214 | 214 | end | end |
215 | |||
215 | |||
216 | 216 | % Figure out upper and lower bounds | % Figure out upper and lower bounds |
217 | |||
217 | |||
218 | 218 | [lo, hi] = deal(cell(nline,1)); | [lo, hi] = deal(cell(nline,1)); |
219 | 219 | for iln = 1:nline | for iln = 1:nline |
220 | |||
220 | |||
221 | 221 | x2 = linedata{iln,1}; | x2 = linedata{iln,1}; |
222 | 222 | y2 = linedata{iln,2}; | y2 = linedata{iln,2}; |
223 | 223 | nx = length(x2); | nx = length(x2); |
224 | |||
224 | |||
225 | 225 | if isvert | if isvert |
226 | 226 | lineval = y2; | lineval = y2; |
227 | 227 | else | else |
228 | 228 | lineval = x2; | lineval = x2; |
229 | 229 | end | end |
230 | |||
230 | |||
231 | 231 | sz = size(err2{iln}); | sz = size(err2{iln}); |
232 | |||
232 | |||
233 | 233 | if isequal(sz, [nx 2]) | if isequal(sz, [nx 2]) |
234 | 234 | lo{iln} = lineval - err2{iln}(:,1)'; | lo{iln} = lineval - err2{iln}(:,1)'; |
235 | 235 | hi{iln} = lineval + err2{iln}(:,2)'; | hi{iln} = lineval + err2{iln}(:,2)'; |
... | ... | for ix = 1:length(x) | |
253 | 253 | hi{iln} = lineval + err2{iln}(2); | hi{iln} = lineval + err2{iln}(2); |
254 | 254 | else | else |
255 | 255 | error('Error bounds must be npt x nside x nline array'); | error('Error bounds must be npt x nside x nline array'); |
256 | end | ||
257 | |||
256 | end | ||
257 | |||
258 | 258 | end | end |
259 | |||
259 | |||
260 | 260 | % Combine all data (xline, yline, marker, linestyle, color, lower bound | % Combine all data (xline, yline, marker, linestyle, color, lower bound |
261 | % (x or y), upper bound (x or y) | ||
262 | |||
261 | % (x or y), upper bound (x or y) | ||
262 | |||
263 | 263 | plotdata = [plotdata; linedata lo hi]; | plotdata = [plotdata; linedata lo hi]; |
264 | |||
264 | |||
265 | 265 | end | end |
266 | 266 | close(htemp); | close(htemp); |
267 | 267 | ||
... | ... | for iln = 1:nline | |
294 | 294 | % xp{iln} = [plotdata{iln,6} fliplr(plotdata{iln,7})]; | % xp{iln} = [plotdata{iln,6} fliplr(plotdata{iln,7})]; |
295 | 295 | % yp{iln} = [plotdata{iln,2} fliplr(plotdata{iln,2})]; | % yp{iln} = [plotdata{iln,2} fliplr(plotdata{iln,2})]; |
296 | 296 | % end | % end |
297 | |||
297 | |||
298 | 298 | [xp{iln}, yp{iln}] = calcpatch(plotdata{iln,1}, plotdata{iln,2}, isvert, plotdata{iln,6}, plotdata{iln,7}); | [xp{iln}, yp{iln}] = calcpatch(plotdata{iln,1}, plotdata{iln,2}, isvert, plotdata{iln,6}, plotdata{iln,7}); |
299 | |||
299 | |||
300 | 300 | marker{iln} = plotdata{iln,3}; | marker{iln} = plotdata{iln,3}; |
301 | 301 | lnsty{iln} = plotdata{iln,4}; | lnsty{iln} = plotdata{iln,4}; |
302 | |||
302 | |||
303 | 303 | if usealpha | if usealpha |
304 | 304 | lncol{iln} = plotdata{iln,5}; | lncol{iln} = plotdata{iln,5}; |
305 | 305 | ptchcol{iln} = plotdata{iln,5}; | ptchcol{iln} = plotdata{iln,5}; |
... | ... | for iln = 1:nline | |
310 | 310 | alpha{iln} = 1; | alpha{iln} = 1; |
311 | 311 | end | end |
312 | 312 | end | end |
313 | |||
313 | |||
314 | 314 | % Plot patches and lines | % Plot patches and lines |
315 | 315 | ||
316 | 316 | [hp,hl] = deal(zeros(nline,1)); | [hp,hl] = deal(zeros(nline,1)); |
... | ... | if nargout == 2 | |
341 | 341 | end | end |
342 | 342 | ||
343 | 343 | %-------------------- | %-------------------- |
344 | % Parse optional | ||
344 | % Parse optional | ||
345 | 345 | % parameters | % parameters |
346 | 346 | %-------------------- | %-------------------- |
347 | 347 | ||
... | ... | function [xp, yp] = calcpatch(xl, yl, isvert, lo, hi) | |
371 | 371 | ||
372 | 372 | ismissing = any(isnan([xl;yl;lo;hi]),2); | ismissing = any(isnan([xl;yl;lo;hi]),2); |
373 | 373 | if any(ismissing) | if any(ismissing) |
374 | |||
374 | |||
375 | 375 | else | else |
376 | 376 | if isvert | if isvert |
377 | 377 | xp = [xl fliplr(xl)]; | xp = [xl fliplr(xl)]; |
... | ... | else | |
381 | 381 | yp = [yl fliplr(yl)]; | yp = [yl fliplr(yl)]; |
382 | 382 | end | end |
383 | 383 | end | end |
384 | |||
385 |
File misc/io/io_test.m changed (mode: 100644) (index 872775e..f485b7a) | |||
1 | 1 | function test_suite = io_test %#ok<STOUT> | function test_suite = io_test %#ok<STOUT> |
2 | initTestSuite; | ||
2 | initTestSuite; | ||
3 | 3 | ||
4 | 4 | function shared = setup | function shared = setup |
5 | shared.startstr = '.__test'; | ||
6 | shared.endstr = '__.datshared.'; | ||
7 | shared.file1 = [shared.startstr, '1', shared.endstr]; | ||
8 | shared.file2 = [shared.startstr, '2', shared.endstr]; | ||
9 | %shared.data1 = [1,2,3]; | ||
10 | shared.data1 = randn(2e6,1); | ||
11 | shared.precision1 = 'double'; | ||
12 | shared.data2 = [1,2,3, 4]; | ||
13 | shared.precision2 = 'single'; | ||
14 | fid1 = fopen(shared.file1, 'w'); | ||
15 | fid2 = fopen(shared.file2, 'w'); | ||
16 | fwrite(fid1, shared.data1, shared.precision1); | ||
17 | fwrite(fid2, shared.data2, shared.precision2); | ||
5 | shared.startstr = '.__test'; | ||
6 | shared.endstr = '__.datshared.'; | ||
7 | shared.file1 = [shared.startstr, '1', shared.endstr]; | ||
8 | shared.file2 = [shared.startstr, '2', shared.endstr]; | ||
9 | %shared.data1 = [1,2,3]; | ||
10 | shared.data1 = randn(2e6,1); | ||
11 | shared.precision1 = 'double'; | ||
12 | shared.data2 = [1,2,3, 4]; | ||
13 | shared.precision2 = 'single'; | ||
14 | fid1 = fopen(shared.file1, 'w'); | ||
15 | fid2 = fopen(shared.file2, 'w'); | ||
16 | fwrite(fid1, shared.data1, shared.precision1); | ||
17 | fwrite(fid2, shared.data2, shared.precision2); | ||
18 | 18 | ||
19 | 19 | function teardown(shared) | function teardown(shared) |
20 | delete(shared.file1); | ||
21 | delete(shared.file2); | ||
20 | delete(shared.file1); | ||
21 | delete(shared.file2); | ||
22 | 22 | ||
23 | 23 | function byteSizeFromPrecision_test(shared) | function byteSizeFromPrecision_test(shared) |
24 | 24 | assertEqual(byteSizeFromPrecision('double'), 8) | assertEqual(byteSizeFromPrecision('double'), 8) |
... | ... | function dtsize_test(shared) | |
45 | 45 | assertEqual(dtsize('uint8'), 1) | assertEqual(dtsize('uint8'), 1) |
46 | 46 | ||
47 | 47 | function fsize_test(shared) | function fsize_test(shared) |
48 | [s n] = fsize([shared.startstr, '*', shared.endstr]); | ||
49 | assertEqual(s(1),... | ||
50 | byteSizeFromPrecision(shared.precision1)*length(shared.data1)) | ||
51 | assertEqual(s(2),... | ||
52 | byteSizeFromPrecision(shared.precision2)*length(shared.data2)) | ||
53 | assertEqual(n{1}, shared.file1) | ||
54 | assertEqual(n{2}, shared.file2) | ||
48 | [s n] = fsize([shared.startstr, '*', shared.endstr]); | ||
49 | assertEqual(s(1),... | ||
50 | byteSizeFromPrecision(shared.precision1)*length(shared.data1)) | ||
51 | assertEqual(s(2),... | ||
52 | byteSizeFromPrecision(shared.precision2)*length(shared.data2)) | ||
53 | assertEqual(n{1}, shared.file1) | ||
54 | assertEqual(n{2}, shared.file2) | ||
55 | 55 | ||
56 | 56 | function sampleNoInFile_test(shared) | function sampleNoInFile_test(shared) |
57 | 57 | ||
58 | assertEqual(sampleNoInFile(shared.file1, shared.precision1),... | ||
59 | length(shared.data1)) | ||
60 | assertEqual(sampleNoInFile(shared.file2, shared.precision2),... | ||
61 | length(shared.data2)) | ||
58 | assertEqual(sampleNoInFile(shared.file1, shared.precision1),... | ||
59 | length(shared.data1)) | ||
60 | assertEqual(sampleNoInFile(shared.file2, shared.precision2),... | ||
61 | length(shared.data2)) | ||
62 | 62 | ||
63 | 63 | function varAndMeanFromFile_test(shared) | function varAndMeanFromFile_test(shared) |
64 | [cumVar, cumMean, cumSize] = varAndMeanFromFile(shared.file1, shared.precision1); | ||
65 | assertAlmostEqual(cumVar, var(shared.data1)) | ||
66 | assertAlmostEqual(cumMean, mean(shared.data1)) | ||
67 | assertAlmostEqual(cumSize, length(shared.data1)) | ||
64 | [cumVar, cumMean, cumSize] = varAndMeanFromFile(shared.file1, shared.precision1); | ||
65 | assertAlmostEqual(cumVar, var(shared.data1)) | ||
66 | assertAlmostEqual(cumMean, mean(shared.data1)) | ||
67 | assertAlmostEqual(cumSize, length(shared.data1)) | ||
68 | 68 | ||
69 | [cumVar, cumMean, cumSize] = varAndMeanFromFile(shared.file2, shared.precision2); | ||
70 | assertAlmostEqual(cumVar, var(shared.data2)) | ||
71 | assertAlmostEqual(cumMean, mean(shared.data2)) | ||
72 | assertAlmostEqual(cumSize, length(shared.data2)) | ||
69 | [cumVar, cumMean, cumSize] = varAndMeanFromFile(shared.file2, shared.precision2); | ||
70 | assertAlmostEqual(cumVar, var(shared.data2)) | ||
71 | assertAlmostEqual(cumMean, mean(shared.data2)) | ||
72 | assertAlmostEqual(cumSize, length(shared.data2)) |
File misc/io/sampleNoInFile.m changed (mode: 100644) (index 4fec935..198d501) | |||
... | ... | assert(mod(byteNo, bytesPerSample)==0,... | |
13 | 13 | sampleNo = byteNo/bytesPerSample; | sampleNo = byteNo/bytesPerSample; |
14 | 14 | ||
15 | 15 | end | end |
16 |
File misc/io/varAndMeanFromFile.m changed (mode: 100644) (index 8a403b4..cbadd6a) | |||
... | ... | cumSize = 0; | |
18 | 18 | for blockInd=1:blockNo | for blockInd=1:blockNo |
19 | 19 | perccount(blockInd, blockNo); | perccount(blockInd, blockNo); |
20 | 20 | data = fread(fid, blockSize, precision); | data = fread(fid, blockSize, precision); |
21 | |||
21 | |||
22 | 22 | blockVar = var(data); | blockVar = var(data); |
23 | 23 | blockMean = mean(data); | blockMean = mean(data); |
24 | |||
24 | |||
25 | 25 | if blockInd==1 | if blockInd==1 |
26 | 26 | cumVar = blockVar; | cumVar = blockVar; |
27 | cumMean = blockMean; | ||
27 | cumMean = blockMean; | ||
28 | 28 | cumSize = blockSize; | cumSize = blockSize; |
29 | |||
29 | |||
30 | 30 | else | else |
31 | 31 | cumVar = covupdate(cumMean, cumVar, cumSize,... | cumVar = covupdate(cumMean, cumVar, cumSize,... |
32 | 32 | blockMean, blockVar, blockSize); | blockMean, blockVar, blockSize); |
File misc/matrices/createTestMatrix.m changed (mode: 100644) (index 78fb143..0d5eded) | |||
... | ... | for k=1:n | |
11 | 11 | end | end |
12 | 12 | ||
13 | 13 | end | end |
14 |
File misc/matrices/matrixfct_test.m changed (mode: 100644) (index c5a34e1..a2395fa) | |||
1 | 1 | function test_suite = matrixfct_test %#ok<STOUT> | function test_suite = matrixfct_test %#ok<STOUT> |
2 | initTestSuite; | ||
2 | initTestSuite; | ||
3 | 3 | ||
4 | 4 | function unity_orthogonal_test | function unity_orthogonal_test |
5 | 5 | unitmat = eye(5); | unitmat = eye(5); |
File misc/meanupdate.m changed (mode: 100644) (index ad411df..5290c04) | |||
1 | 1 | function m = meanupdate(m1,N1,m2,N2) | function m = meanupdate(m1,N1,m2,N2) |
2 | 2 | % mean = meanupdate(mean_1,N_1,mean_2,N_2) | % mean = meanupdate(mean_1,N_1,mean_2,N_2) |
3 | % | ||
3 | % | ||
4 | 4 | % Calculate updated mean vector from two sample of same distribution, | % Calculate updated mean vector from two sample of same distribution, |
5 | 5 | % where mean mean_i and N_i are the mean and sample | % where mean mean_i and N_i are the mean and sample |
6 | 6 | % size of each sample respectively. mean_i can be column or row | % size of each sample respectively. mean_i can be column or row |
File misc/nssv.m changed (mode: 100644) (index 9cbc48c..9b5c51b) | |||
1 | 1 | function [sv,dv] = nssv(cov,part) | function [sv,dv] = nssv(cov,part) |
2 | 2 | % [sv,dv] = nssv(cov,part) | % [sv,dv] = nssv(cov,part) |
3 | % | ||
3 | % | ||
4 | 4 | % Returns normalized singular values of the correlation block given by the | % Returns normalized singular values of the correlation block given by the |
5 | 5 | % cell array part. | % cell array part. |
6 | 6 | % eg to specify the off-diagonal block for a 2mode covariance matrix, | % eg to specify the off-diagonal block for a 2mode covariance matrix, |
File misc/plottools/figure.m changed (mode: 100644) (index 25ee4c1..ead1368) | |||
1 | 1 | function varargout = figure(varargin) | function varargout = figure(varargin) |
2 | [varargout{1:nargout}] = builtin('figure', varargin{:}); | ||
3 | set(gca,'FontName','Palatino'); | ||
2 | [varargout{1:nargout}] = builtin('figure', varargin{:}); | ||
3 | set(gca,'FontName','Palatino'); | ||
4 | 4 | set(gca, 'FontSize', 11); | set(gca, 'FontSize', 11); |
5 | 5 | myColorOrder = cbrewer('qual','Set1',9); | myColorOrder = cbrewer('qual','Set1',9); |
6 | 6 | set(gca, 'ColorOrder', myColorOrder, 'NextPlot', 'replacechildren'); | set(gca, 'ColorOrder', myColorOrder, 'NextPlot', 'replacechildren'); |
File misc/plottools/labels.m changed (mode: 100644) (index 2cc2ba3..036a93a) | |||
1 | 1 | function labels(x_label, y_label) | function labels(x_label, y_label) |
2 | set(gca,'FontName','Palatino'); | ||
2 | set(gca,'FontName','Palatino'); | ||
3 | 3 | set(gca, 'FontSize', 12); | set(gca, 'FontSize', 12); |
4 | xlabel(sentence_case(x_label), 'Interpreter','latex'); | ||
5 | ylabel(sentence_case(y_label), 'Interpreter','latex'); | ||
4 | xlabel(sentence_case(x_label), 'Interpreter','latex'); | ||
5 | ylabel(sentence_case(y_label), 'Interpreter','latex'); | ||
6 | 6 | set(gca, 'FontSize', 11); | set(gca, 'FontSize', 11); |
File misc/plottools/sentence_case.m changed (mode: 100644) (index d18342a..7d7d932) | |||
1 | 1 | function Sentence_string = sentence_case(string) | function Sentence_string = sentence_case(string) |
2 | % Capitalizes first word of the input string | ||
3 | assert(ischar(string), 'Expected string.') | ||
4 | if length(string)>0 | ||
5 | Sentence_string = [upper(string(1)), string(2:end)]; | ||
6 | else | ||
7 | Sentence_string = ''; | ||
8 | end | ||
2 | % Capitalizes first word of the input string | ||
3 | assert(ischar(string), 'Expected string.') | ||
4 | if length(string)>0 | ||
5 | Sentence_string = [upper(string(1)), string(2:end)]; | ||
6 | else | ||
7 | Sentence_string = ''; | ||
8 | end |
File misc/plottools/tex_escape.m changed (mode: 100644) (index f89de0d..6317d6c) | |||
1 | 1 | function escaped_strings = tex_escape(strings) | function escaped_strings = tex_escape(strings) |
2 | % see https://tex.stackexchange.com/questions/34580/escape-character-in-latex for background | ||
3 | if iscell(strings) | ||
4 | escaped_strings = cellfun(@tex_escape_single, strings, 'UniformOutput', false); | ||
5 | else | ||
6 | escaped_strings = tex_escape_single(strings); | ||
7 | end | ||
2 | % see https://tex.stackexchange.com/questions/34580/escape-character-in-latex for background | ||
3 | if iscell(strings) | ||
4 | escaped_strings = cellfun(@tex_escape_single, strings, 'UniformOutput', false); | ||
5 | else | ||
6 | escaped_strings = tex_escape_single(strings); | ||
7 | end | ||
8 | 8 | ||
9 | 9 | function escaped_string = tex_escape_single(string) | function escaped_string = tex_escape_single(string) |
10 | replacements = {... | ||
11 | {'\', 'PRIVATEBACKSLASHESCAPED'};... | ||
12 | {'&', '\&'};... | ||
13 | {'%', '\%'};... | ||
14 | {'$', '\$'};... | ||
15 | {'#', '\#'};... | ||
16 | {'_', '\_'};... | ||
17 | {'{', '\{}'};... | ||
18 | {'}', '\'};... | ||
19 | {'~', '\textasciitilde '};... | ||
20 | {'^', '\textasciicircum '};... | ||
21 | {'PRIVATEBACKSLASHESCAPED', '\textbackslash '}}; | ||
10 | replacements = {... | ||
11 | {'\', 'PRIVATEBACKSLASHESCAPED'};... | ||
12 | {'&', '\&'};... | ||
13 | {'%', '\%'};... | ||
14 | {'$', '\$'};... | ||
15 | {'#', '\#'};... | ||
16 | {'_', '\_'};... | ||
17 | {'{', '\{}'};... | ||
18 | {'}', '\'};... | ||
19 | {'~', '\textasciitilde '};... | ||
20 | {'^', '\textasciicircum '};... | ||
21 | {'PRIVATEBACKSLASHESCAPED', '\textbackslash '}}; | ||
22 | 22 | ||
23 | escaped_string = string; | ||
24 | for k=1:length(replacements) | ||
25 | rep = replacements{k}; | ||
26 | escaped_string = strrep(escaped_string, rep{1}, rep{2}); | ||
27 | end | ||
23 | escaped_string = string; | ||
24 | for k=1:length(replacements) | ||
25 | rep = replacements{k}; | ||
26 | escaped_string = strrep(escaped_string, rep{1}, rep{2}); | ||
27 | end |
File misc/plottools/tex_escape_test.m changed (mode: 100644) (index 2d09cfa..e2675ad) | |||
1 | 1 | function test_suite = tex_escape_test %#ok<STOUT> | function test_suite = tex_escape_test %#ok<STOUT> |
2 | localFunctionHandles = cellfun(@str2func,... | ||
3 | which('-subfun', mfilename('fullpath')), 'UniformOutput', false); | ||
4 | test_suite = buildFunctionHandleTestSuite(localFunctionHandles); | ||
2 | localFunctionHandles = cellfun(@str2func,... | ||
3 | which('-subfun', mfilename('fullpath')), 'UniformOutput', false); | ||
4 | test_suite = buildFunctionHandleTestSuite(localFunctionHandles); | ||
5 | 5 | ||
6 | 6 | function pt = backslash_test | function pt = backslash_test |
7 | input_string = 'string with a \ backslash'; | ||
8 | assertEqual(tex_escape(input_string),... | ||
9 | 'string with a \textbackslash backslash') | ||
7 | input_string = 'string with a \ backslash'; | ||
8 | assertEqual(tex_escape(input_string),... | ||
9 | 'string with a \textbackslash backslash') | ||
10 | 10 | ||
11 | 11 | function pt = mixed_test | function pt = mixed_test |
12 | input_string = 'string with & and a \ backslash ^'; | ||
13 | assertEqual(tex_escape(input_string),... | ||
14 | 'string with \& and a \textbackslash backslash \textasciicircum ') | ||
12 | input_string = 'string with & and a \ backslash ^'; | ||
13 | assertEqual(tex_escape(input_string),... | ||
14 | 'string with \& and a \textbackslash backslash \textasciicircum ') | ||
15 | 15 | ||
16 | 16 | function pt = cell_array_test | function pt = cell_array_test |
17 | input_strings = {'string with & and a \ backslash ^',... | ||
18 | ' & and a \ backslash ^ x_y'}; | ||
19 | assertEqual(tex_escape(input_strings),... | ||
20 | {'string with \& and a \textbackslash backslash \textasciicircum ',... | ||
21 | ' \& and a \textbackslash backslash \textasciicircum x\_y'}) | ||
17 | input_strings = {'string with & and a \ backslash ^',... | ||
18 | ' & and a \ backslash ^ x_y'}; | ||
19 | assertEqual(tex_escape(input_strings),... | ||
20 | {'string with \& and a \textbackslash backslash \textasciicircum ',... | ||
21 | ' \& and a \textbackslash backslash \textasciicircum x\_y'}) | ||
22 | 22 | ||
23 | 23 | function pt = plot_test | function pt = plot_test |
24 | input_string = 'x_y r^z string with & and a \ backslash ^'; | ||
25 | fig = figure; plot([1,2],[1,2]) | ||
26 | title(tex_escape(input_string), 'Interpreter', 'latex') | ||
27 | legend({tex_escape(input_string)}, 'Interpreter', 'latex') | ||
28 | xlabel(tex_escape(input_string), 'Interpreter', 'latex') | ||
29 | ylabel(tex_escape(input_string), 'Interpreter', 'latex') | ||
30 | close(fig) | ||
24 | input_string = 'x_y r^z string with & and a \ backslash ^'; | ||
25 | fig = figure; plot([1,2],[1,2]) | ||
26 | title(tex_escape(input_string), 'Interpreter', 'latex') | ||
27 | legend({tex_escape(input_string)}, 'Interpreter', 'latex') | ||
28 | xlabel(tex_escape(input_string), 'Interpreter', 'latex') | ||
29 | ylabel(tex_escape(input_string), 'Interpreter', 'latex') | ||
30 | close(fig) |
File misc/running_stats.m changed (mode: 100644) (index 9a0afad..8d1e6bc) | |||
1 | 1 | function [covs, means] = running_stats(array, interval) | function [covs, means] = running_stats(array, interval) |
2 | 2 | % [covs, means] = running_stats(array, interval) takes a (sampleno, dim)-sized array | % [covs, means] = running_stats(array, interval) takes a (sampleno, dim)-sized array |
3 | % and computes covariance matrices | ||
3 | % and computes covariance matrices | ||
4 | 4 | ||
5 | 5 | sampleno = size(array, 1); | sampleno = size(array, 1); |
6 | 6 | dim = size(array, 2); | dim = size(array, 2); |
... | ... | means{1} = mean(data); | |
16 | 16 | samples = interval; | samples = interval; |
17 | 17 | ||
18 | 18 | for k=2:stepno | for k=2:stepno |
19 | data = array(samples+1:samples+interval,:); | ||
19 | data = array(samples+1:samples+interval,:); | ||
20 | 20 | ||
21 | 21 | % mean = meanupdate(mean_1,N_1,mean_2,N_2) | % mean = meanupdate(mean_1,N_1,mean_2,N_2) |
22 | means{k} = meanupdate(means{k-1}, samples,... | ||
23 | mean(data), interval); | ||
22 | means{k} = meanupdate(means{k-1}, samples,... | ||
23 | mean(data), interval); | ||
24 | 24 | ||
25 | 25 | % cov = covupdate(mean_1,cov_1,N_1,mean_2,cov_2,N_2) | % cov = covupdate(mean_1,cov_1,N_1,mean_2,cov_2,N_2) |
26 | covs{k} = covupdate(means{k-1}, covs{k-1}, samples,... | ||
27 | means{k}, cov(data), interval); | ||
26 | covs{k} = covupdate(means{k-1}, covs{k-1}, samples,... | ||
27 | means{k}, cov(data), interval); | ||
28 | 28 | ||
29 | samples = samples + interval; | ||
29 | samples = samples + interval; | ||
30 | 30 | end | end |
31 | 31 | ||
32 | 32 | %% test code | %% test code |
File misc/ui/perccount.m changed (mode: 100644) (index 09454ce..cd02cda) | |||
... | ... | function perccount(jj,maxjj) | |
8 | 8 | % Do not print anything to the screen between calls of this function! | % Do not print anything to the screen between calls of this function! |
9 | 9 | % | % |
10 | 10 | ||
11 | % title - s cmspike/perccount vr - 1.2 | ||
11 | % title - s cmspike/perccount vr - 1.2 | ||
12 | 12 | % author - bodc/alead date - 2006may16 | % author - bodc/alead date - 2006may16 |
13 | 13 | ||
14 | 14 | % Updated 2009May14 | % Updated 2009May14 |
15 | % At suggestion of John D'Errico renamed internal variable "max" to | ||
15 | % At suggestion of John D'Errico renamed internal variable "max" to | ||
16 | 16 | % "maxjj" | % "maxjj" |
17 | 17 | % Also following D'Errico's suggestions the following functionality has | % Also following D'Errico's suggestions the following functionality has |
18 | 18 | % been added: | % been added: |
File misc/varargs2cell.m changed (mode: 100644) (index a54068a..77c98d6) | |||
1 | 1 | function [varout,nargs] = varargs2cell(varin) | function [varout,nargs] = varargs2cell(varin) |
2 | 2 | % varout = varargs2cell(varin) | % varout = varargs2cell(varin) |
3 | % | ||
3 | % | ||
4 | 4 | % Parse varargin: If varin has one element which is a structure unfold | % Parse varargin: If varin has one element which is a structure unfold |
5 | 5 | % the structure to a key/value type cell, else return varin | % the structure to a key/value type cell, else return varin |
6 | 6 | % unmodified. | % unmodified. |
7 | 7 | ||
8 | 8 | if ~iscell(varin) | if ~iscell(varin) |
9 | 9 | error('input argument must be cell') | error('input argument must be cell') |
10 | end | ||
10 | end | ||
11 | 11 | ||
12 | 12 | if numel(varin) == 1 && isstruct(varin{1}) | if numel(varin) == 1 && isstruct(varin{1}) |
13 | 13 | c = struct2cell(varin{1}); | c = struct2cell(varin{1}); |
File misc/varargs2struct.m changed (mode: 100644) (index 177a265..182a0d5) | |||
... | ... | function argS = varargs2struct(varargin) | |
3 | 3 | % argS = varargs2struct(argNamesC,argC) | % argS = varargs2struct(argNamesC,argC) |
4 | 4 | % argS = varargs2struct(argNamesC,argC,nReq) | % argS = varargs2struct(argNamesC,argC,nReq) |
5 | 5 | % | % |
6 | % One input argument: | ||
7 | % | ||
6 | % One input argument: | ||
7 | % | ||
8 | 8 | % Input must either be a cell in key/value-pair | % Input must either be a cell in key/value-pair |
9 | 9 | % which is returned as a struct or can be a struct which is returned | % which is returned as a struct or can be a struct which is returned |
10 | 10 | % unmodified. | % unmodified. |
11 | 11 | % | % |
12 | 12 | % Two or more input arguments: | % Two or more input arguments: |
13 | % | ||
13 | % | ||
14 | 14 | % Copy arguments from cell argC to struct argS, where fieldnames are | % Copy arguments from cell argC to struct argS, where fieldnames are |
15 | 15 | % given in argNamesC in the form {'arg1','arg2',...}. argC must have | % given in argNamesC in the form {'arg1','arg2',...}. argC must have |
16 | 16 | % at most the same length as argNamesC. As a last argument the number | % at most the same length as argNamesC. As a last argument the number |
... | ... | function argS = varargs2struct(varargin) | |
26 | 26 | if nargin == 1 | if nargin == 1 |
27 | 27 | % one layer of {} has to be unwrapped | % one layer of {} has to be unwrapped |
28 | 28 | % (varargin{1} is equal to original input from calling function) | % (varargin{1} is equal to original input from calling function) |
29 | if isstruct(varargin{1}) | ||
30 | % if single struct is given, return unmodified | ||
29 | if isstruct(varargin{1}) | ||
30 | % if single struct is given, return unmodified | ||
31 | 31 | argS = varargin{1}; | argS = varargin{1}; |
32 | 32 | elseif iscell(varargin{1}) | elseif iscell(varargin{1}) |
33 | 33 | % if single cell is given it must be in key/value pair form | % if single cell is given it must be in key/value pair form |
File misc/varupdate.m changed (mode: 100644) (index d676a18..9853ed8) | |||
1 | 1 | function var = varupdate(m1,v1,N1,m2,v2,N2) | function var = varupdate(m1,v1,N1,m2,v2,N2) |
2 | 2 | % var = varupdate(mean_1,var_1,N_1,mean_2,var_2,N_2) | % var = varupdate(mean_1,var_1,N_1,mean_2,var_2,N_2) |
3 | % | ||
3 | % | ||
4 | 4 | % Calculate update variance from two samples of same distribution, | % Calculate update variance from two samples of same distribution, |
5 | 5 | % where mean mean_i, var_i and N_i are the mean, variance and sample | % where mean mean_i, var_i and N_i are the mean, variance and sample |
6 | 6 | % size of each sample respectively. mean_i and var_i must be arrays of | % size of each sample respectively. mean_i and var_i must be arrays of |
File statisticstests/archive/jarque_bera_test.m changed (mode: 100644) (index 38f58ac..f0b72cf) | |||
1 | 1 | function [jbstat, msig] = jarque_bera_test(y,k) | function [jbstat, msig] = jarque_bera_test(y,k) |
2 | 2 | % [jbstat, msig] = jarque_bera_test(y,k) | % [jbstat, msig] = jarque_bera_test(y,k) |
3 | % | ||
3 | % | ||
4 | 4 | % Jarque-Bera statistic with marginal significance level, y input, k | % Jarque-Bera statistic with marginal significance level, y input, k |
5 | 5 | % regressors | % regressors |
6 | 6 |
File statisticstests/neestest.m changed (mode: 100644) (index 6a688fa..027e3c1) | |||
... | ... | switch method | |
141 | 141 | neesCov=cov(NEES'); | neesCov=cov(NEES'); |
142 | 142 | if ~statv.chi2.h, result='passed'; else result='failed'; end | if ~statv.chi2.h, result='passed'; else result='failed'; end |
143 | 143 | fprintf('NEES test %s (p=%g)\n',result,statv.chi2.p); | fprintf('NEES test %s (p=%g)\n',result,statv.chi2.p); |
144 | |||
145 | |||
144 | |||
145 | |||
146 | 146 | case 'NMEE' | case 'NMEE' |
147 | 147 | % test NMEE against normal distribution | % test NMEE against normal distribution |
148 | 148 | % NMEE should be Gaussian and white (???) with normalized variance | % NMEE should be Gaussian and white (???) with normalized variance |
149 | |||
149 | |||
150 | 150 | fprintf('\nDo NMEE test...'); | fprintf('\nDo NMEE test...'); |
151 | 151 | NEES=zeros(NT,sn); | NEES=zeros(NT,sn); |
152 | 152 | h=zeros(1,sn); | h=zeros(1,sn); |
... | ... | if show_plots | |
228 | 228 | [~,r,bound] = chi2Test(NEES,sn,alpha,confint); | [~,r,bound] = chi2Test(NEES,sn,alpha,confint); |
229 | 229 | plot(xvec,NEES,xvec,bound(1)*ones(1,NT),'k-.',xvec,bound(2)*ones(1,NT),'k-.'); | plot(xvec,NEES,xvec,bound(1)*ones(1,NT),'k-.',xvec,bound(2)*ones(1,NT),'k-.'); |
230 | 230 | title(sprintf('NEES + %s %g confidence interval: r=%f',confint,alpha,r)); | title(sprintf('NEES + %s %g confidence interval: r=%f',confint,alpha,r)); |
231 | |||
231 | |||
232 | 232 | figure(); | figure(); |
233 | 233 | [~,cdfstats]=cdfplot(NEES);hold on; | [~,cdfstats]=cdfplot(NEES);hold on; |
234 | 234 | xx=(0:1/NT:1)*cdfstats.max; | xx=(0:1/NT:1)*cdfstats.max; |
235 | 235 | plot(xx,chi2cdf(xx,sn),'r'); | plot(xx,chi2cdf(xx,sn),'r'); |
236 | 236 | title(sprintf('CDF NEES: h=%d, p=%f',h,p)) | title(sprintf('CDF NEES: h=%d, p=%f',h,p)) |
237 | |||
237 | |||
238 | 238 | case 'NMEE' | case 'NMEE' |
239 | 239 | xx=(-1:1/NT:1)*5; | xx=(-1:1/NT:1)*5; |
240 | 240 | fNMEE=zeros(sn,1); | fNMEE=zeros(sn,1); |
... | ... | if show_plots | |
245 | 245 | plot(xx,cdffunc(xx),'r'); | plot(xx,cdffunc(xx),'r'); |
246 | 246 | title(sprintf('CDF NMEE(%d): h=%d, p=%f',mm,h(mm),p(mm))) | title(sprintf('CDF NMEE(%d): h=%d, p=%f',mm,h(mm),p(mm))) |
247 | 247 | end | end |
248 | |||
248 | |||
249 | 249 | % plot histogram of NMEE values | % plot histogram of NMEE values |
250 | 250 | figure(); | figure(); |
251 | 251 | histbins=100; | histbins=100; |
File statisticstests/nistest.m changed (mode: 100644) (index 08fecdc..acee28e) | |||
... | ... | end | |
67 | 67 | % (this makes evaluation of if's faster) | % (this makes evaluation of if's faster) |
68 | 68 | if sequcalc | if sequcalc |
69 | 69 | fprintf('\n******** NIS/NMI test ********\n'); | fprintf('\n******** NIS/NMI test ********\n'); |
70 | |||
70 | |||
71 | 71 | H_NTD = (size(H,3)==1); | H_NTD = (size(H,3)==1); |
72 | 72 | P_NTD = (size(pmvec,3)==1); | P_NTD = (size(pmvec,3)==1); |
73 | |||
73 | |||
74 | 74 | % skip data points | % skip data points |
75 | 75 | if tsstart>1 | if tsstart>1 |
76 | 76 | fprintf('\nNIS/NMI test: drop first %d datapoints',tsstart-1); | fprintf('\nNIS/NMI test: drop first %d datapoints',tsstart-1); |
... | ... | if sequcalc | |
82 | 82 | H=H(:,:,tsstart:end); | H=H(:,:,tsstart:end); |
83 | 83 | end | end |
84 | 84 | end | end |
85 | |||
85 | |||
86 | 86 | %%% run NIS tests | %%% run NIS tests |
87 | 87 | % (Heijden, p. 294) | % (Heijden, p. 294) |
88 | |||
88 | |||
89 | 89 | statv = struct(); | statv = struct(); |
90 | 90 | [os,sn,~] = size(H); | [os,sn,~] = size(H); |
91 | 91 | NT = length(innov); | NT = length(innov); |
92 | |||
92 | |||
93 | 93 | fprintf('\nNIS/NMI test with %d DOF (#measurements) and with %d state vaiables\n',os,sn); | fprintf('\nNIS/NMI test with %d DOF (#measurements) and with %d state vaiables\n',os,sn); |
94 | |||
94 | |||
95 | 95 | else | else |
96 | 96 | fprintf('\n******** NIS/NMI test: sequence given ********\n'); | fprintf('\n******** NIS/NMI test: sequence given ********\n'); |
97 | |||
97 | |||
98 | 98 | os=size(innov,2); | os=size(innov,2); |
99 | 99 | NT = length(innov); | NT = length(innov); |
100 | |||
100 | |||
101 | 101 | fprintf('\nNIS/NMI test with %d DOF (#measurements)\n',os); | fprintf('\nNIS/NMI test with %d DOF (#measurements)\n',os); |
102 | 102 | end | end |
103 | 103 | ||
... | ... | switch method | |
154 | 154 | covnischi2=cov(NIS); | covnischi2=cov(NIS); |
155 | 155 | if ~statv.chi2.h, result='passed'; else result='failed'; end | if ~statv.chi2.h, result='passed'; else result='failed'; end |
156 | 156 | fprintf('NIS test %s (p=%g)\n',result,statv.chi2.p); | fprintf('NIS test %s (p=%g)\n',result,statv.chi2.p); |
157 | |||
157 | |||
158 | 158 | xx=(0:1/NT:1)*25; | xx=(0:1/NT:1)*25; |
159 | |||
159 | |||
160 | 160 | case 'NMI' | case 'NMI' |
161 | 161 | if sequcalc | if sequcalc |
162 | 162 | % calculate NIS sequence | % calculate NIS sequence |
... | ... | switch method | |
166 | 166 | NIS=zeros(NT,os); | NIS=zeros(NT,os); |
167 | 167 | h=zeros(1,os); p=h; | h=zeros(1,os); p=h; |
168 | 168 | droptol=1E-15; | droptol=1E-15; |
169 | |||
169 | |||
170 | 170 | % initialize variables for time-independent case | % initialize variables for time-independent case |
171 | 171 | if H_NTD | if H_NTD |
172 | 172 | ht=H; | ht=H; |
... | ... | switch method | |
177 | 177 | icopts = struct('type','ict','droptol',droptol); | icopts = struct('type','ict','droptol',droptol); |
178 | 178 | if H_NTD && P_NTD | if H_NTD && P_NTD |
179 | 179 | S=ht*pt*ht'+R; | S=ht*pt*ht'+R; |
180 | C=ichol(sparse(S),icopts); | ||
180 | C=ichol(sparse(S),icopts); | ||
181 | 181 | for mm=1:NT | for mm=1:NT |
182 | 182 | %NIS=C\innov; %WITLEF | %NIS=C\innov; %WITLEF |
183 | 183 | NIS(mm,:)=C\innov(mm,:)'; | NIS(mm,:)=C\innov(mm,:)'; |
... | ... | switch method | |
195 | 195 | NIS(mm,:)=C\innov(mm,:)'; | NIS(mm,:)=C\innov(mm,:)'; |
196 | 196 | end | end |
197 | 197 | end | end |
198 | |||
198 | |||
199 | 199 | else | else |
200 | 200 | % NIS sequence given | % NIS sequence given |
201 | 201 | NIS=innov; | NIS=innov; |
202 | 202 | end | end |
203 | |||
203 | |||
204 | 204 | for mm=1:os | for mm=1:os |
205 | 205 | switch hyptest | switch hyptest |
206 | 206 | case 'chi2gof' | case 'chi2gof' |
... | ... | switch method | |
210 | 210 | [~,NISxx,~,~,~] = cdfcalc(NIS(:,mm)); | [~,NISxx,~,~,~] = cdfcalc(NIS(:,mm)); |
211 | 211 | nistestf=@(x) kstest(x,[NISxx,normcdf(NISxx,0,1)],alpha); | nistestf=@(x) kstest(x,[NISxx,normcdf(NISxx,0,1)],alpha); |
212 | 212 | [h(mm),p(mm)]=nistestf(NIS(:,mm)); | [h(mm),p(mm)]=nistestf(NIS(:,mm)); |
213 | case 'ksstat' | ||
213 | case 'ksstat' | ||
214 | 214 | h(mm)=2; % not relevant | h(mm)=2; % not relevant |
215 | 215 | p(mm)=ksstatistic(NIS(:,mm)); % p is here the test statistic! | p(mm)=ksstatistic(NIS(:,mm)); % p is here the test statistic! |
216 | 216 | case 'none' | case 'none' |
... | ... | switch method | |
225 | 225 | if ~statv.norm.h(mm), result='passed'; else result='failed'; end | if ~statv.norm.h(mm), result='passed'; else result='failed'; end |
226 | 226 | fprintf('NMI(%d) test %s (p=%g)\n',mm,result,statv.norm.p(mm)); | fprintf('NMI(%d) test %s (p=%g)\n',mm,result,statv.norm.p(mm)); |
227 | 227 | end | end |
228 | |||
228 | |||
229 | 229 | xx=(-1:1/NT:1)*5; | xx=(-1:1/NT:1)*5; |
230 | |||
230 | |||
231 | 231 | otherwise | otherwise |
232 | 232 | warning(sprintf('unknown method %s',method)); | warning(sprintf('unknown method %s',method)); |
233 | 233 | show_plots = false; | show_plots = false; |
... | ... | if show_info | |
267 | 267 | if ~statv.norm.h(mm), result='passed'; else result='failed'; end | if ~statv.norm.h(mm), result='passed'; else result='failed'; end |
268 | 268 | fprintf('NMI(%d) test: %s (p=%g)\n',mm,result,statv.norm.p(mm)); | fprintf('NMI(%d) test: %s (p=%g)\n',mm,result,statv.norm.p(mm)); |
269 | 269 | fprintf('NMI(%d) test: %g inside (%s) %g bound(s)\n',mm,r(mm),confint,1-alpha); | fprintf('NMI(%d) test: %g inside (%s) %g bound(s)\n',mm,r(mm),confint,1-alpha); |
270 | fprintf('NMI(%d) test: mean(NMI) (should be 0): %g\n',mm,meannisnorm(mm)); | ||
270 | fprintf('NMI(%d) test: mean(NMI) (should be 0): %g\n',mm,meannisnorm(mm)); | ||
271 | 271 | end | end |
272 | 272 | fprintf('NMI test: cov(NMI) (should be eye(%g)):\n',size(innov,2)); | fprintf('NMI test: cov(NMI) (should be eye(%g)):\n',size(innov,2)); |
273 | 273 | fprintfarray(1,'%g\t',covnisnorm); | fprintfarray(1,'%g\t',covnisnorm); |
274 | 274 | end | end |
275 | |||
275 | |||
276 | 276 | % whiteness | % whiteness |
277 | 277 | if wttest | if wttest |
278 | 278 | for mm=1:os | for mm=1:os |
... | ... | if show_info | |
286 | 286 | fprintf('Whiteness test(%d) (%s) - smoothed spectral density - %g inside (%s) %g bound(s)\n',mm,method,rwt,confint,1-alpha); | fprintf('Whiteness test(%d) (%s) - smoothed spectral density - %g inside (%s) %g bound(s)\n',mm,method,rwt,confint,1-alpha); |
287 | 287 | end | end |
288 | 288 | end | end |
289 | |||
289 | |||
290 | 290 | end | end |
291 | 291 | ||
292 | 292 | if show_plots | if show_plots |
... | ... | if show_plots | |
298 | 298 | bound = chi2inv(confInterval(alpha,confint),os); | bound = chi2inv(confInterval(alpha,confint),os); |
299 | 299 | plot(xvec,NIS,xvec,bound(1)*ones(1,NT),'k-.',xvec,bound(2)*ones(1,NT),'k-.'); | plot(xvec,NIS,xvec,bound(1)*ones(1,NT),'k-.',xvec,bound(2)*ones(1,NT),'k-.'); |
300 | 300 | title(sprintf('NIS + %s %g confidence interval: r=%f',confint,alpha,r)); | title(sprintf('NIS + %s %g confidence interval: r=%f',confint,alpha,r)); |
301 | |||
301 | |||
302 | 302 | figure(); | figure(); |
303 | 303 | cdfplot(NIS);hold on; | cdfplot(NIS);hold on; |
304 | 304 | plot(xx,chi2cdf(xx,os),'r'); | plot(xx,chi2cdf(xx,os),'r'); |
305 | 305 | title(sprintf('CDF NIS^2: h=%d, p=%f',statv.chi2.h,statv.chi2.p)) | title(sprintf('CDF NIS^2: h=%d, p=%f',statv.chi2.h,statv.chi2.p)) |
306 | |||
307 | case 'NMI' | ||
308 | for mm=1:os | ||
309 | figure(); | ||
306 | |||
307 | case 'NMI' | ||
308 | for mm=1:os | ||
309 | figure(); | ||
310 | 310 | cdfplot(NIS(:,mm)); hold on; | cdfplot(NIS(:,mm)); hold on; |
311 | 311 | plot(xx,normcdf(xx),'-r'); | plot(xx,normcdf(xx),'-r'); |
312 | 312 | title(sprintf('CDF NMI(%d): h=%d, p=%f',mm,statv.norm.h(mm),statv.norm.p(mm))) | title(sprintf('CDF NMI(%d): h=%d, p=%f',mm,statv.norm.h(mm),statv.norm.p(mm))) |
313 | 313 | end | end |
314 | |||
314 | |||
315 | 315 | % plot histogram of NMI values | % plot histogram of NMI values |
316 | 316 | figure(); | figure(); |
317 | 317 | histbins=100; | histbins=100; |
... | ... | function kstat = ksstatistic(vec) | |
373 | 373 | % function computes the Kolmogorov-Smirnov test statistics | % function computes the Kolmogorov-Smirnov test statistics |
374 | 374 | % max(|F(x)-G(x)|), where F(x) is the empirical df and | % max(|F(x)-G(x)|), where F(x) is the empirical df and |
375 | 375 | % G(x) the standard normal cdf | % G(x) the standard normal cdf |
376 | [yCDF,xCDF] = cdfcalc(vec); | ||
376 | [yCDF,xCDF] = cdfcalc(vec); | ||
377 | 377 | xCDF = [xCDF;1.1*xCDF(end)]; | xCDF = [xCDF;1.1*xCDF(end)]; |
378 | 378 | yncdf = normcdf(xCDF,0,1); | yncdf = normcdf(xCDF,0,1); |
379 | kstat = max(abs(yCDF-yncdf)); | ||
379 | kstat = max(abs(yCDF-yncdf)); |
File statisticstests/whitenesstest.m changed (mode: 100644) (index a5771cb..0a19374) | |||
1 | 1 | function [h p varargout] = whitenesstest(x,varargin) | function [h p varargout] = whitenesstest(x,varargin) |
2 | 2 | % [h p] = whitenesstest(x,...) | % [h p] = whitenesstest(x,...) |
3 | % | ||
3 | % | ||
4 | 4 | % Test if stochastic process x (single column vector) is white. The result h=0 | % Test if stochastic process x (single column vector) is white. The result h=0 |
5 | 5 | % means that the null hypothesis (i.e. x is white) cannot be rejected | % means that the null hypothesis (i.e. x is white) cannot be rejected |
6 | 6 | % at the given significance level α (default: 0.05). The p value is | % at the given significance level α (default: 0.05). The p value is |
... | ... | function [h p varargout] = whitenesstest(x,varargin) | |
8 | 8 | % observing the given statistic or one more extreme. | % observing the given statistic or one more extreme. |
9 | 9 | % | % |
10 | 10 | % Note: Data must be zero mean in order for these tests to work! Use | % Note: Data must be zero mean in order for these tests to work! Use |
11 | % 'detrend' if needed. | ||
11 | % 'detrend' if needed. | ||
12 | 12 | % | % |
13 | 13 | % optional arguments (key/value pairs): | % optional arguments (key/value pairs): |
14 | 14 | % - 'alpha': significance level (default: 0.05) | % - 'alpha': significance level (default: 0.05) |
... | ... | switch method | |
69 | 69 | case 'lbq' | case 'lbq' |
70 | 70 | %% Ljung-Box Q-test | %% Ljung-Box Q-test |
71 | 71 | % see McNelis, p. 86 | % see McNelis, p. 86 |
72 | % | ||
72 | % | ||
73 | 73 | % Note: | % Note: |
74 | 74 | % - the rejection value for Q is given by the | % - the rejection value for Q is given by the |
75 | 75 | % (1-alpha)-quantile of the chi^2 distribution for maxlag d.o.f | % (1-alpha)-quantile of the chi^2 distribution for maxlag d.o.f |
... | ... | switch method | |
92 | 92 | %% Bartnett's method | %% Bartnett's method |
93 | 93 | % calculate periodogram by averaging over segments | % calculate periodogram by averaging over segments |
94 | 94 | % see Shiavi, p. 244f; Hayes, p. 412; | % see Shiavi, p. 244f; Hayes, p. 412; |
95 | % | ||
95 | % | ||
96 | 96 | % Note: | % Note: |
97 | 97 | % - Only use rectangular, non-overlapping windows, | % - Only use rectangular, non-overlapping windows, |
98 | 98 | % otherwise variances can't be evaluated. | % otherwise variances can't be evaluated. |
File stochasticintegration/discretize.m changed (mode: 100644) (index 088b515..0e2cfba) | |||
... | ... | function [F,G,H,D,L,Q,R,M]=discretize(FC,GC,HC,DC,LC,QC,RC,MC,dt,varargin) | |
32 | 32 | % Convert to discrete system | % Convert to discrete system |
33 | 33 | % | % |
34 | 34 | % Notes: | % Notes: |
35 | % | ||
35 | % | ||
36 | 36 | % - By default this uses the built-in c2d function, which is probably | % - By default this uses the built-in c2d function, which is probably |
37 | 37 | % the safest to use if prescaling of the ss model may be an issue. | % the safest to use if prescaling of the ss model may be an issue. |
38 | % | ||
38 | % | ||
39 | 39 | % - A first order approximation for the noise term would be: | % - A first order approximation for the noise term would be: |
40 | 40 | % L=(F-eye(length(F)))/FC*LC, | % L=(F-eye(length(F)))/FC*LC, |
41 | 41 | % with appropriate scaling of Q,M! | % with appropriate scaling of Q,M! |
42 | % | ||
42 | % | ||
43 | 43 | % - If needed (e.g. for time-variant systems), this can be used to | % - If needed (e.g. for time-variant systems), this can be used to |
44 | 44 | % find the exact value for Q(t): | % find the exact value for Q(t): |
45 | 45 | % qf=@(u) expm(FC*u)*LC*QC*LC'*expm(FC'*u); Q=quadv(qf,0,dt); | % qf=@(u) expm(FC*u)*LC*QC*LC'*expm(FC'*u); Q=quadv(qf,0,dt); |
46 | 46 | % Ref. [3] gives an explicit form of Q in terms of matrix | % Ref. [3] gives an explicit form of Q in terms of matrix |
47 | 47 | % exponentials for LTI systems. | % exponentials for LTI systems. |
48 | % | ||
48 | % | ||
49 | 49 | % - An alternative first order approximation of F would be F=id+dt*FC | % - An alternative first order approximation of F would be F=id+dt*FC |
50 | 50 | % (explicit Euler), but may be unstable. | % (explicit Euler), but may be unstable. |
51 | % | ||
51 | % | ||
52 | 52 | % - The (old) scaling Q = QC*dt and R = RC/dt [1] amounts to the definition of | % - The (old) scaling Q = QC*dt and R = RC/dt [1] amounts to the definition of |
53 | 53 | % - n_k = int_{t_{k-1}}^{t_k} n(s) ds/dt (rescaled by dt) | % - n_k = int_{t_{k-1}}^{t_k} n(s) ds/dt (rescaled by dt) |
54 | 54 | % - w_k = int_{t_{k-1}}^{t_k} n(s) ds (no rescaling) | % - w_k = int_{t_{k-1}}^{t_k} n(s) ds (no rescaling) |
55 | 55 | % From above scaling M = MC follows, which is consistent with the | % From above scaling M = MC follows, which is consistent with the |
56 | 56 | % requirement that positive definitenes must not depent on dt! | % requirement that positive definitenes must not depent on dt! |
57 | % | ||
57 | % | ||
58 | 58 | % - The (new) scaling Q = QC/dt and R = RC/dt [5] amounts to the definition of | % - The (new) scaling Q = QC/dt and R = RC/dt [5] amounts to the definition of |
59 | 59 | % - n_k = int_{t_{k-1}}^{t_k} n(s) ds/dt (rescaled by dt) | % - n_k = int_{t_{k-1}}^{t_k} n(s) ds/dt (rescaled by dt) |
60 | 60 | % - w_k = int_{t_{k-1}}^{t_k} n(s) ds/dt (rescaled by dt) | % - w_k = int_{t_{k-1}}^{t_k} n(s) ds/dt (rescaled by dt) |
... | ... | function [F,G,H,D,L,Q,R,M]=discretize(FC,GC,HC,DC,LC,QC,RC,MC,dt,varargin) | |
62 | 62 | % advantage that G and L = LC*dt are treated identically, which is important | % advantage that G and L = LC*dt are treated identically, which is important |
63 | 63 | % for connecting them! Additionally, this is supposed to be more | % for connecting them! Additionally, this is supposed to be more |
64 | 64 | % exact [5]. This method is/seems to be the same as c2d with 'zoh'! | % exact [5]. This method is/seems to be the same as c2d with 'zoh'! |
65 | % | ||
65 | % | ||
66 | 66 | % References: | % References: |
67 | 67 | % [1] Simon, p.231f; | % [1] Simon, p.231f; |
68 | 68 | % [2] Stengel, p.326f; | % [2] Stengel, p.326f; |
File stochasticintegration/simgauss.m changed (mode: 100644) (index 8c54a13..a73d84d) | |||
... | ... | switch method | |
115 | 115 | % Note: this is the prefered method as | % Note: this is the prefered method as |
116 | 116 | % its most robust to numerical errors which | % its most robust to numerical errors which |
117 | 117 | % lead to non positive definiteness | % lead to non positive definiteness |
118 | % Does NOT work for SEMI-DEFINITE matrices! | ||
118 | % Does NOT work for SEMI-DEFINITE matrices! | ||
119 | 119 | alpha = max(0,max(sum(abs(sigma),2)./diag(sigma))-2); | alpha = max(0,max(sum(abs(sigma),2)./diag(sigma))-2); |
120 | 120 | C = ichol(sparse(sigma),struct('droptol',droptol,'type','ict')); | C = ichol(sparse(sigma),struct('droptol',droptol,'type','ict')); |
121 | 121 | seq = C*randn(size(C,1),NT)+mum; | seq = C*randn(size(C,1),NT)+mum; |
File stochasticintegration/simlinsys.m changed (mode: 100644) (index 2938192..8bbc262) | |||
1 | 1 | function [z,x,varargout]=simlinsys(F,G,H,D,L,Q,R,M,u,xinit,NT,varargin) | function [z,x,varargout]=simlinsys(F,G,H,D,L,Q,R,M,u,xinit,NT,varargin) |
2 | 2 | % [z,x] = simlinsys(F,G,H,D,L,Q,R,M,u,xinit,NT,...) | % [z,x] = simlinsys(F,G,H,D,L,Q,R,M,u,xinit,NT,...) |
3 | 3 | % [z,x,statenoise,obsnoise] = simlinsys(F,G,H,D,L,Q,R,M,u,xinit,NT,...) | % [z,x,statenoise,obsnoise] = simlinsys(F,G,H,D,L,Q,R,M,u,xinit,NT,...) |
4 | % | ||
4 | % | ||
5 | 5 | % Sample a linear discrete system | % Sample a linear discrete system |
6 | % | ||
6 | % | ||
7 | 7 | % x(k+1) = F(k) x(k) + G u(k) + L(k) w(k) | % x(k+1) = F(k) x(k) + G u(k) + L(k) w(k) |
8 | 8 | % z(k) = H(k) x(k) + D u(k) + n(k) | % z(k) = H(k) x(k) + D u(k) + n(k) |
9 | % | ||
9 | % | ||
10 | 10 | % with time-dependent state-space matrices F(k), G(k), H(k), D(k), | % with time-dependent state-space matrices F(k), G(k), H(k), D(k), |
11 | 11 | % L(k). The noise statistics are given by | % L(k). The noise statistics are given by |
12 | % | ||
12 | % | ||
13 | 13 | % w ~ N(0,Q) | % w ~ N(0,Q) |
14 | 14 | % n ~ N(0,R) | % n ~ N(0,R) |
15 | 15 | % E[w*n'] = M | % E[w*n'] = M |
16 | % | ||
16 | % | ||
17 | 17 | % Note that time-dependent cross correlations in M are not sampled | % Note that time-dependent cross correlations in M are not sampled |
18 | 18 | % correctly! | % correctly! |
19 | 19 | % | % |
... | ... | end | |
76 | 76 | ||
77 | 77 | % check if inputs are time-dependent | % check if inputs are time-dependent |
78 | 78 | % x_TD=true <> x is time dependent! | % x_TD=true <> x is time dependent! |
79 | if size(F,3)==1, F_TD=false; f=F; else F_TD=true; end | ||
79 | if size(F,3)==1, F_TD=false; f=F; else F_TD=true; end | ||
80 | 80 | if size(G,3)==1, D_TD=false; g=G; else G_TD=true; end | if size(G,3)==1, D_TD=false; g=G; else G_TD=true; end |
81 | 81 | if size(H,3)==1, H_TD=false; h=H; else H_TD=true; end | if size(H,3)==1, H_TD=false; h=H; else H_TD=true; end |
82 | 82 | if size(D,3)==1, G_TD=false; d=D; else D_TD=true; end | if size(D,3)==1, G_TD=false; d=D; else D_TD=true; end |
... | ... | for tt = 1:NT | |
131 | 131 | if H_TD, h=H(:,:,tt); end; | if H_TD, h=H(:,:,tt); end; |
132 | 132 | if D_TD, d=D(:,:,tt); end; | if D_TD, d=D(:,:,tt); end; |
133 | 133 | if L_TD, l=L(:,:,tt); end; | if L_TD, l=L(:,:,tt); end; |
134 | |||
134 | |||
135 | 135 | x(:,tt) = x0; | x(:,tt) = x0; |
136 | 136 | z(:,tt) = h*x0 + d*u(tt,:).' + obsnoise(:,tt); | z(:,tt) = h*x0 + d*u(tt,:).' + obsnoise(:,tt); |
137 | 137 | x0 = f*x0 + l*statenoise(:,tt) + g*u(tt,:).'; | x0 = f*x0 + l*statenoise(:,tt) + g*u(tt,:).'; |
File tests/kalmanfilter_test.m changed (mode: 100644) (index b7819cd..3dce5e1) | |||
... | ... | tsMSESS(1).label = 'actual means square error'; | |
161 | 161 | % figure(); | % figure(); |
162 | 162 | % plot(tvec(PLOT_TIMEDATA)/dao.refF,tsEstSS(2).yData(PLOT_TIMEDATA,1),'g',tvec(PLOT_TIMEDATA)/dao.refF,tsSim(2).yData(PLOT_TIMEDATA,1),'k'); hold on; | % plot(tvec(PLOT_TIMEDATA)/dao.refF,tsEstSS(2).yData(PLOT_TIMEDATA,1),'g',tvec(PLOT_TIMEDATA)/dao.refF,tsSim(2).yData(PLOT_TIMEDATA,1),'k'); hold on; |
163 | 163 | % plot(tvec(PLOT_TIMEDATA)/dao.refF,tsEstSS(2).yData(PLOT_TIMEDATA,2),'r',tvec(PLOT_TIMEDATA)/dao.refF,tsSim(2).yData(PLOT_TIMEDATA,2),'y'); hold off; | % plot(tvec(PLOT_TIMEDATA)/dao.refF,tsEstSS(2).yData(PLOT_TIMEDATA,2),'r',tvec(PLOT_TIMEDATA)/dao.refF,tsSim(2).yData(PLOT_TIMEDATA,2),'y'); hold off; |
164 | % | ||
164 | % | ||
165 | 165 | % frStart=100; | % frStart=100; |
166 | 166 | % [frSim1,w]=pwelch(tsSim(2).yData(frStart:end,1)); | % [frSim1,w]=pwelch(tsSim(2).yData(frStart:end,1)); |
167 | 167 | % frSim2=pwelch(tsSim(2).yData(frStart:end,2)); | % frSim2=pwelch(tsSim(2).yData(frStart:end,2)); |
... | ... | tsMSESS(1).label = 'actual means square error'; | |
173 | 173 | ||
174 | 174 | ||
175 | 175 | %% time-dependent kalman filter | %% time-dependent kalman filter |
176 | if RUN_TDF | ||
176 | if RUN_TDF | ||
177 | 177 | fprintf('******** t-dependent kalmanfilter ********\n'); | fprintf('******** t-dependent kalmanfilter ********\n'); |
178 | 178 | % initialize data structures | % initialize data structures |
179 | 179 | tsEst = dadac(2,'xData',tvec); | tsEst = dadac(2,'xData',tvec); |
180 | tsErr = dadac(2,'xData',tvec); | ||
180 | tsErr = dadac(2,'xData',tvec); | ||
181 | 181 | tsMSE = dadac(2,'xData',tvec); | tsMSE = dadac(2,'xData',tvec); |
182 | |||
182 | |||
183 | 183 | % run Kalman filter | % run Kalman filter |
184 | 184 | if isempty(x0est) | if isempty(x0est) |
185 | 185 | x0est = [0;0]; | x0est = [0;0]; |
186 | 186 | end | end |
187 | 187 | if isempty(p0est) | if isempty(p0est) |
188 | 188 | p0est = kfsscov(sys,'posterior'); | p0est = kfsscov(sys,'posterior'); |
189 | end | ||
190 | |||
189 | end | ||
190 | |||
191 | 191 | [tsEst(2).yData,tsMSE(1).yData,tsEst(1).yData] = kalmanfilter(sys,tsSim(1).yData,[],x0est,p0est,nisOpts); | [tsEst(2).yData,tsMSE(1).yData,tsEst(1).yData] = kalmanfilter(sys,tsSim(1).yData,[],x0est,p0est,nisOpts); |
192 | 192 | % $$$ [tsEst(2).yData,tsMSE(1).yData,tsEst(1).yData] = informationfilter(sys,tsSim(1).yData,[],x0est,[]); | % $$$ [tsEst(2).yData,tsMSE(1).yData,tsEst(1).yData] = informationfilter(sys,tsSim(1).yData,[],x0est,[]); |
193 | 193 | Ptend=tsMSE(1).yData(:,:,end); | Ptend=tsMSE(1).yData(:,:,end); |
194 | 194 | tsEst(1).label = 'estimated measurement'; | tsEst(1).label = 'estimated measurement'; |
195 | 195 | tsEst(2).label = 'estimated statevector'; | tsEst(2).label = 'estimated statevector'; |
196 | 196 | tsMSE(1).label = 'estimated mean square error'; | tsMSE(1).label = 'estimated mean square error'; |
197 | |||
197 | |||
198 | 198 | tsErr(2) = tsSim(2)-tsEst(2); | tsErr(2) = tsSim(2)-tsEst(2); |
199 | 199 | tsErr(2).label = 'estimation error sequence'; | tsErr(2).label = 'estimation error sequence'; |
200 | Ptreal=cov(tsErr(2).yData(teststart:end,:)); | ||
200 | Ptreal=cov(tsErr(2).yData(teststart:end,:)); | ||
201 | 201 | tsMSE(2).yData = zeros(NT,sn); | tsMSE(2).yData = zeros(NT,sn); |
202 | 202 | tsMSE(2).yData(:,1) = tsErr(2).yData(:,1).^2; | tsMSE(2).yData(:,1) = tsErr(2).yData(:,1).^2; |
203 | 203 | tsMSE(2).yData(:,2) = tsErr(2).yData(:,2).^2; | tsMSE(2).yData(:,2) = tsErr(2).yData(:,2).^2; |
204 | 204 | tsMSE(2).yData(:,3) = tsErr(2).yData(:,1).*tsErr(2).yData(:,2); | tsMSE(2).yData(:,3) = tsErr(2).yData(:,1).*tsErr(2).yData(:,2); |
205 | tsMSE(2).label = 'actual means square error'; | ||
205 | tsMSE(2).label = 'actual means square error'; | ||
206 | 206 | % NEES test | % NEES test |
207 | 207 | % if NEES test of ss filter has been run | % if NEES test of ss filter has been run |
208 | 208 | % this one is not required | % this one is not required |
... | ... | fprintf('\ncov Sim:\n'); | |
239 | 239 | fprintfarray(1,'%g\t',cvSim); | fprintfarray(1,'%g\t',cvSim); |
240 | 240 | ||
241 | 241 | %% export to file | %% export to file |
242 | if export_results | ||
243 | save(exportfile,'Pss','Pssreal','Pss2','Ptend','Ptreal','-ascii'); | ||
242 | if export_results | ||
243 | save(exportfile,'Pss','Pssreal','Pss2','Ptend','Ptreal','-ascii'); | ||
244 | 244 | end | end |
245 | 245 | ||
246 | 246 | %% plots | %% plots |
... | ... | if show_plots | |
250 | 250 | plot(tvec,tsSim(1).yData,tvec,tsSim(2).yData,tvec,tsEst(2).yData) | plot(tvec,tsSim(1).yData,tvec,tsSim(2).yData,tvec,tsEst(2).yData) |
251 | 251 | title('timetraces: simulation + estimation') | title('timetraces: simulation + estimation') |
252 | 252 | legend('simulated measurement','simulated statevector','simulated statevector','estimated statevector','estimated statevector') | legend('simulated measurement','simulated statevector','simulated statevector','estimated statevector','estimated statevector') |
253 | |||
253 | |||
254 | 254 | fssMSE=figure(); | fssMSE=figure(); |
255 | 255 | plot(tvec,tsMSESS(1).yData); | plot(tvec,tsMSESS(1).yData); |
256 | 256 | title('ss actual mean square error') | title('ss actual mean square error') |
257 | |||
257 | |||
258 | 258 | if export_pics | if export_pics |
259 | 259 | saveas(ftt,strcat(imagefilehead,'_ftt',imageft)); | saveas(ftt,strcat(imagefilehead,'_ftt',imageft)); |
260 | 260 | saveas(fssMSE,strcat(imagefilehead,'_fssMSE',imageft)); | saveas(fssMSE,strcat(imagefilehead,'_fssMSE',imageft)); |
261 | 261 | end | end |
262 | |||
262 | |||
263 | 263 | if RUN_TDF | if RUN_TDF |
264 | 264 | % actual mean square error | % actual mean square error |
265 | 265 | ftMSE=figure(); | ftMSE=figure(); |
266 | 266 | plot(tvec,tsMSE(2).yData); | plot(tvec,tsMSE(2).yData); |
267 | 267 | title('actual mean square error') | title('actual mean square error') |
268 | |||
268 | |||
269 | 269 | % show actual z and zpred | % show actual z and zpred |
270 | 270 | tsZ = dadac(1,'xData',tvec); | tsZ = dadac(1,'xData',tvec); |
271 | 271 | tsZ(1).label = 'predicted measurement'; | tsZ(1).label = 'predicted measurement'; |
272 | tsZ(1).yData = tsEst(2).yData*sys.c'; | ||
273 | fzzpred=figure(); | ||
272 | tsZ(1).yData = tsEst(2).yData*sys.c'; | ||
273 | fzzpred=figure(); | ||
274 | 274 | plot(tvec,tsSim(1).yData,'+m');hold on; | plot(tvec,tsSim(1).yData,'+m');hold on; |
275 | plot(tvec,tsZ(1).yData,'-r'); | ||
275 | plot(tvec,tsZ(1).yData,'-r'); | ||
276 | 276 | title('actual z and zpred') | title('actual z and zpred') |
277 | 277 | legend('actual z','zpred') | legend('actual z','zpred') |
278 | |||
279 | % estimated mean square error | ||
278 | |||
279 | % estimated mean square error | ||
280 | 280 | fMSE=figure();hold on; | fMSE=figure();hold on; |
281 | 281 | ov = ones(NT,1); | ov = ones(NT,1); |
282 | 282 | plot(tvec,squeeze(tsMSE(1).yData(1,1,:)),tvec,squeeze(tsMSE(1).yData(2,2,:)),tvec,squeeze(tsMSE(1).yData(1,2,:))); % time-dependent | plot(tvec,squeeze(tsMSE(1).yData(1,1,:)),tvec,squeeze(tsMSE(1).yData(2,2,:)),tvec,squeeze(tsMSE(1).yData(1,2,:))); % time-dependent |
... | ... | if show_plots | |
290 | 290 | 't-dep actual MSE','t-dep actual MSE','t-dep actual MSE',... | 't-dep actual MSE','t-dep actual MSE','t-dep actual MSE',... |
291 | 291 | 'ss MSE','ss MSE','ss MSE',... | 'ss MSE','ss MSE','ss MSE',... |
292 | 292 | 'ss actual MSE','ss actual MSE','ss actual MSE') | 'ss actual MSE','ss actual MSE','ss actual MSE') |
293 | |||
293 | |||
294 | 294 | if export_pics | if export_pics |
295 | 295 | saveas(ftMSE,strcat(imagefilehead,'_ftMSE',imageft)); | saveas(ftMSE,strcat(imagefilehead,'_ftMSE',imageft)); |
296 | 296 | saveas(fzzpred,strcat(imagefilehead,'_fzzpred',imageft)); | saveas(fzzpred,strcat(imagefilehead,'_fzzpred',imageft)); |
297 | 297 | saveas(fMSE,strcat(imagefilehead,'_fMSE',imageft)); | saveas(fMSE,strcat(imagefilehead,'_fMSE',imageft)); |
298 | end | ||
298 | end | ||
299 | 299 | end | end |
300 | 300 | end | end |
301 | 301 |
File tests/kfcomparison_test.m changed (mode: 100644) (index ac8fa60..0cee07d) | |||
1 | 1 | % Kalmanfilter comparison: | % Kalmanfilter comparison: |
2 | % | ||
2 | % | ||
3 | 3 | % Compare different filters (kfss, kalman, kalmanfilter). | % Compare different filters (kfss, kalman, kalmanfilter). |
4 | 4 | % - kalman and kalmanfilter should be the same in steady-state (Note | % - kalman and kalmanfilter should be the same in steady-state (Note |
5 | 5 | % that kalman returns the prior estimation error while kalmanfilter | % that kalman returns the prior estimation error while kalmanfilter |
... | ... | end | |
68 | 68 | [kf2,~,Pss2] = kalman(sys,'current'); | [kf2,~,Pss2] = kalman(sys,'current'); |
69 | 69 | % compare prior error variances | % compare prior error variances |
70 | 70 | disp('filter steady state error variances') | disp('filter steady state error variances') |
71 | Pss1 - Pss2 | ||
71 | Pss1 - Pss2 | ||
72 | 72 | % apply filters to simulates timeseries and calculate errors | % apply filters to simulates timeseries and calculate errors |
73 | 73 | if isempty(u) | if isempty(u) |
74 | 74 | xest1 = lsim(kf1('StateEstimate','Measurement'),zvec,tvec,x0est); | xest1 = lsim(kf1('StateEstimate','Measurement'),zvec,tvec,x0est); |
File tests/montecarlo_test.m changed (mode: 100644) (index 3b5bd41..a5db4a5) | |||
... | ... | pss | |
50 | 50 | % $$$ neesAv = sum(nees); | % $$$ neesAv = sum(nees); |
51 | 51 | % $$$ neesTestF = @(x) chi2gof(x,'cdf',@(z)chi2cdf(z,NM*sn),'alpha',alpha); | % $$$ neesTestF = @(x) chi2gof(x,'cdf',@(z)chi2cdf(z,NM*sn),'alpha',alpha); |
52 | 52 | % $$$ [h,p] = neesTestF(neesAv) | % $$$ [h,p] = neesTestF(neesAv) |
53 | % $$$ | ||
53 | % $$$ | ||
54 | 54 | % $$$ figure; | % $$$ figure; |
55 | 55 | % $$$ xx=(0:1/NT:1)*60; | % $$$ xx=(0:1/NT:1)*60; |
56 | 56 | % $$$ cdfplot(neesAv);hold on; | % $$$ cdfplot(neesAv);hold on; |
File tests/qfactor_test.m changed (mode: 100644) (index b9cf64b..a88ecd6) | |||
1 | 1 | % Test Q-factor of sampled timeseries | % Test Q-factor of sampled timeseries |
2 | % | ||
2 | % | ||
3 | 3 | % Initial condition must be far out from equilibrium such that we can | % Initial condition must be far out from equilibrium such that we can |
4 | 4 | % actually see a real ringdown!! | % actually see a real ringdown!! |
5 | 5 |