From: Raeldor on
On Jul 26, 4:23 pm, Tim Wescott <t...(a)seemywebsite.com> wrote:
> On 07/26/2010 02:19 PM, Raeldor wrote:
>
>
>
>
>
> > On Jul 26, 1:56 pm, Jerry Avins<j...(a)ieee.org>  wrote:
> >> On 7/26/2010 4:43 PM, Tim Wescott wrote:
>
> >>> On 07/26/2010 01:07 PM, Raeldor wrote:
>
> >>     ...
>
> >>>> Thank you both for your explanations. Looks like i have some more
> >>>> reading to do! :) Is there a standard formula to convert the returned
> >>>> values into decibels?
>
> >>> Yes. The FFT returns complex numbers (or phasors, depending on where you
> >>> learned this stuff). For your purposes, they're a number pair (a, b),
> >>> where the estimated signal for that particular frequency bin is a *
> >>> cos(w*t) + b * sin(w*t), w = 2 * pi * frequency. The magnitude of the
> >>> signal is sqrt(a^2 + b^2); to convert that to Decibels you need to take
> >>> the logarithm to the base 10 of the magnitude, and multiply by 20, then
> >>> add a constant to take the effect of all the gains in your system into
> >>> account:
>
> >>> mag(dB) = 20 * log(sqrt(a^2 + b^2)), or if you know your logarithms:
> >>> mag(dB) = 10 * log(a^2 + b^2).
>
> >> Plus an additive constant to set the scale. When the constant is zero,
> >> a^2 + b^2 = 1 becomes 0 dB.
>
> >> Jerry
> >> --
> >> Engineering is the art of making what you want from things you can get..
> >> ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
>
> > Thank you.  So if I'm just interested in a 'loudness' or magnitude and
> > am not worried about whether it is decibels, I can just use the
> > sqrt(a^2*b^2)?  I tried it, and for some numbers it's retuning NaN
> > (not a number).  I'm populating it with a sample squaretooth wave,
> > could that results in NaN for some frequency bins?
>
> You want an add inside the square root, not a multiply.  But yes, that
> should work -- even with a multiply it should give a wrong number but
> not an NaN.  Sumpin's wrong...
>
> The dB scale was invented to mimic our perception of sound level: one
> 'Bell' is roughly equivalent to "that sounds about twice as loud".  So
> displaying sound levels in dB is a pretty good match for what a listener
> would perceive.
>
> --
>
> Tim Wescott
> Wescott Design Serviceshttp://www.wescottdesign.com
>
> Do you need to implement control loops in software?
> "Applied Control Theory for Embedded Systems" was written for you.
> See details athttp://www.wescottdesign.com/actfes/actfes.html

Sorry, that was a coding error I'm getting real numbers now each
time. It's starting to look a bit more meaningful though. If I use
just sqrt(a^2+b^2) then I get a peak a what looks like the base
frequency, plus smaller descending peaks at what look like the
harmonics. However, if I modify to be 10*log(sqrt(a^2+b^2)) then it
looks a little different... I still get the same number of peaks at
the same positions, but there is a curved run-up and drop-off to the
peak (sorry, I'm sure there's probably a technical term for
this! :P). Is this just a effect of the decibel scale being more
sensitive at lower amplitudes?

Thanks again
Ray
From: Tim Wescott on
On 07/26/2010 08:44 PM, Raeldor wrote:
> On Jul 26, 4:23 pm, Tim Wescott<t...(a)seemywebsite.com> wrote:
>> On 07/26/2010 02:19 PM, Raeldor wrote:
>>
>>
>>
>>
>>
>>> On Jul 26, 1:56 pm, Jerry Avins<j...(a)ieee.org> wrote:
>>>> On 7/26/2010 4:43 PM, Tim Wescott wrote:
>>
>>>>> On 07/26/2010 01:07 PM, Raeldor wrote:
>>
>>>> ...
>>
>>>>>> Thank you both for your explanations. Looks like i have some more
>>>>>> reading to do! :) Is there a standard formula to convert the returned
>>>>>> values into decibels?
>>
>>>>> Yes. The FFT returns complex numbers (or phasors, depending on where you
>>>>> learned this stuff). For your purposes, they're a number pair (a, b),
>>>>> where the estimated signal for that particular frequency bin is a *
>>>>> cos(w*t) + b * sin(w*t), w = 2 * pi * frequency. The magnitude of the
>>>>> signal is sqrt(a^2 + b^2); to convert that to Decibels you need to take
>>>>> the logarithm to the base 10 of the magnitude, and multiply by 20, then
>>>>> add a constant to take the effect of all the gains in your system into
>>>>> account:
>>
>>>>> mag(dB) = 20 * log(sqrt(a^2 + b^2)), or if you know your logarithms:
>>>>> mag(dB) = 10 * log(a^2 + b^2).
>>
>>>> Plus an additive constant to set the scale. When the constant is zero,
>>>> a^2 + b^2 = 1 becomes 0 dB.
>>
>>>> Jerry
>>>> --
>>>> Engineering is the art of making what you want from things you can get.
>>>> �����������������������������������������������������������������������
>>
>>> Thank you. So if I'm just interested in a 'loudness' or magnitude and
>>> am not worried about whether it is decibels, I can just use the
>>> sqrt(a^2*b^2)? I tried it, and for some numbers it's retuning NaN
>>> (not a number). I'm populating it with a sample squaretooth wave,
>>> could that results in NaN for some frequency bins?
>>
>> You want an add inside the square root, not a multiply. But yes, that
>> should work -- even with a multiply it should give a wrong number but
>> not an NaN. Sumpin's wrong...
>>
>> The dB scale was invented to mimic our perception of sound level: one
>> 'Bell' is roughly equivalent to "that sounds about twice as loud". So
>> displaying sound levels in dB is a pretty good match for what a listener
>> would perceive.
>>
>> --
>>
>> Tim Wescott
>> Wescott Design Serviceshttp://www.wescottdesign.com
>>
>> Do you need to implement control loops in software?
>> "Applied Control Theory for Embedded Systems" was written for you.
>> See details athttp://www.wescottdesign.com/actfes/actfes.html
>
> Sorry, that was a coding error I'm getting real numbers now each
> time. It's starting to look a bit more meaningful though. If I use
> just sqrt(a^2+b^2) then I get a peak a what looks like the base
> frequency, plus smaller descending peaks at what look like the
> harmonics. However, if I modify to be 10*log(sqrt(a^2+b^2)) then it
> looks a little different... I still get the same number of peaks at
> the same positions, but there is a curved run-up and drop-off to the
> peak (sorry, I'm sure there's probably a technical term for
> this! :P).

