Wolfgang,
The value in question should actually be a ration of two values, i.e., a
relative measure. Technically, a ratio of two powers, the formula being
10 * log10 (P1/P2). This is the "Power" version of the formula, and I'm
guessing the value input is P1/P2. For reference, at half power one
commonly says "3 db down", meaning 10*log10(0.5) is approximately -3 db.
In circuit analysis, power is P = I * V = V/R * V = V^2/R. So if the
input option is "Voltage", then the formula becomes 10 * log10
(V1^2/V2^2) = 20 * log10 (V1/V2), and I'm guessing the value input is
V1/V2. (Note how the resistance R cancels out.)
Resistance value? Got me. Perhaps it is in reference to some kind of
absolute value? 10 * log10 (V^2 / R) maybe, where V is now the input
value. I'm just guessing on that one... I just looked at your
implementation and what I said agrees with what you have:
10 * log10 (V^2 / R) = 10*log10(V^2) - 10*log10(R)
= 20*log10(V) - 10*log10(R)
One thing I question is forcing the resistance value to be R = 1 in the
case the user enters one of the "power" string qualifiers. That type of
behavior (ignoring the value of R) should be documented, otherwise it
can trip users up. Couldn't you replace
R = 1; % Ignore any value for R
with
if (nargin == 3)
error('Resistance value is insignificant when power specified.');
or something similar?
Another question is whether the order of the options must be unit string
followed by resistance value. If that is your preference that is fine,
but there is no ambiguity with, say, db(5, 50, 'Voltage') versus db(5,
'Voltage', 50). The only rule being that the resistance value follows
the voltage value.
Also, in the case of bad inputs, your routine is returning without
defining the returning value. Isn't that considered an error by the
interpreter? Or is that what you are intending?
I'm also slightly confused why "Voltage" should be the default for a
routine which is by definition a ration of two powers, unless perhaps
this routine is very circuits oriented in which case working with
"voltage gains" is more common.
Dan
On 04/26/2011 06:00 AM, Wolfgang Wallner wrote:
>
> Hello Octave-Community,
>
> I was trying to get some Matlab scripts to work, however, I failed,
> because of the missing function db().
>
> db() is part of the "Signal Processing" toolbox in Matlab, and it converts
> a value to decibel.
> Additionally, it takes optional arguments for mode selection ('Voltage' or
> 'Power'), and a Resistor value.
>
> This is what db() is described in MatLab:
> http://pastebin.com/hGV6ZJnv
>
> I tried to re-implement the function, which looks like this:
>
> http://pastebin.com/dBKXqt3W
>
> This primitive re-implementation lacks some features (usage message, more
> error checking), but it works fine for me.
> However, maybe there are other people missing this function, and it would
> be nice if an implementation of db() would be a part of octave's signal
> processing package?
>
> Kind regards,
> Wolfgang Wallner
>
> PS: I tried to get more information about db() on the internet, but I
> could not find anything.
> It is also not in the function list of the Signal Processing toolbox
> (http://www.mathworks.com/help/toolbox/signal/f9-131178c.html).
> This is strange. However, on my Matlab installation, it is in
> "toolbox/signal/signal/db.m".
>
> ------------------------------------------------------------------------------
> WhatsUp Gold - Download Free Network Management Software
> The most intuitive, comprehensive, and cost-effective network
> management toolset available today. Delivers lowest initial
> acquisition cost and overall TCO of any competing solution.
> http://p.sf.net/sfu/whatsupgold-sd
> _______________________________________________
> Octave-dev mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/octave-dev
>
--
Dan Sebald
email: daniel(DOT)sebald(AT)ieee(DOT)org
URL: http://www(DOT)dansebald(DOT)com
------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network
management toolset available today. Delivers lowest initial
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
_______________________________________________
Octave-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/octave-dev