Take the 2-minute tour ×
Signal Processing Stack Exchange is a question and answer site for practitioners of the art and science of signal, image and video processing. It's 100% free, no registration required.

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!
clear;

% Set the sampling frequency used by our digital filtering system:
fs=8000;

% 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:
figure(1);
plot(f, 20*log10(abs(H)));
xlabel('Frequency (Hz)');
ylabel('Magnitude (dB)');
share|improve this question
    
Post the links to the images in plain text or put them in a comment and someone will edit them in for you. –  jonsca Jan 9 '13 at 12:44
add comment

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer
    
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! –  Brian Sidebotham Jan 9 '13 at 13:53
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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