1
$\begingroup$

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.

enter image description here

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

$\endgroup$
  • 1
    $\begingroup$ 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. $\endgroup$ – bill s Dec 1 '15 at 22:55
  • $\begingroup$ @bills I really appreciate your comment but I am unfortunately unfamiliar with filtering techniques. Can you suggest another solution. Thank you. $\endgroup$ – Algohi Dec 1 '15 at 23:54
  • $\begingroup$ 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, $\endgroup$ – bill s Dec 2 '15 at 4:44
  • $\begingroup$ @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 $\endgroup$ – Algohi Dec 2 '15 at 15:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.