> Is this just a effect of the decibel scale being more
> sensitive at lower amplitudes?

Yes -- the run up and run down are still there in the linear magnitude
plot, they're just not apparent.

--

Tim Wescott
Wescott Design Services
http://www.wescottdesign.com

Do you need to implement control loops in software?
"Applied Control Theory for Embedded Systems" was written for you.
See details at http://www.wescottdesign.com/actfes/actfes.html
From: Dirk Bell on
On Jul 26, 11:44 pm, Raeldor <rael...(a)gmail.com> wrote:
> On Jul 26, 4:23 pm, Tim Wescott <t...(a)seemywebsite.com> wrote:
>
>
>
>
>
> > On 07/26/2010 02:19 PM, Raeldor wrote:
>
> > > On Jul 26, 1:56 pm, Jerry Avins<j...(a)ieee.org>  wrote:
> > >> On 7/26/2010 4:43 PM, Tim Wescott wrote:
>
> > >>> On 07/26/2010 01:07 PM, Raeldor wrote:
>
> > >>     ...
>
> > >>>> Thank you both for your explanations. Looks like i have some more
> > >>>> reading to do! :) Is there a standard formula to convert the returned
> > >>>> values into decibels?
>
> > >>> Yes. The FFT returns complex numbers (or phasors, depending on where you
> > >>> learned this stuff). For your purposes, they're a number pair (a, b),
> > >>> where the estimated signal for that particular frequency bin is a *
> > >>> cos(w*t) + b * sin(w*t), w = 2 * pi * frequency. The magnitude of the
> > >>> signal is sqrt(a^2 + b^2); to convert that to Decibels you need to take
> > >>> the logarithm to the base 10 of the magnitude, and multiply by 20, then
> > >>> add a constant to take the effect of all the gains in your system into
> > >>> account:
>
> > >>> mag(dB) = 20 * log(sqrt(a^2 + b^2)), or if you know your logarithms:
> > >>> mag(dB) = 10 * log(a^2 + b^2).
>
> > >> Plus an additive constant to set the scale. When the constant is zero,
> > >> a^2 + b^2 = 1 becomes 0 dB.
>
> > >> Jerry
> > >> --
> > >> Engineering is the art of making what you want from things you can get.
> > >> ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
>
> > > Thank you.  So if I'm just interested in a 'loudness' or magnitude and
> > > am not worried about whether it is decibels, I can just use the
> > > sqrt(a^2*b^2)?  I tried it, and for some numbers it's retuning NaN
> > > (not a number).  I'm populating it with a sample squaretooth wave,
> > > could that results in NaN for some frequency bins?
>
> > You want an add inside the square root, not a multiply.  But yes, that
> > should work -- even with a multiply it should give a wrong number but
> > not an NaN.  Sumpin's wrong...
>
> > The dB scale was invented to mimic our perception of sound level: one
> > 'Bell' is roughly equivalent to "that sounds about twice as loud".  So
> > displaying sound levels in dB is a pretty good match for what a listener
> > would perceive.
>
> > --
>
> > Tim Wescott
> > Wescott Design Serviceshttp://www.wescottdesign.com
>
> > Do you need to implement control loops in software?
> > "Applied Control Theory for Embedded Systems" was written for you.
> > See details athttp://www.wescottdesign.com/actfes/actfes.html
>
> Sorry, that was a coding error I'm getting real numbers now each
> time.  It's starting to look a bit more meaningful though.  If I use
> just sqrt(a^2+b^2) then I get a peak a what looks like the base
> frequency, plus smaller descending peaks at what look like the
> harmonics.  However, if I modify to be 10*log(sqrt(a^2+b^2)) then it
> looks a little different... I still get the same number of peaks at
> the same positions, but there is a curved run-up and drop-off to the
> peak (sorry, I'm sure there's probably a technical term for
> this! :P).  Is this just a effect of the decibel scale being more
> sensitive at lower amplitudes?
>
> Thanks again
> Ray- Hide quoted text -
>
> - Show quoted text -

