|
| 1 | +classdef BeamformerInverter < inverse.CommonInverseParameters & handle |
| 2 | + |
| 3 | + % |
| 4 | + % BeamformerInverter |
| 5 | + % |
| 6 | + % A class which defines the properties needed for different types of |
| 7 | + % beamforming, and the method itself. |
| 8 | + % |
| 9 | + |
| 10 | + properties |
| 11 | + |
| 12 | + % |
| 13 | + %The inverse algorithm used. The options are currently: |
| 14 | + % - Linearly constrained minimum variance (LCMV) beamformer |
| 15 | + % - Unit noise gain (UNG) beamformer |
| 16 | + % - Unit-gain constrained beamformer |
| 17 | + % The last option is essentially UNG but beamformer-optimal, i.e., |
| 18 | + % maximal-signal-producing orientation is calculated first. |
| 19 | + % |
| 20 | + method_type (1,1) string { mustBeMember(method_type, ["Linearly constrained minimum variance (LCMV) beamformer", "Unit noise gain (UNG) beamformer", "Unit-gain constrained beamformer"]) } = "Linearly constrained minimum variance (LCMV) beamformer" |
| 21 | + |
| 22 | + % |
| 23 | + %The error covariance regularization parameter |
| 24 | + % |
| 25 | + cov_reg_parameter (1,1) double {mustBeNonnegative} = 0.05 |
| 26 | + |
| 27 | + % |
| 28 | + %The lead field regularization parameter |
| 29 | + % |
| 30 | + leadfield_reg_parameter (1,1) double {mustBeNonnegative} = 0.001 |
| 31 | + |
| 32 | + % |
| 33 | + %The leadfield regularization procedure |
| 34 | + % |
| 35 | + leadfield_reg_type (1,1) string { mustBeMember(leadfield_reg_type, ["Basic", "Pseudoinverse"]) } = "Basic" |
| 36 | + |
| 37 | + % |
| 38 | + %Lead field normalization strategy |
| 39 | + % |
| 40 | + leadfield_normalization (1,1) string { mustBeMember(leadfield_normalization, ["None", "Matrix norm", "Column norm", "Row norm"]) } = "None" |
| 41 | + |
| 42 | + % |
| 43 | + % Property to check if user has changed the error covariance by |
| 44 | + % hand |
| 45 | + % |
| 46 | + error_covSetted (1,1) {mustBeNumericOrLogical} = false |
| 47 | + |
| 48 | + % |
| 49 | + % Support variable to ensure that only user changed of error_cov |
| 50 | + % causes action. |
| 51 | + % |
| 52 | + computing_parameters (1,1) {mustBeNumericOrLogical} = false |
| 53 | + |
| 54 | + end % properties |
| 55 | + properties (SetObservable) |
| 56 | + |
| 57 | + % |
| 58 | + %The data error covariance matrix (optional) |
| 59 | + % |
| 60 | + error_cov = [] |
| 61 | + |
| 62 | + end %SetObservable properties |
| 63 | + |
| 64 | + methods |
| 65 | + |
| 66 | + function self = BeamformerInverter(args) |
| 67 | + |
| 68 | + % |
| 69 | + % BeamformerInverter |
| 70 | + % |
| 71 | + % The constructor for this class. |
| 72 | + % |
| 73 | + arguments |
| 74 | + |
| 75 | + args.method_type = "Linearly constrained minimum variance (LCMV) beamformer" |
| 76 | + |
| 77 | + args.cov_reg_parameter = 0.05 |
| 78 | + |
| 79 | + args.leadfield_reg_parameter = 0.001 |
| 80 | + |
| 81 | + args.reg_type = "Basic" |
| 82 | + |
| 83 | + args.error_cov = [] |
| 84 | + |
| 85 | + args.error_covSetted = false |
| 86 | + |
| 87 | + args.computing_parameters = false |
| 88 | + |
| 89 | + args.leadfield_normalization = "None" |
| 90 | + |
| 91 | + args.data_normalization_method = "Maximum entry" |
| 92 | + |
| 93 | + args.high_cut_frequency = 9 |
| 94 | + |
| 95 | + args.low_cut_frequency = 7 |
| 96 | + |
| 97 | + args.number_of_frames = 1 |
| 98 | + |
| 99 | + args.sampling_frequency = 1024 |
| 100 | + |
| 101 | + args.time_start = 0 |
| 102 | + |
| 103 | + args.time_window = 0 |
| 104 | + |
| 105 | + args.time_step = 1 |
| 106 | + |
| 107 | + end |
| 108 | + |
| 109 | + % Initialize superclass fields. |
| 110 | + |
| 111 | + |
| 112 | + "low_cut_frequency" ,args.low_cut_frequency, ... |
| 113 | + "high_cut_frequency", args.high_cut_frequency, ... |
| 114 | + "data_normalization_method", args.data_normalization_method, ... |
| 115 | + "number_of_frames", args.number_of_frames, ... |
| 116 | + "sampling_frequency", args.sampling_frequency, ... |
| 117 | + "time_start", args.time_start, ... |
| 118 | + "time_window", args.time_window, ... |
| 119 | + "time_step", args.time_step ... |
| 120 | + ); |
| 121 | + |
| 122 | + % Initialize own fields. |
| 123 | + |
| 124 | + self.method_type = args.method_type; |
| 125 | + |
| 126 | + self.leadfield_reg_type = args.reg_type; |
| 127 | + |
| 128 | + self.cov_reg_parameter = args.cov_reg_parameter; |
| 129 | + |
| 130 | + self.leadfield_reg_parameter = args.leadfield_reg_parameter; |
| 131 | + |
| 132 | + self.leadfield_normalization = args.leadfield_normalization; |
| 133 | + |
| 134 | + self.error_cov = args.error_cov; |
| 135 | + |
| 136 | + self.error_covSetted = args.error_covSetted; |
| 137 | + |
| 138 | + self.computing_parameters = args.computing_parameters; |
| 139 | + |
| 140 | + %Set listener for error_cov |
| 141 | + addlistener(self,'error_cov','PostSet',@(src,evnt)self.setEventsFlags(src,evnt,self)); |
| 142 | + |
| 143 | + end |
| 144 | + |
| 145 | + % Declare the initialize and inverse method defined in the files invert and initialize in this same |
| 146 | + % folder. |
| 147 | + |
| 148 | + self = initialize(self) |
| 149 | + |
| 150 | + [reconstruction, self] = invert(self, f, L, procFile, source_direction_mode) |
| 151 | + |
| 152 | + % Function that ZI runs after all inversions are done for each |
| 153 | + % desired time steps. With this function, one can reset the |
| 154 | + % variables and properties that has been changed during the |
| 155 | + % computing process |
| 156 | + |
| 157 | + function self = terminateComputation(self) |
| 158 | + %If the user has not given their own inversion parameters, we |
| 159 | + %reset the automatically computed parameters because the user |
| 160 | + %could change the data or model between separate runs. |
| 161 | + if not(self.error_covSetted) |
| 162 | + self.error_cov = []; |
| 163 | + end |
| 164 | + end |
| 165 | + |
| 166 | + end % methods |
| 167 | + |
| 168 | + methods (Static) |
| 169 | + %The function that is woken by listener when the value of theta or |
| 170 | + %noise_cov is changed to something else than empty by hand. |
| 171 | + % The function set the respective *Setted property value true when |
| 172 | + % value is changed. |
| 173 | + function setEventsFlags(src,evnt,self) %two first inputs must be there and have these dedicated roles. The third 'self' is an extra variable. |
| 174 | + if not(self.computing_parameters) |
| 175 | + if isempty(self.error_cov) |
| 176 | + self.error_covSetted = false; |
| 177 | + else |
| 178 | + self.error_covSetted = true; |
| 179 | + end |
| 180 | + end |
| 181 | + end % function |
| 182 | + end % static methods |
| 183 | + |
| 184 | +end % classdef |
0 commit comments