MATLAB Answers


Query about Butterworth filter

Asked by tranquiliser
on 17 Jun 2013


I am relatively new to Matlab and I am not from Signal processing background, so pardon my ignorance. I have a fluid pressure data acquired at 10 Hz from the sensor, which I wish to filter using low-pass filter. I measured for 51s to acquire 510 samples of pressure data. I saw this code in the internet which I modified to suit my data:

pa=data(:,3);		% extracting third column from the acquired data
t1=data(:,1);		% time data from first column
t1=t1-min(t1);		% resetting the start time to zero
cut_off_freq = 0.2;	% normalised cut-off frequency
sampling_freq = 10;	% acquisition rate of the measurement device
number_of_point = length(pa);
order = 2;
[butter_b, butter_a] = butter(order, cut_off_freq/(sampling_freq/2));
freqz(butter_b, butter_a, number_of_point, sampling_freq);

My friend tells me that the sampling frequency is the sampling frequency of the filter and not the actual measurement. He suggests me to use any frequency above 20 Hz (Nyquist criteria). But I am of the opinion that it should be 10, and we should play around the normalised cutoff frequency instead to come up with a proper filter. Who is right in this case?

Should sampling_freq=10 or should it be >20?



This doesn't appear to be a MATLAB question. The answer is your sampling frequency is 10 Hz, but you need to understand the theory behind the differences between the continuous time Fourier transform and the DTFT (and to some extent the DFT) tp understand why.

Jan Simon
on 19 Jun 2013

Although the usage of normalized frequencies should be trivial, it took me some time to understand the underlying logic also. Therefore I've voted for this question.


No products are associated with this question.

2 Answers

Answer by Wayne King
on 17 Jun 2013
Edited by Wayne King
on 17 Jun 2013
 Accepted answer

Your sampling frequency is 10 Hz as you correctly note. Therefore you should construct your cut_off_freq exactly as you do except use the cut_off_freq in Hz not in normalized frequency. So to have a cutoff frequency of 2 Hz is 2/5 in normalized units. The Nyquist frequency for your application is 5 Hz. Your friend is incorrect.


Jan Simon
on 18 Jun 2013

The rate a signal is recorded is called "sampling rate" also. When you record a signal with 10 Hz, you cannot find frequencies with more than the Nyquist frequency (here 5 Hz) in it. This is the meaning of the Nyquist theorem. Therefore you cann find frequency components at 12.5 Hz.

Wayne King
on 18 Jun 2013

Jan is correct. Sampling a signal at a given rate periodizes the spectrum with a period equal to the sampling rate. So the spectrum is completely characterized by one period ([-5,5] in this case for a real-valued signal). Just because you arbitrarily set the sampling frequency to some value and construct a frequency vector does not mean that there is signal energy at a given frequency. I can construct a frequency vector with arbitrary values and plot the fft() output against that vector if they are equal length.

Now whether the original analog signal was undersampled and therefore the spectrum is distorted by aliasing, that is another question. Still, that does not change the fact that your discrete-time signal was sampled at 10 Hz and this periodizes the spectrum to have a period of 10.

That's a lot helpful. Thanks a lot Jan and Wayne. Appreciate the help.

Answer by Jan Simon
on 17 Jun 2013

As usual the documentation of butter reveals some details:

For data sampled at 1000 Hz, design a 9th-order highpass Butterworth filter
with cutoff frequency of 300 Hz, which corresponds to a normalized value of
  [z,p,k] = butter(9,300/500,'high');

So do not use the already normalized cut-off frequency in cut_off_freq/(sampling_freq/2), because this normalized it again.


Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!