# Fast Optimization for Long FIR Filters

I need FIR filter lengths in the order of 1e4 and above to obtain reasonable accuracy in desired frequency response. The problem is that optimisation in MATLAB (e.g. fircls or the Optimization Toolbox) is very slow (because the problem size becomes a bit silly). Does any software exist out there that solve long FIR filter synthesis problems quickly-ish (or quicker than MATLAB)?

Or are there better ways of generating super-narrow pass band filters (suitable for FPGAs)?

Sampling will be at about 1 GHz, output should be about 10 kHz, so 1/100000 pass to stop ratio. The FIR filter is to perform weighted averaging.

• arbitrary guess: you want to decimate after super-narrow pass band filtering? How large is your pass and stopband compared to the nyquist bandwidth? 1/100? 1/1000? – Marcus Müller Oct 8 '18 at 15:20
• i normally use firls() or occasionally firpm() to design FIR filters. but normally IIR filters will more efficiently perform extremely sharp and narrow-band filtering. what are your frequency response requirements? – robert bristow-johnson Oct 8 '18 at 15:21
• Sampling will be at about 1 GHz, output should be about 10 kHz, so 1/100000 pass to stop ratio. The FIR filter is to perform weighted averaging. – Arnfinn Oct 8 '18 at 15:25
• More questions: do you need optimization with designing the filter or running the filter? What type of filter do you need? Just a lowpass or something more fancy, with detailed amplitude and phase requirements ? – Hilmar Oct 8 '18 at 15:46
• @Hilmar I want to average a signal coming at high sample rate, the averaging can be specified in freq. domain, will essentially be a low-pass filter, but should ideally have some compensation for mechanical dynamics etc., things happen at very different time-scales, but high-freq. stuff should be averaged to produce nice low freq. measurement... – Arnfinn Oct 8 '18 at 15:52

Sampling will be at about 1 GHz, output should be about 10 kHz

So, you're decimating by a factor of $$10^5=2^5\cdot5^5$$.

This very much says that you'd normally go ahead and successively decimate.

In an FPGA, halfband filters are especially cheap and efficient to implement; better yet: they're extremely easy to design, and you don't have to change the shape the halfband filter for each step (though you certainly can, to some gain).

I'd probably (you'll have to do your own effort estimates; Sylvain Muneaut of the Osmocom project had a handy cascaded FIR decimation effort calculator, can't find it...) do the following, from a pure gut feeling

• 1 GHz -> Halfband
• 500 MHz -> same Halfband
• 250 MHz -> ¼-band
• 62.5 MHz -> simple $$\frac15$$-band filter
• 12.5 MHz -> simple $$\frac15$$-band filter
• 2.5 MHz -> good $$\frac1{25}$$-band filter
• 100 kHz -> excellent $$\frac1{10}$$-band filter

That way, the easiest to calculate filters (i.e. the ones with the least non-zero coefficients) run at the highest rate, and and the closer you get to the bandwidth you want to "protect", the flatter your passbands and the steeper your transition bands can get.

For complexity reasons, you could consider transferring the 62.5 MS/s or 12.5 MHz out of your FPGA into a PC and processing it there on a multicore CPU – CPU power is much cheaper than FPGA power these days, for memory intense tasks like long FIRs, at least.

Generally, the question is whether you're not doing something questionable when sampling a 10 kHz signal at 1 GHz; but that's due to the physical reality of the system you're observing, and it's hard to help without knowing that system.

• The point of having 1 GHz sampling is to be able to do brute force averaging (can't do ensemble averaging since only one detector). Nothing questionable here! ;) – Arnfinn Oct 8 '18 at 16:00
• Know of any toolbox to automate procedure? – Arnfinn Oct 8 '18 at 16:02
• nope, sorry. But yeah, don't forget that the oversampling gain you get isn't infinite, and that really wideband noise isn't white anymore. An FPGA that can do significant math at 1GS/s isn't exactly cheap, so you really ought to make sure your analog circuitry can even support what you're doing. Also, your matlab firls approach doesn't cut it, since you'll want to do fixed point on your FPGA, and the rounding errors you get here when converting from a floating point design might easily negate a few dB of the averaging gain you get! – Marcus Müller Oct 8 '18 at 16:05
• So, what kind of signal are you observing? Pulsars? What's the dynamic range? What's the carrier frequency, if any? – Marcus Müller Oct 8 '18 at 16:06
• Yeah, I need to optimise the filter for fixed-point before implementing. The system generates a sort of pulse-width modulated signal, hence the more counts that can be squeezed in each output sample increases resolution (in theory). Looks like successive decimation should do the trick. No pulsars, but maybe some exciting gauge blocks in the metrology lab ;) – Arnfinn Oct 8 '18 at 16:25