2 properties (SetAccess=
protected) % Read-only (can be changed only by a method)
7 PCol; % Power per column in signal field
10 properties (SetAccess=
protected,Hidden=
true)
16 if isfield(param,'Fc') && isscalar(param.Fc), obj.Fc = param.Fc; else obj.Fc = 1; end
17 if isfield(param,'Fs') && isscalar(param.Fs), obj.Fs = param.Fs; else
robolog('Sampling frequency must be specified','ERR'); end
18 if isfield(param,'Rs') && isscalar(param.Rs), obj.Rs = param.Rs; else obj.Rs = 1; end
23 if isfield(param, 'PCol')
24 if ~isa(param.PCol,'
pwr')
25 robolog('Power needs to be specified as
object of "
pwr" class.','ERR');
27 if numel(param.PCol) ~= size(obj.E, 2)
28 robolog('The number of "
pwr" objects in PCol must match the number of columns of the signal.', 'ERR');
30 obj.PCol = param.PCol;
33 elseif isfield(param,'P')
34 if ~isa(param.P,'
pwr')
35 robolog('Power needs to be specified as
object of "
pwr" class.','ERR');
37 if length(param.P) > 1
38 robolog('Power cannot be an array of "
pwr"
object. Use PCol instead.','ERR');
41 avpow =
pwr.meanpwr(signal);
42 pwrfraction = avpow/sum(avpow);
43 obj.PCol = repmat(obj.P, obj.N, 1).*pwrfraction;
45 robolog('Calculating power automatically - may be wrong', 'NFO0');
46 robolog(' Set power using
pwr object constructor:', 'NFO0');
48 robolog(' where SNR is in dB and Ptot is in dBm', 'NFO0');
50 avpow =
pwr.meanpwr(signal);
51 obj.PCol =
pwr(inf, {avpow(1),
'W'});
53 obj.PCol(jj) =
pwr(inf, {avpow(jj),
'W'});
57 %Check that user is not specifying properties that
do not exist
58 f = fieldnames(param);
59 props = {
'Fc',
'Fs',
'Rs',
'PCol',
'P'};
60 [~,ai,~] = intersect(f,props);
61 ai2 =
false(size(f)); ai2(ai)=
true; ai2=~ai2;
62 if any(ai2),
robolog(
'Following properties: %s are not used by signal_interface.',
'WRN', strjoin(strcat(
'''',f(ai2),''''),
', ')); end
67 function obj = fun1(obj,fun)
68 obj.enforceLhs(nargout);
69 s = cellfun(fun,mat2cell(get(obj),obj.L,ones(1,obj.N)),'UniformOutput',false);
70 if ~all(cellfun(@(c)isequal(size(c),size(s{1})),s))
71 robolog(
'Outputs after fun1 have different lengths. Cannot concatenate.',
'ERR');
75 % WARNING: SNR is not updated
77 for i=1:length(obj.PCol)
78 PCol_new(i) =
pwr(obj.PCol(i).SNR, {Pout(i),
'W'});
84 function p = params(obj)
102 function obj = mtimes(obj,M)
106 if ~isequal(size(M),([obj.N obj.N]))
107 robolog('Jones matrix must be a NxN square matrix.','ERR');
110 Fnew=zeros(size(get(obj)));
111 Pscale=zeros(obj.N, 1);
113 Fnew(:,i) = get(obj)*M(i,:).';
114 Pscale(i) = norm(M(:,i), 2)^2;
118 obj.PCol = obj.PCol.*Pscale;
119 obj.P = setPtot(obj);
122 function Nss = Nss(obj)
123 % Oversampling rate of the signal
127 function Ts = Ts(obj)
128 % Sampling time of the signal
132 function Tb = Tb(obj)
133 % Symbol time of the signal
135 robolog('Don''t use Tb for symbol time. Use 1/Rs. This function will be soon removed','WRN');
138 function Pout = setPtot(obj)
140 for jj=2:numel(obj.PCol)
141 Pout = Pout + obj.PCol(jj);
145 function ind = end(obj, k, n)
159 function sref = subsref(obj,s)
162 sref = builtin('subsref',obj,s);
164 % If length(obj) > 1 obj is a vector fo
signal_interface and the builtin method should be
166 % length(s) <= 2 seems unuseful. Can be removed?
167 if length(s) <= 2 && length(obj) == 1
169 sref = builtin('subsref',EScaled,s);
172 sref = builtin('subsref',obj,s);
175 error('MYDataClass:subsref
',... 176 'Not a supported subscripted reference
') 180 function s = get(obj) 184 function s = getRaw(obj) 188 function s = getScaled(obj) 189 % Modified by Robert to include power scaling (28.08.2014). 191 Pin = pwr.meanpwr(s); 193 Pout(jj) = obj.PCol(jj).Ptot('W
'); 196 s = bsxfun(@times, s, sqrt(Pout./Pin)); 200 robolog('Cannot scale waveform with 0 power to %.2e W
','WRN
', Pout) 205 function s = getNormalized(obj) 206 snorm = obj.normalize(); 210 function sigout=normalize(obj) 212 s = s/sqrt(mean(pwr.meanpwr(s))); 213 sigout = set(obj, s); 216 function obj = plus(obj1,obj2) 218 param = struct('Fs
',obj1.Fs); 221 if param.Fs~=obj2.Fs || N~=obj2.N || L~=obj2.L 222 robolog('Sampling rate, and signal sizes of both signals must be equal.
','ERR
'); 226 robolog('Assuming symbol rate of the first signal (%sBd).
', 'WRN
', formatPrefixSI(param.Rs,'%1.1f
')); 228 param.PCol = obj1.PCol+obj2.PCol; %TEMPORARY - for SNR only; power should be calculated numerically b/c of coherence issues 233 param.Fc = (Fc1+Fc2)/2; 234 s1 = bsxfun(@times,getScaled(obj1),exp(2j*pi*(Fc1-param.Fc)/param.Fs*(0:L-1)'));
235 s2 = bsxfun(@times,getScaled(obj2),exp(2j*pi*(Fc2-param.Fc)/param.Fs*(0:L-1)
')); 241 avpower = pwr.meanpwr(s); 243 param.PCol(jj) = pwr(param.PCol(jj).SNR, {avpower(jj), 'W
'}); 246 obj = signal_interface(s,param); 247 obj.P = setPtot(obj); 250 function obj = truncate(obj, L) 251 obj.enforceLhs(nargout); 253 obj = set(obj, sig(1:L, :)); 256 function obj = combine(varargin) 257 obj=Combiner_v1.combine(varargin); 261 % Overload display function (for easy viewing in the console and 269 strFc = 'Undefined
'; 270 strWavelength = 'Undefined
'; 272 strFc = formatPrefixSI(obj.Fc,'%1.3f
'); 273 strWavelength = formatPrefixSI(const.c/obj.Fc,'%1.5f
'); 276 strRs = 'Undefined
'; 277 strTs = 'Undefined
'; 278 strNss = 'Undefined
'; 280 strRs = formatPrefixSI(obj.Rs,'%1.1f
'); 281 strTs = formatPrefixSI(1/obj.Rs,'%1.1f
'); 282 strNss = formatPrefixSI(obj.Nss,'%1.2f
'); 287 'Number of components: %d\n
'... 288 ' Sampling rate: %sHz (%ss)\n
'... 289 ' Symbol rate: %sBd (%ss)\n
'... 290 ' Oversampling ratio: %sSa/symbol\n
'... 291 ' Carrier frequency: %sHz (%sm)\n
'... 294 formatPrefixSI(obj.L,'%1.0f
'),... 296 formatPrefixSI(obj.Fs,'%1.2f
'),formatPrefixSI(obj.Ts,'%1.2f
'),... 299 strFc, strWavelength); 304 function obj = set(obj,varargin) 307 obj.enforceLhs(nargout); 308 if numel(varargin)==1 309 obj.E = varargin{1}; % TODO input checking --- can only be a matrix 310 if numel(obj.PCol)~=size(obj.E, 2) 311 robolog('The number of
"pwr" objects in PCol must match the number of columns of the signal.
', 'WRN
'); 312 robolog('Resetting quasi-arbitrarily. This warning will become an error in the future.
', 'WRN
'); 313 if numel(obj.PCol)>size(obj.E, 2); 314 obj.PCol = obj.PCol(1:size(obj.E, 2)); 316 obj.PCol = repmat(obj.P/obj.N, obj.N, 1); 318 obj.P = setPtot(obj); 322 obj.(varargin{2*i-1}) = varargin{2*i}; 323 if strcmp(varargin{2*i-1}, 'P
'), rescalePCol=1; end 324 if strcmp(varargin{2*i-1}, 'PCol
') 325 if numel(varargin{2*i}) ~= size(obj.E, 2) 326 robolog('The number of
"pwr" objects in PCol must match the number of columns of the signal.
', 'ERR
'); 332 robolog('Bad key-value pairs.
','ERR
'); 334 if rescaleP, obj.P = setPtot(obj); end 335 if rescalePCol, obj.PCol = repmat(obj.P/obj.N, obj.N, 1); end 336 if rescalePCol && rescaleP 337 robolog('Both power per column and total power were specified. Power per column takes precedence
') 343 methods (Access=private,Hidden,Static) 345 function enforceLhs(n,minimum) 346 %ENFORCELHS Enforces assignment on the LHS to a certain 352 robolog('When
using this method, you must ensure that LHS exists. Due to memory considerations, overwriting the original
object is recommended.
','ERR
'); Signal description class.
function P(in obj, in varargin)
Depreciated get for power.
function robolog(in msg, in varargin)
This function allows the user to print log messages in a standard way.
static function meanpwr(in x)
Mean signal power and energy.