digital audio effects page 67
%% wah-wah filters
clc; close all; clear;
fs = 44.1e3;
fc = 10e3;
Wc = fc / fs;
fb = 1e2;
Wb = fb / fs;
num = 5e4;
f0 = 3;
t = (0:num-1) / fs;
t = t(:);
f = (0:num-1) / num * fs;
f = f(:);
x = randn(num, 1);
xh = [0 0];
fcc = fc;
fca = 5e3;
y = zeros(size(x));
mix = 0.01;
for n = 1:length(x)
fc = 1e4 + fca * cos( 2 * pi * f0 * t(n));
Wc = fc / fs;
d = -cos( 2 * pi * Wc);
c = (tan(pi *Wb) - 1) / (tan(pi *Wb) + 1);
xh_new = x(n) -d * (1 - c) * xh(1) + c * xh(2);
ap_y = -c*xh_new + d * (1 - c) * xh(1) + xh(2); % allpass filter
xh = [xh_new xh(1)];
ap = 0.5 * ( x(n) - ap_y); % bandpass
y(n) = mix*x(n) + (1 - mix)*ap;
end
figure;
spectrogram(y, 128, [], [], fs);
sound(y, fs);
The result is depicted in the following figure.
a similar approach can be found at http://web.uvic.ca/~cjam/ELEC484/Assignment%203/Part%201/wahwah2.m