Hello Jeff,

thank you for answering. And Carnë, thank you too.

I don't realize what's the problem with the number of coefficients at the
moment. Please, let me think about it.

However, you are right about that sentence about Matlab's normalization.
Matlab's help on fir1 says so. But in fact that's not the actual behaviour
of the function if you look at the code (or maybe it is, if you consider
the periodic nature of the discrete filter frequency response when looking
for the center frequencies of the bands). Anyway, attached is a patch with
the actual behavior (if I'm not wrong; it still needs thoroughly testing).
It's all briefly explained in the comments.

Regards

Alberto

2011/11/8 Jeffrey Cunningham <jeff...@jkcunningham.com>

> On Mon, 07 Nov 2011 17:48:51 -0800, Carnë Draug <carandraug+...@gmail.com>
> wrote:
>
>  On 7 November 2011 22:42, Jeffrey Cunningham <jeff...@jkcunningham.com>
>>
>>>
>>> Are you sure it is a bug? I am assuming that you want the filter to be
>>> normalized the same way as Matlab's fir1 function, and they say:
>>>
>>>  "By default, the filter is scaled so that the center of the first
>>> passband
>>> has a magnitude of exactly 1 after windowing."
>>>
>>> In other words, they are normalizing so the *frequency domain* passband
>>> comes out to 1. The d.c. output level divided by the bandwidth will be
>>> (roughly) 1.
>>>
>>
>> I asked in ##matlab and it seems it returns exactly 1 there.
>>
>> Carnė
>>
>
>
> Right. I don't know what I was thinking of: The dc level is the sum of the
> weights.
> But I'm not seeing a problem. Here's a low-pass fir1 filter:
>
>  b = fir1(48,[0,0.35]);
>  sum(b) => 1.005
>
> freqz shows unity gain in the passband. And I can drive it with a unit
> gain d.c. voltage and after it stops ringing I get unity output.
>
>  c=filter(b,1,ones(520,1))(end) ==> 1.005
>
> I think I see what his trouble is. He doesn't have nearly enough
> coefficients for a low-pass filter that narrow. Its a bad fit to an
> impulse-function.
>
> octave:17> version
> ans = 3.2.4
> octave:19> sum(fir1(240,0.01))
> ans =  1.1822
> octave:20> sum(fir1(512,0.01))
> ans =  1.0804
> octave:21> sum(fir1(10000,0.01))
> ans =  0.99934
>
>
> Jeff
>
--- fir1.m.1_1_1	2011-09-29 19:19:30.000000000 +0200
+++ fir1.m	2011-11-07 21:36:52.000000000 +0100
@@ -110,9 +110,18 @@
 
   ## normalize filter magnitude
   if scale == 1
-    ## find the middle of the first band edge
-    if m(1) == 1, w_o = (f(2)-f(1))/2;
-    else w_o = f(3) + (f(4)-f(3))/2;
+    ## find the frequency of the normalizing gain
+    if m(1) == 1
+      ## if the first band is a passband, use DC gain
+      w_o = 0;
+    elseif f(4) == 1
+      ## for a highpass filter,
+      ## use the gain at half the sample frequency
+      w_o = 1;
+    else
+      ## otherwise, use the gain at the center
+      ## frequency of the first passband 
+      w_o = f(3) + (f(4)-f(3))/2;
     endif
 
     ## compute |h(w_o)|^-1
------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
Octave-dev mailing list
Octave-dev@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/octave-dev

Reply via email to