Create Low Pass Filter by Octave

user3021107 picture user3021107 · Nov 22, 2013 · Viewed 16.3k times · Source

Though I had an example of low pass filter coded in Octave and I'm sure it works, I can't understand. How dose this work? and How can I know cut-off frequency of this filter?

The original_data is a column of water quality data I obtained with 1Hz.

l = rows(original_data);
a = fft(original_data);
for i = (1:l);
 if i >9
  a(i) = 0;
 endif
endfor
b = fft(original_data);
for i = (1:l)
 if i > 1
  b(i) = 0;
 endif
endfor
c = real(ifft(a));
c(1);
d = real(ifft(a))*2-c(1);

If you have any idea, please help me.

Answer

am304 picture am304 · Nov 22, 2013

I agree with the comment, there are plenty of functions to allow you to design a low-pass filter correctly (see http://octave.sourceforge.net/signal/overview.html, in particular the IIR and FIR filter design sections). Once you have designed your filter you can apply it using the function filter or filtfilt.

As an example, a simple way to go about this would be:

[b,a] = butter(n, Wc) % low pass Butterworth filter with cutoff pi*Wc radians - choose the order of the filter n and cut-off frequency Wc to suit
filtered_data = filter(b,a,original_data);