Use 20, instead of 10, in your deciBel equation

OR

Use 10, but drop the sqrt in the log().

Dirk
From: Raeldor on
On Jul 27, 7:26 am, Dirk Bell <bellda2...(a)cox.net> wrote:
> On Jul 26, 11:44 pm, Raeldor <rael...(a)gmail.com> wrote:
>
>
>
>
>
> > On Jul 26, 4:23 pm, Tim Wescott <t...(a)seemywebsite.com> wrote:
>
> > > On 07/26/2010 02:19 PM, Raeldor wrote:
>
> > > > On Jul 26, 1:56 pm, Jerry Avins<j...(a)ieee.org>  wrote:
> > > >> On 7/26/2010 4:43 PM, Tim Wescott wrote:
>
> > > >>> On 07/26/2010 01:07 PM, Raeldor wrote:
>
> > > >>     ...
>
> > > >>>> Thank you both for your explanations. Looks like i have some more
> > > >>>> reading to do! :) Is there a standard formula to convert the returned
> > > >>>> values into decibels?
>
> > > >>> Yes. The FFT returns complex numbers (or phasors, depending on where you
> > > >>> learned this stuff). For your purposes, they're a number pair (a, b),
> > > >>> where the estimated signal for that particular frequency bin is a *
> > > >>> cos(w*t) + b * sin(w*t), w = 2 * pi * frequency. The magnitude of the
> > > >>> signal is sqrt(a^2 + b^2); to convert that to Decibels you need to take
> > > >>> the logarithm to the base 10 of the magnitude, and multiply by 20, then
> > > >>> add a constant to take the effect of all the gains in your system into
> > > >>> account:
>
> > > >>> mag(dB) = 20 * log(sqrt(a^2 + b^2)), or if you know your logarithms:
> > > >>> mag(dB) = 10 * log(a^2 + b^2).
>
> > > >> Plus an additive constant to set the scale. When the constant is zero,
> > > >> a^2 + b^2 = 1 becomes 0 dB.
>
> > > >> Jerry
> > > >> --
> > > >> Engineering is the art of making what you want from things you can get.
> > > >> ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
>
> > > > Thank you.  So if I'm just interested in a 'loudness' or magnitude and
> > > > am not worried about whether it is decibels, I can just use the
> > > > sqrt(a^2*b^2)?  I tried it, and for some numbers it's retuning NaN
> > > > (not a number).  I'm populating it with a sample squaretooth wave,
> > > > could that results in NaN for some frequency bins?
>
> > > You want an add inside the square root, not a multiply.  But yes, that
> > > should work -- even with a multiply it should give a wrong number but
> > > not an NaN.  Sumpin's wrong...
>
> > > The dB scale was invented to mimic our perception of sound level: one
> > > 'Bell' is roughly equivalent to "that sounds about twice as loud".  So
> > > displaying sound levels in dB is a pretty good match for what a listener
> > > would perceive.
>
> > > --
>
> > > Tim Wescott
> > > Wescott Design Serviceshttp://www.wescottdesign.com
>
> > > Do you need to implement control loops in software?
> > > "Applied Control Theory for Embedded Systems" was written for you.
> > > See details athttp://www.wescottdesign.com/actfes/actfes.html
>
> > Sorry, that was a coding error I'm getting real numbers now each
> > time.  It's starting to look a bit more meaningful though.  If I use
> > just sqrt(a^2+b^2) then I get a peak a what looks like the base
> > frequency, plus smaller descending peaks at what look like the
> > harmonics.  However, if I modify to be 10*log(sqrt(a^2+b^2)) then it
> > looks a little different... I still get the same number of peaks at
> > the same positions, but there is a curved run-up and drop-off to the
> > peak (sorry, I'm sure there's probably a technical term for
> > this! :P).  Is this just a effect of the decibel scale being more
> > sensitive at lower amplitudes?
>
> > Thanks again
> > Ray- Hide quoted text -
>
> > - Show quoted text -
>
> Use 20, instead of 10, in your deciBel equation
>
> OR
>
> Use 10, but drop the sqrt in the log().
>
> Dirk

You guys are awesome, thank you. I've been playing with the decibel
vs the linear, and I think the linear will work best for my purposes.
Question is... is there a way to restrain or normalize the values
between say 0.0 and 1.0?

Thanks
Ray
First  |  Prev  | 
Pages: 1 2 3
Prev: Fftw for TS101.
Next: IMBECILE::Re: FFT Questions