On 6 July 2012 03:11, Mike Miller <mtmil...@ieee.org> wrote:
> On Tue, Jul 3, 2012 at 10:50 AM, Carnë Draug <carandraug+...@gmail.com> wrote:
>> Hi
>>
>> I was looking at the built-in forums of sourceforge and found the
>> following reported 2 years ago (these forums have since been hidden
>> and blocked to prevent posting). Could someone please review the
>> following?
>
> Hey Carnë, I've taken a look at this function and run some test cases
> against it, I do not think there is a (serious) bug here, see below.
>
>> Reported by jmiles1: possible typo in main/signal/inst/fir2.m:
>>
>> ## make sure grid is big enough for the window
>> if 2*grid_n < n+1, grid_n = 2^nextpow2(n+1); endif
>>
>> should probably be
>>
>> ## make sure grid is big enough for the window
>> if grid_n < n+1, grid_n = 2^nextpow2(n+1); endif
>>
>> Otherwise it looks like there's a range of grid sizes between n/2 and
>> n that will be smaller than n, and generate an overlapped impulse
>> response in line 122. Apologies in advance if this was the intent, but
>> it definitely doesn't jibe with the comment in line 29.
>
> The comment is surely not clear about what "big enough" means, but the
> test for 2*grid_n < n+1 is correct when compared with the rest of the
> function as well as comparing the ML fir2 help text [1]: "npt must be
> greater than 1/2 the filter order (npt>n/2)".
>
> [1] http://www.mathworks.com/help/toolbox/signal/ref/fir2.html
>
> Line 105 interpolates the input to a length (grid_n+1) vector, and
> lines 111 and 116 replicate this for even spectral symmetry
> (2*grid_n), and this is the length that must be >= n+1.
>
> The only thing that is not clear to me is whether this matches ML
> behavior, and whether we care, e.g. if the caller passes in a 4th arg
> too small, does ML generate an error or silently make it larger like
> this line 29 does?

MatLab gives an error in somes cases and silently makes it larger in others.

>> f = [0 0.6 0.6 1]; m = [1 1 0 0];
>> b5 = fir2(30,f,m, 5);
Error using fir2 (line 135)
The number of grid points npt must be greater than or equal to 16 for
filter order 30.

>> b8 = fir2(30,f,m, 8);
Error using fir2 (line 135)
The number of grid points npt must be greater than or equal to 16 for
filter order 30.

>> b9 = fir2(30,f,m, 9);
>> b15 = fir2(30,f,m, 15);
>> b16 = fir2(30,f,m, 16);
>> b17 = fir2(30,f,m, 17);
>> isequal (b9, b15)

ans =

     1

>> isequal (b15, b16)

ans =

     1

>> isequal (b16, b17)

ans =

     0


Seems that MatLab behaviour is to adjust number of points (to the
minimum), if the value is more than half of it and error otherwise.

Not sure what's the best behavior but I'd guess at least a warning
should be given.

Carnë

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Octave-dev mailing list
Octave-dev@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/octave-dev

Reply via email to