3 properties (SetAccess=immutable,Hidden=
true)
8 methods (Access=private,Hidden=true,Static=true)
10 function res = validpwr(P)
12 if isscalar(P) && isreal(P), res = true; end
15 function P_format = outputP(P_dBW,varargin)
16 type = defaultargs('dBm',varargin{:});
21 P_format =
dB2lin(P_dBW)*1e3;
23 P_format =
dB2lin(P_dBW)*1e6;
31 error('Power
unit can be W, mW, uW, dBW, dBm or dBu.');
35 function SNR_format = outputSNR(SNR_dB,varargin)
36 type = defaultargs('dB',varargin{:});
39 SNR_format =
dB2lin(SNR_dB);
43 error(
'SNR unit can be lin for linear or dB.');
47 function P_dB = inputP(P)
50 elseif iscell(P) && numel(P)==2 &&
pwr.
validpwr(P{1}) && ischar(P{2})
54 error(
'Power must be specified as a real scalar (in dBm) or a cell array must be constructed as {value,unit}');
70 error(
'Power unit can be W, mW, uW, dBW, dBm or dBu.');
74 function SNR_dB = inputSNR(SNR)
77 elseif iscell(SNR) && numel(SNR)==2 &&
pwr.
validpwr(SNR{1}) && ischar(SNR{2})
81 error(
'SNR must be specified as a real scalar (in dB) or a cell array must be constructed as {value,unit}.');
89 error(
'SNR unit can be lin for linear or dB.');
99 function [y,scfactor] = normpwr(x,varargin)
100 [type,P,
unit] = defaultargs({
'average',1,
'linear'},varargin);
103 case {
'linear',
'lin'}
113 error(
'Unit must be ''linear'', ''dB'' or ''dBm''.');
116 % TODO Handling real and complex cases
119 case {
'average',
'avg'}
122 case {
'maximum',
'max'}
123 scfactor = Prange(2,:)/P_;
126 error(
'Normalization type must be ''average'' or ''maximum''.');
129 % y = bsxfun(@mrdivide,x,sqrt(scfactor));
130 y = x/sqrt(scfactor);
133 function [P,E,Prange,Ppeak] = meanpwr(x)
141 absxsq = x.*conj(x); %faster
151 function OSNR = getOSNR(sig, varargin)
158 robolog(
'The signal carrier frequency is required to compute the noise bandwidth',
'ERR');
160 lambda =
const.c/sig.Fc;
161 NBW_Hz =
const.c./(lambda-.5*1e-9*NBW)-
const.c./(lambda+.5*1e-9*NBW);
162 OSNR_dB = sig.P.SNR+10*log10(sig.Fs/NBW_Hz);
174 function obj =
pwr(SNR,P)
176 error(
'Signal-to-noise ratio must be specified.');
184 function obj = plus_1elem(obj1,obj2)
185 Ps = obj1.Ps(
'W')+obj2.Ps(
'W');
186 Pn = obj1.Pn(
'W')+obj2.Pn(
'W');
187 %zero total power is a special
case 188 if isinf(log10(Ps))&&isinf(log10(Pn))
191 obj =
pwr({Ps/Pn,
'lin'},{Ps+Pn,
'W'});
195 function obj = plus(obj1, obj2)
196 if numel(obj1)~=numel(obj2)
197 error(
'When adding two power object arrays, number of elements in array 1 must equal number of elements in array 2');
199 obj = plus_1elem(obj1(1), obj2(1));
201 obj(jj) = plus_1elem(obj1(jj), obj2(jj));
206 function obj = minus(obj1,obj2)
207 warning(
'Subtraction is equivalent to addition -- no correlation.')
208 obj = plus(obj1,obj2);
211 function obj = mtimes(in1,in2)
212 if isa(in1,
'pwr')&&~isa(in2,
'pwr')
213 Ps =
dB2lin([in1.P_dBW])*in2;
215 elseif ~isa(in1,
'pwr')&&isa(in2,
'pwr')
216 Ps = in1*
dB2lin([in2.P_dBW]);
220 obj(jj) =
pwr(SNR(jj), {Ps(jj),
'W'});
224 function obj = times(in1, in2)
225 if numel(in1)==numel(in2)
226 for jj=1:numel(in1), obj(jj) = in1(jj)*in2(jj); end
227 elseif (numel(in1)==1)||(numel(in2)==1)
229 for jj=1:numel(in2), obj(jj) = in1*in2(jj); end
231 for jj=1:numel(in1), obj(jj) = in1(jj)*in2; end
234 error(
'Matrix dimensions must agree');
238 function obj = mrdivide(in1, C)
239 obj = mtimes(in1, 1/C);
242 function P = P(obj,varargin)
243 warning(
'Please use Ptot instead of P function of pwr.');
244 P = Ptot(obj,varargin{:});
247 function SNR = SNR(obj,varargin)
251 function Ptot = Ptot(obj,varargin)
255 function Ps = Ps(obj,varargin)
256 if isinf(obj.SNR(
'lin')) % If SNR is infinite, there is no noise, so Ps = P;
257 Ps = obj.Ptot(
'dBW');
259 Ps = obj.Ptot(
'dBW')+obj.SNR(
'dB')-10*log10(obj.SNR(
'lin')+1);
264 function Pn = Pn(obj,varargin)
265 Pn =
pwr.
outputP(obj.Ptot(
'dBW')-10*log10(obj.SNR(
'lin')+1),varargin);
268 function obj = disp(obj)
269 % Space pad differently to show single power
object 276 print_obj = @(obj)fprintf(1,
'%s Total power: %1.2f dBm (%1.2f mW)\n%s SNR: %1.2f dB (%1.2f)\n%s Signal power: %1.2f dBm (%1.2f mW)\n%s Noise power: %1.2f dBm (%1.2f mW)\n',...
277 spacePad,obj.Ptot(
'dBm'),obj.Ptot(
'mW'),spacePad,obj.SNR(
'dB'),obj.SNR(
'lin'),spacePad,obj.Ps(
'dBm'),obj.Ps(
'mW'),spacePad,obj.Pn(
'dBm'),obj.Pn(
'mW'));
281 % Used when we want to print PCol (array of
pwr objects)
283 fprintf(1,
'Power in signal %d:\n', jj);
static function inputSNR(in SNR)
Parse format to set SNR.
Superclass: basic building block to hold functions.
function findrange(in x)
Finds min-max range of a vector/matrix.
static function outputP(in P_dBW, in varargin)
Parse format to get power.
static function outputSNR(in SNR_dB, in varargin)
Parse format to get SNR.
function lin2dB(in lin, in varargin)
Convert linear units to dB.
static function validpwr(in P)
validate power
function robolog(in msg, in varargin)
This function allows the user to print log messages in a standard way.
static function inputP(in P)
Parse format to set power.
static function meanpwr(in x)
Mean signal power and energy.
function dB2lin(in dB, in varargin)
Convert dB to linear units.