Skip to content

Instantly share code, notes, and snippets.

@michaelbartnett
Created November 30, 2011 21:52
Show Gist options
  • Save michaelbartnett/1411128 to your computer and use it in GitHub Desktop.
Save michaelbartnett/1411128 to your computer and use it in GitHub Desktop.
svfilter from last dst lab hw
function svfilter(cutoff, Q)
% lowpass
[lpf_b, lpf_b] = fir1(10, cutoff, 'low');
% highpass
[hpf_b, hpf_b] = fir1(10, cutoff, 'high');
% bandpass
% For bandpass coefficients, the order is half of the passed in order parameter (has to be an even order beacuse of poles and zeroes)
bw = cutoff / Q;
Wn = [cutoff - bw / 2, cutoff + bw / 2];
if (Wn(1) <= 0 || or Wn(2) >= 1)
warn('Center frequency and Q problem . . . .');
b_bp = 1;
a_bp = 1;
else
[bpf_b, bpf_b] = fir1(5, cutoff, 'bandpass');
end
% display
if b_bp == 1 && b_bp == 1
fvtool([lpf_b, lpf_a], [hpf_b, hpf_a]);
else
fvtool([lpf_b, lpf_a], [hpf_b, hpf_a], [bpf_b, bpf_a]);
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment