0
$\begingroup$

I am trying to simulate a distributed sensing system and I need to filter only frequencies lesser than 500 Hz(low pass filter) from acquired signal with sample rate 1250000 Samples/sec using below mentioned program:

 %Time specifications:
   Fs = 1250000;                   % samples per second
   dt = 1/Fs;                   % seconds per sample
   StopTime = 0.25;             % seconds
   t = (dt:dt:StopTime-dt);     % seconds
   %Input Sine wave:
   Fc = 300;                     % hertz
   dataIn = cos(2*pi*Fc*t);

   % Plot the signal versus time:
   figure;
   plot(t,dataIn);
   xlabel('time (in seconds)');
   title('Input signal');
   zoom xon;

   wc=500; % cut off frequency
   Wn=wc/(Fs/2); % normalized frequency
   [b,a] = butter(6,Wn,'low'); 
   figure;
   freqz(b,a)

%Plot filtered output 
    dataOut = filter(b,a,dataIn);
    figure; 
    plot(t,dataOut)
    title('dataout')
    zoom xon;

However I am unable to filter the desired frequencies below 500 Hz, as the cut off frequency is dependant on the sampling rate. Kindly suggest what to be done as I am new in MATLAB.

Thanks in advance.

$\endgroup$
2
  • 1
    $\begingroup$ I am new in MATLAB. Your problem is not about MATLAB! Its about theory $\endgroup$ – Ander Biguri Feb 28 '17 at 8:46
  • $\begingroup$ @AnderBiguri It is not really about theory, but about the numerical nature of MATLAB. $\endgroup$ – m7913d Feb 28 '17 at 10:11
1
$\begingroup$

Solution: Take a lower order butterworth filter or sampling frequency

Reason: As discussed here, a high order butterworth filter with a low (relative) cutoff frequency may be numerically unstable due to quantisation noise.

Explanation with figures:

I changed your frequency plot to include the region of interest:

freqz(b,a, logspace(1, 5, 1000), Fs)
ax = findall(gcf, 'Type', 'axes');
set(ax, 'XScale', 'log');

The frequency response is: Frequency response of 6th order butterworth filter

which seems very noisy at low frequencies, indicating an unstable filter.

This results in an extremely high output (blue = input, red = output): enter image description here

If I change the butterworth order to 4, I get: Frequency response of 4th order butterworth filter Input (blue) and Output(red) of the 4th order butterworth filter

The output (red) is a shifted version of the input (blue) as can been expected from the frequency response.

Keeping a 6th order butterworth filter, but lowering the sampling frequency also solves your problem.

$\endgroup$
1
  • $\begingroup$ Thank you. The output looks better with lower order filter. $\endgroup$ – K.Thomas Mar 2 '17 at 4:38

Your Answer

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