help-octave
[Top][All Lists]

## Re: fir1 function and max value of the sinc signal

 From: Mike Miller Subject: Re: fir1 function and max value of the sinc signal Date: Sat, 9 Nov 2013 11:31:11 -0500 User-agent: Mutt/1.5.21 (2010-09-15)

On Sat, Nov 09, 2013 at 01:52:59 -0800, alfredd wrote:
> im doing a little research on the sinc wave to implemelt lowpass fir
> filtering.
> [...]
> h(51)=0.0833333333333...
> is it related to the round off error of the floating point value? if this is
> the case, how can i get more precision out of the function?

Hi Alfred, good questions!

First of all, good news. Octave is free software, which gives you the
freedom to study and inspect the code yourself. The code for fir1 and
fir2 are both completely implemented in the Octave scripting language:

http://sourceforge.net/p/octave/signal/ci/default/tree/inst/fir1.m
http://sourceforge.net/p/octave/signal/ci/default/tree/inst/fir2.m

You didn't state how you got your sinc pulse, so here's what I use:

octave:1> a = sinc ([-50:50] / 12) / 12;
octave:2> b = fir1 (100, 1/12, "low", "rectwin", "noscale");
octave:3> format long
octave:4> a(51)
ans =  0.0833333333333333
octave:5> b(51)
ans =  0.0823567708333333

The primary reason for this difference is that both fir1 and fir2
construct the desired filter response in the frequency domain with some
bin resolution (either default or specified to fir2). As the number of
points in the frequency domain increases, the answer comes closer to the
pure sinc pulse that you are expecting. And of course the filter takes
somewhat longer to compute.

Try comparing these results for example (the first is what fir1 calls):

octave:6> b = fir2 (100, [0,1/12,1/12,1], [1,1,0,0], 2^10, 2, "rectwin");
octave:7> b = fir2 (100, [0,1/12,1/12,1], [1,1,0,0], 2^14, 2, "rectwin");
octave:8> b = fir2 (100, [0,1/12,1/12,1], [1,1,0,0], 2^24, 2, "rectwin");

HTH,

--
mike