# Digital Lowpass butterworth filter with cut off 500Hz and sampling rate 1.25MSPS

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.

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

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:

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

This results in an extremely high output (blue = input, red = output):

If I change the butterworth order to 4, I get:

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.

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