%WAH generates the wah effect.
%WAH() takes the user selected .wav file and play back the file with a wah
%effect. A .wav file with the wah effect called output.wav is generated and saved into the
%user file path. A bandpass filter with a centre peaking frequency sweeps
%up and down the spectrum to generate the sound effect.
%WAH() uses the wah_wah function on the bottom to calculate the
%coefficients for the band pass filter.
%
%Standard wah-wah effect:
%Prompts the user to enter the minimum and the maximum centre cutoff frequency,
%the minium value CANNOT be equal to or greater than the maximum value.
%
%Improved wah-wah effect:
%Allows input for the first formant and the second formant,
%to achieve a more realistic vocal wah sound or variations.
%
%Example:
%minf1 = 300, maxf1 = 1000
%minf2 = 2000, minf 2050
%visit http://www.geofex.com/Article_Folders/wahpedl/voicewah.htm
%for more formant informantion.
%
%Advanced wah-wah effect:
%Allows complete control of all the parameters ofthe funciton.
%The damping factor controls the size of the pass band.
%The lower the damping factor the smaller the pass band.
%The wah frequency determins how man HZ per second are cycled through.
%
%IMPORTANT:
%The function freezes when a wrong statement or a wrong value has been
%entered.
%press 'control'+'c" to stop the debugging process and follow the prompts
%in the next attempt.
%FIRST PART OF THE FUNCTION.
function wah()
%High-leve script which takes the data and calls the function to work with
%the data.
dataIn = input('Enter the .wav file you wish to apply the wah-wah effect:\n','s');
%EFFECT COEFFICIENTS
[x fs] = wavread(dataIn);%Obtain values for the input wav.
% damping factor
% lower the damping factor the smaller the pass band.
damp = 0.05;
fw = 2000;% wah frequency, how many Hz per second are cycled through
formants = input('Standard, improved or advanced effect? (std\\imp\\adv) \n','s');
if (formants == 'std');
% min and max centre cutoff frequency of variable bandpass filter. The
% peak centre of the band pass filter sweeps between the minimum and
% the maximum values.
minf = input('Enter the minmium centre cutoff frequency value: \n(Recommanded starting value: 200-500) \n');
maxf = input('Enter the maximum centre cutoff frequency value: \n(Recommanded starting value: 2500-3500) \n');
dataOut = wah_wah(dataIn,damp,minf,maxf,fw); %Calls the function and process the input signal.
name = input('Enter the name of the output file in with .wav extension\n','s');
wavwrite(dataOut, fs, name);%Write the output signal into wav.
sound(dataOut,fs);%Plays the output signal.
display('The sound played has been saved in your folder');
display('thank you for using the wah() function.');
elseif (formants == 'imp');
% min and max centre cutoff frequency of variable bandpass filter for the first formant.
minf1= input('Enter the minmium centre cutoff frequency value for the first formant: \n');
maxf1= input('Enter the maximium centre cutoff frequency value for the first formant: \n');
% min and max centre cutoff frequency of variable bandpass filter for the escond formant.
minf2= input('Enter the minmium centre cutoff frequency value for the second formant: \n');
maxf2= input('Enter the minmium centre cutoff frequency value for the second formant: \n');
dataOut1 = wah_wah(dataIn,damp,minf1,maxf1,fw);%Calls the function and process the input signal.
dataOut2 = wah_wah(dataIn,damp,minf2,maxf2,fw);%Calls the function and process the input signal.
dataOut = dataOut1 + dataOut2;% Adds both the first formant and the second formant values together.
name = input('Enter the name of the output file in with .wav extension\n','s');
wavwrite(dataOut, fs,name);%Write the output signal into wav.
sound(dataOut,fs);%Plays the output signal.
display('The sound played has been saved in your folder,');
display('thank you for using the wah() function.');
elseif (formants == 'adv');
% min and max centre cutoff frequency of variable bandpass filter for the first formant.
minf1= input('Enter the minmium centre cutoff frequency value for the first formant: \n');
maxf1= input('Enter the maximium centre cutoff frequency value for the first formant: \n');
% min and max centre cutoff frequency of variable bandpass filter for the escond formant.
minf2= input('Enter the minmium centre cutoff frequency value for the second formant: \n');
maxf2= input('Enter the minmium centre cutoff frequency value for the second formant: \n');
damp = input('Enter the damping factor: \n(Recommanded defult setting:0.05\n');
fw = input('Enter the wah frequency: \n(Recommanded defult setting:2000)\n');
dataOut1 = wah_wah(dataIn,damp,minf1,maxf1,fw);%Calls the function and process the input signal.
dataOut2 = wah_wah(dataIn,damp,minf2,maxf2,fw);%Calls the function and process the input signal.
dataOut = dataOut1 + dataOut2;% Adds both the first formant and the second formant values together.
name = input('Enter the name of the output file in with .wav extension\n','s');
wavwrite(dataOut, fs,name);%Write the output signal into wav.
sound(dataOut,fs);%Plays the output signal.
display('The sound played has been saved in your folder,');
display('thank you for using the wah() function.');
else
display('You have entered the wrong statement, please try again from the beginning.');
end
%SECOND PART OF THE FUNCTION.
% wah_wah.m state variable band pass
% written by Ronan O'Malley
% October 2nd 2005
%
% BP filter with narrow pass band, Fc oscillates up and down the spectrum
% Difference equation taken from DAFX chapter 2
%
% Changing this from a BP to a BS (notch instead of a bandpass) converts this effect to a phaser
%
% yl(n) = F1*yb(n) + yl(n-1)
% yb(n) = F1*yh(n) + yb(n-1)
% yh(n) = x(n) - yl(n-1) - Q1*yb(n-1)
%
% vary Fc from 500 to 5000 Hz
% 44100 samples per sec
function y = wah_wah(infile,damp,minf,maxf,Fw);
% read in wav sample
[ x, Fs, N ] = wavread(infile);
% wah frequency, how many Hz per second are cycled through
Fw = Fw;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% change in centre frequency per sample (Hz)
%delta=0.1;
delta = Fw/Fs;
%0.1 => at 44100 samples per second should mean 4.41kHz Fc shift per sec
% create triangle wave of centre frequency values
Fc=minf:delta:maxf;
while(length(Fc) < length(x) )
Fc= [ Fc (maxf:-delta:minf) ];
Fc= [ Fc (minf:delta:maxf) ];
end
% trim tri wave to size of input
Fc = Fc(1:length(x));
% difference equation coefficients
F1 = 2*sin((pi*Fc(1))/Fs); % must be recalculated each time Fc changes
Q1 = 2*damp; % this dictates size of the pass bands
yh=zeros(size(x)); % create emptly out vectors
yb=zeros(size(x));
yl=zeros(size(x));
% first sample, to avoid referencing of negative signals
yh(1) = x(1);
yb(1) = F1*yh(1);
yl(1) = F1*yb(1);
% apply difference equation to the sample
for n=2:length(x),
yh(n) = x(n) - yl(n-1) - Q1*yb(n-1);
yb(n) = F1*yh(n) + yb(n-1);
yl(n) = F1*yb(n) + yl(n-1);
F1 = 2*sin((pi*Fc(n))/Fs);
end
%normalise
maxyb = max(abs(yb));
y = yb/maxyb;