# ButterworthFilterModel consumes the memory too much

I have a simple filter which is a result of the these questions here and here.

I have to use this filter in a Do loop but I found that this filter consume the memory too much even I am not storing any thing. It is just direct calculation.

For example:

filter[n_, ω_, b_, data_] := Reverse[
RecurrenceFilter[
ToDiscreteTimeModel[ButterworthFilterModel[{n, ω}], b],
Reverse[
RecurrenceFilter[
ToDiscreteTimeModel[ButterworthFilterModel[{n, ω}], b],
data]]]]

datatest = RandomReal[{-30, 200}, {100, 100}];

Do[indicator = i;
filter[8, 0.039063, 3.2, #] & /@ datatest;, {i, 1, 100}];


When I run this code the memory was consumed too much.

Can anyone help me in this and tell me what is wrong so that I get such consumption in the memory?

• The basic problem is that you are using an inappropriate filter. Butterworth filters are old-style analog filters that were efficient in the days when you needed to use op amps and transisters. There are many very efficient digital filters that can do a much better job, especially in 2D. – bill s Dec 1 '15 at 22:55
• @bills I really appreciate your comment but I am unfortunately unfamiliar with filtering techniques. Can you suggest another solution. Thank you. – Algohi Dec 1 '15 at 23:54
• What exactly are you trying to do? If smoothing then try Meanfilter or GasssianFilter, or maybe BandpassFilter, or for highpass edge-detection try EdgeDetect or Highpass... all of these are much easier to use than Butterworth (they don't require ToDiscreteTimeModel or RecurrenceFilter) they just operate right on the 2D data, – bill s Dec 2 '15 at 4:44
• @bills, yes you are right, there are other filters that do the same job. It appears that ButterworthFilterModel and ToDiscreteTimeModel use Internal DumpSave each time with different local variables and that is probably the reason for memory high usage. I have tried other filters as you suggested and they work fine with not problem on the memory. thanks – Algohi Dec 2 '15 at 15:46