Created
November 12, 2012 12:07
-
-
Save zapu/4059015 to your computer and use it in GitHub Desktop.
filtry filtry filtry
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
close all; | |
sampling_freq = 8000; | |
nyq_freq = sampling_freq / 2; | |
% Bandpass filter frequencies | |
freqs = [41 82 123]; | |
for i=1:10 | |
fsize = size(freqs, 2); | |
freqs = [freqs (freqs(fsize-1)*2)]; | |
end | |
% Color table, for cute plotting | |
colors = [linspace(0,1,15)' logspace(0,1,15)'/10 linspace(1,0,15)']; | |
fig = figure(1); | |
hold on; | |
for i=2:size(freqs,2)-1 | |
width = freqs(i+1)-freqs(i-1); | |
fqi = freqs(i); | |
w1 = fqi - freqs(i-1); | |
w2 = freqs(i+1) - fqi; | |
fp = [fqi - w1 * 0.6, fqi + w2 * 0.6] ./ nyq_freq; % Pass frequencies | |
fs = [fqi - w1, fqi + w2] ./ nyq_freq; % Stop frequencies | |
% Filter design | |
[N,wn] = buttord(fp, fs, 2, 10); | |
[b,a] = butter(N,wn,'bandpass'); | |
% Plot frequency response | |
[H,w] = freqz(b, a, 512, sampling_freq); | |
plot(w, (abs(H)).^2, 'Color', colors(i,:)); | |
title('Frequency Response (Magnitude)'); | |
xlabel('Frequency (Hz)'); | |
ylabel('|H(\omega)|^2'); | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment