I'm wondering why the following code for GNU Octave appears to be incorrect in the frequency domain by a magnitude of 2. For example, in Figure 1. (Sorry, I'm apparently not allowed to post images!) it can be seen that the -3dB points of the bandpass butterworth filter are at 150 and 300Hz instead of the design requirement of 300 and 600Hz. I can't really see that I'm doing wrong?

%Start from nothing!

% Set the sampling frequency used by our digital filtering system:

% Start designing a butterworth filter, passband. (In Hz)
pass_lo = 300;
pass_hi = 600;

% The order of the filter
order = 4;

% Determine the low and high frequencies of the passband as fractions of the
% sampling rate:
flo = pass_lo/fs;
fhi = pass_hi/fs;

% Use the butterworth filter design function to get the coefficients for a
% bandpass filter with the settings above:
[b,a] = butter(order, [flo fhi]);

% Determine the frequency response of the filter design above. Get the output
% in frequency rather than rad/s. Use 512 plot points.
[H,f] = freqz(b, a, 512, fs);

% Plot the result so that we can see if it is correct:
plot(f, 20*log10(abs(H)));
xlabel('Frequency (Hz)');
ylabel('Magnitude (dB)');
  • $\begingroup$ Post the links to the images in plain text or put them in a comment and someone will edit them in for you. $\endgroup$ – jonsca Jan 9 '13 at 12:44

Don't know about GNU but in Matlab the frequency argument is specified relative to the Nyquist frequency (fs/2) and not the sample rate itself (fs). This makes the maxium legal argument for a relative cutoff frequency 1 (instead of 0.5). Your frequency argument should be [flo fhi]/fs*2.

  • $\begingroup$ Thanks Hilmar, that's exactly right. I found that out afterwards, but apparently I can't answer my own question for 8 hours. Thanks though, teaches me to read the manual more! $\endgroup$ – Brian Sidebotham Jan 9 '13 at 13:53

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.