Thanks for the good hints!
After debugging the code as suggested, so far I found one bug in my
coding:
if(bw == 0.0f){
if(swType > 1 && swType < 5){ bw = halfsq2;} // lp/hp
else if(swType == 5 || swType == 6){ bw = 0.9f;} // ls/hs
else if(swType == 7){ bw = 30.0f;} // notch
}
else{ <-- BUG (should be done for ls/hs types only)
bw /= 12.0f;
}
This change helped for issues above 70Hz but still issues below it. I just
need to debug some more.
Juha
_____________________________
Posted through www.DSPRelated.com
Reply by Tim Wescott●December 10, 20132013-12-10
On Tue, 10 Dec 2013 17:09:28 -0500, Randy Yates wrote:
> clay@claysturner.com writes:
>
>> On Tuesday, December 10, 2013 12:41:49 PM UTC-5, jtp_1960 wrote:
>>> Carification:
>>>
>>>
>>>
>>> >39Hz/0,502 -> sample 39 value = NaN
>>> >numerator=-1,33226762955019E-15
>>>
>>> >denominnator=1,4255263636187E-13
>>>
>>>
>>> >
>>> >39Hz/0,503 -> sample 39 value = -23,1945375055488
>>>
>>> >numerator=6,66133814775094E-16 denominnator=1,4388490399142E-13
>>>
>>>
>>> >
>>> >40Hz/0,504 -> sample 40 value = NaN
>>> >numerator=-6,66133814775094E-16
>>>
>>> >denominnator=1,58317803311547E-13
>>>
>>>
>>> >
>>> >In some cases there is INF instead of NaN
>>>
>>>
>>> >
>>> >sample 113 value = -INF numerator=0
>>> >denominnator=1,03672626039497E-12
>>>
>>>
>>>
>>> "value" is the magnitude (dB) got from 20*log10(sqrtl(numerator /
>>>
>>> denominator)).
>>>
>>>
>>>
>>> Looks like the NaN / INF is result from sqrtl() function
>>>
>>> sample 39 (39Hz)
>>>
>>> value = NaN
>>>
>>> numerator=-6,66133814775094E-16
>>>
>>> denominnator=3,574918139293E-14
>>>
>>> sqrtl(numerator/denominnator) = NaN
>>>
>>>
>>>
>>> Juha
>>>
>>>
>>>
>>>
>>>
>>> _____________________________
>>>
>>> Posted through www.DSPRelated.com
>>
>> Looks like you are trying to find the square root of a negative number.
>> The proper domain for the square root function is the non-negative
>> numbers.
>>
>> Clay
>
> Wups - didn't see this. Yeah, that would do it.
When you fix that, you may also want to note that
20 * log10(sqrtl(something))
is the same as
10 * log10(something)
You'll save some processing time...
--
Tim Wescott
Wescott Design Services
http://www.wescottdesign.com
Reply by Randy Yates●December 10, 20132013-12-10
clay@claysturner.com writes:
> On Tuesday, December 10, 2013 12:41:49 PM UTC-5, jtp_1960 wrote:
>> Carification:
>>
>>
>>
>> >39Hz/0,502 -> sample 39 value = NaN numerator=-1,33226762955019E-15
>>
>> >denominnator=1,4255263636187E-13
>>
>> >
>>
>> >39Hz/0,503 -> sample 39 value = -23,1945375055488
>>
>> >numerator=6,66133814775094E-16 denominnator=1,4388490399142E-13
>>
>> >
>>
>> >40Hz/0,504 -> sample 40 value = NaN numerator=-6,66133814775094E-16
>>
>> >denominnator=1,58317803311547E-13
>>
>> >
>>
>> >In some cases there is INF instead of NaN
>>
>> >
>>
>> >sample 113 value = -INF numerator=0 denominnator=1,03672626039497E-12
>>
>>
>>
>> "value" is the magnitude (dB) got from 20*log10(sqrtl(numerator /
>>
>> denominator)).
>>
>>
>>
>> Looks like the NaN / INF is result from sqrtl() function
>>
>> sample 39 (39Hz)
>>
>> value = NaN
>>
>> numerator=-6,66133814775094E-16
>>
>> denominnator=3,574918139293E-14
>>
>> sqrtl(numerator/denominnator) = NaN
>>
>>
>>
>> Juha
>>
>>
>>
>>
>>
>> _____________________________
>>
>> Posted through www.DSPRelated.com
>
> Looks like you are trying to find the square root of a negative number. The proper domain for the square root function is the non-negative numbers.
>
> Clay
Hi Juha,
I recently had a similar problem (I was using Octave) and it turned out
my filter was unstable (poles outside the unit circle).
I haven't dug through your code to check them, but you might want to.
--
Randy Yates
Digital Signal Labs
http://www.digitalsignallabs.com
Reply by ●December 10, 20132013-12-10
On Tuesday, December 10, 2013 12:41:49 PM UTC-5, jtp_1960 wrote:
> Carification:
>
>
>
> >39Hz/0,502 -> sample 39 value = NaN numerator=-1,33226762955019E-15
>
> >denominnator=1,4255263636187E-13
>
> >
>
> >39Hz/0,503 -> sample 39 value = -23,1945375055488
>
> >numerator=6,66133814775094E-16 denominnator=1,4388490399142E-13
>
> >
>
> >40Hz/0,504 -> sample 40 value = NaN numerator=-6,66133814775094E-16
>
> >denominnator=1,58317803311547E-13
>
> >
>
> >In some cases there is INF instead of NaN
>
> >
>
> >sample 113 value = -INF numerator=0 denominnator=1,03672626039497E-12
>
>
>
> "value" is the magnitude (dB) got from 20*log10(sqrtl(numerator /
>
> denominator)).
>
>
>
> Looks like the NaN / INF is result from sqrtl() function
>
> sample 39 (39Hz)
>
> value = NaN
>
> numerator=-6,66133814775094E-16
>
> denominnator=3,574918139293E-14
>
> sqrtl(numerator/denominnator) = NaN
>
>
>
> Juha
>
>
>
>
>
> _____________________________
>
> Posted through www.DSPRelated.com
Looks like you are trying to find the square root of a negative number. The proper domain for the square root function is the non-negative numbers.
Clay
Reply by jtp_1960●December 10, 20132013-12-10
Carification:
>39Hz/0,502 -> sample 39 value = NaN numerator=-1,33226762955019E-15
>denominnator=1,4255263636187E-13
>
>39Hz/0,503 -> sample 39 value = -23,1945375055488
>numerator=6,66133814775094E-16 denominnator=1,4388490399142E-13
>
>40Hz/0,504 -> sample 40 value = NaN numerator=-6,66133814775094E-16
>denominnator=1,58317803311547E-13
>
>In some cases there is INF instead of NaN
>
>sample 113 value = -INF numerator=0 denominnator=1,03672626039497E-12
"value" is the magnitude (dB) got from 20*log10(sqrtl(numerator /
denominator)).
Looks like the NaN / INF is result from sqrtl() function
sample 39 (39Hz)
value = NaN
numerator=-6,66133814775094E-16
denominnator=3,574918139293E-14
sqrtl(numerator/denominnator) = NaN
Juha
_____________________________
Posted through www.DSPRelated.com
Reply by jtp_1960●December 10, 20132013-12-10
>On 12/10/13 8:20 AM, jtp_1960 wrote:
>> Hello!
>>
>> I have an issue with a Notch filter which works OK for certain Hz/bw/Q
but
>> after changing Hz or bw/Q sometimes a NaN value is given for the sample
>> 2.0L*coefficient[s].a2*cosl(2.0L*w);
>> magnitude = 20*log10(sqrtl(numerator / denominator));
>>
>> ..
>>
>>
>> Is there something wrong in source code or is there other factors
>> involved?
>>
>
>exactly what variable becomes a NaN?
>
>
>--
>
>r b-j rbj@audioimagination.com
>
>"Imagination is more important than knowledge."
>
>
>
39Hz/0,502 -> sample 39 value = NaN numerator=-1,33226762955019E-15
denominnator=1,4255263636187E-13
39Hz/0,503 -> sample 39 value = -23,1945375055488
numerator=6,66133814775094E-16 denominnator=1,4388490399142E-13
40Hz/0,504 -> sample 40 value = NaN numerator=-6,66133814775094E-16
denominnator=1,58317803311547E-13
In some cases there is INF instead of NaN
sample 113 value = -INF numerator=0 denominnator=1,03672626039497E-12
Juha
_____________________________
Posted through www.DSPRelated.com
Reply by jtp_1960●December 10, 20132013-12-10
>On 12/10/13 8:20 AM, jtp_1960 wrote:
>> Hello!
>>
>> I have an issue with a Notch filter which works OK for certain Hz/bw/Q
but
>> after changing Hz or bw/Q sometimes a NaN value is given for the sample
>> 2.0L*coefficient[s].a2*cosl(2.0L*w);
>> magnitude = 20*log10(sqrtl(numerator / denominator));
>>
>> ..
>>
>>
>> Is there something wrong in source code or is there other factors
>> involved?
>>
>
>exactly what variable becomes a NaN?
>
>
>--
>
>r b-j rbj@audioimagination.com
>
>"Imagination is more important than knowledge."
>
>
>
39Hz/0,502 -> sample 39
value = NaN
numerator=-1,33226762955019E-15
enominnator=1,4255263636187E-13
39Hz/0,503 -> sample 39 value = -23,1945375055488
numerator=6,66133814775094E-16 denominnator=1,4388490399142E-13
40Hz/0,504 -> sample 40 value = NaN numerator=-6,66133814775094E-16
denominnator=1,58317803311547E-13
_____________________________
Posted through www.DSPRelated.com
Reply by ●December 10, 20132013-12-10
On Tuesday, December 10, 2013 8:20:19 AM UTC-5, jtp_1960 wrote:
I havn't "dug" through your code, but when a NAN ("Not A Number") shows up, you have likely divided by zero or attempted to perform a calculation with a number not in the domain of the function causing the issue. The "zero" doesn't have to be exactly zero but can be an extremely small number resulting from the differencing of two similarly valued numbers. Since you know the frequency that makes it blow up, just trace the code as it processes the data. This should point you towards the problem.
IHTH,
Clay
Reply by robert bristow-johnson●December 10, 20132013-12-10