Академический Документы
Профессиональный Документы
Культура Документы
Assignment 3:
Filter Implementations
Wah-wah Filter, Comb Filters, Allpass Filter
Prepared for:
Peter Driessen
ELEC 484
University of Victoria
Prepared by:
Tim I. Perry
V00213455
May, 2009
Tim Perry
V00213455
2009-05-21
CONTENTS
PART 1: Wha-Wha Filter Derived from 2nd Order Allpass .......................................................................... 2
PART 2: Convolution of two Audio Files .................................................................................................... 5
PART 3: FIR and IIR Comb Filter Derivations ............................................................................................ 7
PART 4: FIR and IIR Comb Filter Implementation ................................................................................... 13
PART 5: Vibrato Effect .............................................................................................................................. 18
PART 6: Second Order Allpass Filter Design ............................................................................................ 19
PART 7: Second Order Allpass Filter Group Delay ................................................................................... 22
PART 8: Sound Collage Using Filtered White Noise................................................................................. 24
REFERENCES ........................................................................................................................................... 27
APPENDIX A ............................................................................................................................................. 27
Tim Perry
V00213455
2009-05-21
Figure 1 is the block diagram for a tuneable second order allpass filter, denoted A(z). From this structure,
the tuning parameters c and d are used to implement a second order BPF.
Tim Perry
V00213455
2009-05-21
For the allpass filter of Figure 1:
=
+ 1 +
1 + 1
2%
= cos
!
(1)
(2)
(3)
(4)
Figure 2: Second-order bandpass and bandreject implemented with allpass filter [1]
Therefore, the second order bandpass transfer function can be expressed as:
(
+ + ,( +'( + ')
&' = *(
)
( + ,( +'( +')
(5)
Expanding this, we can find the a and b parametric filter coefficients. The terms in the numerator
cancel out, and the resulting form is analogous to the BPF seen in assignment 2:
1 + 1 + 1
= *
2 1 + 1
For constructing the filter in Matlab, the coefficient arrays are implemented as:
b = [(c+1) 0 (c+1)];
a = 2*[(1 d*(1-c) -c];
Tim Perry
V00213455
2009-05-21
Tim Perry
V00213455
2009-05-21
Figure 3 contains the output spectrums of the above Matlab script, with two different choices for
parameters. The first is a typical sweeping about 689 Hz. The second version uses a higher value of 10 for
the sweep range multiplier variable, and the odd high frequency effects are the result of negative values
for f_c being calculated and then reflected back into the positive frequency spectrum.
Figure 3: Output spectrum for two versions of the Matlab implemented wha filter. Typical paremeters (top),
"lazer_wha" parameters with sweep range multiplier set to 10 (bottom). In both cases, the center frequency is
clearly time-varying.
Waveform images of the convolution results are presented in the figures below. To avoid clipping when
executing the Matlab wavwrite command, the output sample amplitudes were scaled down.
Tim Perry
V00213455
2009-05-21
Figure 4: Original Tom's Diner (top), "TransSiberian_Drums.wav" (center), and mono-convoluted and
scaled output file (bottom).
Tim Perry
V00213455
2009-05-21
where
(6)
?'
= ( + 1'2
@'
(7)
&' = ( + 1'A
=
B + :
B
Poles:
There is a 4th order pole at z = 0.
Zeros:
0 = B + :
= ED:
z=
Figure 6 displays the pole-zero plot for the FIR comb filter, as displayed in WinPOI.
Figure 7 displays the frequency response and Figure 8 displays the impulse response with
g chosen to be 0.9. Figure 9 displays the block diagram as described by Equation (7).
Tim Perry
V00213455
2009-05-21
Figure 6: FIR comb filter pole-zero plot, magnitude response and phase response
Tim Perry
V00213455
2009-05-21
Tim Perry
V00213455
2009-05-21
The difference equation for the IIR comb filter is given by:
./ = +0/ + 1./ 2
where
2 = 3/56
(8)
?'
+
=
@' ( 1'2
=
<
=
= 1 : B
(9)
For delay M = 4:
=
B
B :
Poles:
= ED:
This results in 4 poles in the complex plane with magnitude g at angles of:
For stability,
3
0, , ,
2
2
|:| 1
Zeros:
There is a 4th order zero at z = 0.
The pole-zero plot for the IIR filter is shown in Figure 11. In practice, the poles will lie inside the
unit circle as opposed to right on it. This is to ensure that there is an attenuated signal in the
feedback loop. |:| 1 is a necessary condition for stability. The pole-zero plot, frequency
response, and impulse response plots are shown below. For the FR and IR plots, the feedback
loop gain g was set to 0.8.
10
Tim Perry
V00213455
2009-05-21
Figure 11: IIR comb filter pole-zero plot, magnitude response and phase response.
Figure 12: Frequency Response of FIR Comb Filter with delay line gain g set to 0.8
11
Tim Perry
V00213455
2009-05-21
Figure 13: Impulse Response of IIR Comb Filter with delay line gain g set to 0.8
Figure 14: Parameter Table and Block Diagram for a Universal Comb Filter [1]. Both the
FIR and IIR comb filters may be implemented with this general structure.
12
Tim Perry
V00213455
2009-05-21
Delay Time
(ms)
0
10
30
50
100
For lower delay times, the effects on the vocal timbre were more noticeable than the flute. However, the
effects of comb filtering were particularly pronounced for the flute sample that was filtered through the
FIR comb filter with 100ms delay. The interference caused by the out of phase copy of the original signal
causes the flute vibrato (flute vibrato is actually closer to a tremolo) to be altered. Since the flutes
vibrato is essentially a tremolo, the amplitude variations are distorted by the comb filtering, and the
overall dynamics are altered. Additionally, a thickening of texture, loss of clarity, and the typical
disorienting effects of extreme comb filtering are present. This effect would be more significant if the
delay gain parameter g was set to 1 (for the FIR comb filtered audio files, a value of g= 0.9 was used).
13
Tim Perry
V00213455
2009-05-21
Figure 15: Response of FIR comb filter applied to Tom's Diner with 0ms delay.
Figure 16: Response of FIR comb filter applied to Tom's Diner with 10ms delay.
Figure 17: Response of FIR comb filter applied to Tom's Diner with 100ms delay.
14
Tim Perry
V00213455
2009-05-21
Figure 18: FIR comb filter response to flute2.wav as input; delay time = 10ms.
Figure 19: FIR comb filter response to flute2.wav as input; delay time = 100ms.
15
Tim Perry
V00213455
2009-05-21
Delay Time
(ms)
0
10
30
50
100
Thickening of sound.
Thickening of sound and subtle smoothing of
transients.
As time progresses, multiple flute voices can
be perceived.
As g approaches 1 for the IIR comb filter, successive delays decay so slowly that they stack up as time
progresses (Figure 22), making for an unnatural but interesting sounding effect. If g is greater than 1
(corresponding to poles outside of the unit circle), the system is unstable (Figure 23) and will quickly
blow up toward infinity.
16
Tim Perry
V00213455
2009-05-21
Figure 20: IIR comb filter response to flute2.wav as input; delay time = 0ms, g = 0.5.
Figure 21: IIR comb filter response to flute2.wav as input; delay time = 100ms, g = 0.50.
17
Tim Perry
V00213455
2009-05-21
Figure 22: IIR comb filter response to flute2.wav as input; delay time = 100ms, g = 0.9.
Figure 23: IIR comb filter response to flute2.wav as input; delay time = 100ms, g = 1.1 (left) and g = 1.3
(right). These filters are unstable.
The vibrato effect was implemented in the time domain, using the algorithm presented on page 69 of
DAFX [1]. A typical modulation frequency of 4Hz was chosen (around average for human vocals, which
other instruments tend to mimic). I originally tried to apply this algorithm to a cello sample; however,
there were some implementation problems that were taking a very long time to work around. In the end,
the vibrato was applied to a sinusoid oscillating at 110Hz (a low A).
The sine wave makes it easy to view the effects of vibrato, which is a relatively slow and narrow
oscillation in pitch that deviates about the fundamental frequency of a tone. Without vibrato, we would
expect to see a constant spectrum for a sin wave.
18
Tim Perry
V00213455
2009-05-21
The second-order allpass filter was used to create the wha BP filter of Part 1. From Equations (1), (3) and
(4), the transfer function for the allpass filter is:
=
+ 1 +
1 + 1
tan ! 1
=
2
tan
!+1
2%
= cos
!
19
Tim Perry
V00213455
2009-05-21
To construct a second-order allpass filter with with real coefficients, two allpass pole-zero couples must
be multiplied together, where the poles are complex conjugates. The steady state magnitude must be
constant over the entire frequency range, therefore:
WW
|N OP Q| = Q|RST UV = Q
Y
= Z
XX RST UV
Therefore the allpass filter must satisfy:
W = ZX
b = 0.9N B ,
b = 0.9N
Oe
B
The corresponding image zeros will lie diagonally opposite the poles in the z-plane. This means that the
zeros will be located outside the unit circle at an equal distance to the unit circle as the poles, with the
same angle as the poles:
Oe
= 1.1N B ,
= 1.1N
Oe
B
The z-plane pole zero-plot shown below. The resulting magnitude and phase response are as desired:
20
Tim Perry
V00213455
2009-05-21
Figure 27: Magnitude Response (top) and Phase Response (bottom) for all pass filter. The apparent phase
discontinuity is simply due to the axis of the plot (the phase range is from to instead of from -2 to 0).
21
Tim Perry
V00213455
2009-05-21
The magnitude response, phase response, and group delay of the allpass filter from part 6 are plotted in
Matlab below (Figure 28). Additionally, the two input AM waveforms are plotted, and the time delay of
the amplitude envelope can be used to determine an identical group delay (Figure 31).
From the plots below, the maximum group delay was determined to be 19 samples, occurring at 5500Hz.
This is at the cutoff frequency, where the phase response passes -180.
Figure 28: Second-order allpass filter frequency response and group delay
22
Tim Perry
V00213455
2009-05-21
Figure 29: Envelope comparison between sinusoids having maximum (top) and minimum (bottom) delay.
Modulating frequency = 30Hz
Figure 30: Envelope comparison between sinusoids having maximum (top) and minimum (bottom) delay.
Modulating frequency = 30Hz
23
Tim Perry
V00213455
2009-05-21
Figure 31: Zoomed in on envelope comparison plot. The difference between the sample times with a
particular amplitude on the envelope can be counted to reveal the delay. Half of the samples are not shown as
they occupy the top half of the envelope, and thus the result should be multiplied by 2.
24
Tim Perry
V00213455
2009-05-21
The other new filter that was used is a 6 band parametric EQ (Figure 33). The center frequencies were
carefully chosen to add or remove the impression of proximity and listener envelopment. These gain of
these 6 center frequencies was automated to change through time by defining them as automation
parameters in Pro Tools. The gain was altered throughout the track.
Figure 32: Initial filtered noise files used for sound college.
25
Tim Perry
V00213455
2009-05-21
Figure 33: 6 Band parametric EQ with automated gain at center frequencies - applied to white noise to cause
proximity related frequencies to swell and wane as time progresses.
26
Tim Perry
V00213455
2009-05-21
REFERENCES
[1]
APPENDIX A
PART 2 MATLAB Code
Convolution of Two Audio Files
%==========================================================================
% a5part7_Convolve.m
Tim Perry
% Elec484: DAFX
V00213455
% Assignment 3, Part 7
2009-05-21
%
% Convolve about 5 seconds of the Tom's Diner .wav sound file with
% a rhythmic pattern (made up from the given samples or your own sample),
% and describe the result.
% Repeat with the flute.wav sound file.
%==========================================================================
clear all;
close all;
% input audio files
wavfile1 = 'flute2.wav';
%wavfile1 = 'x1.wav';
wavfile2 = 'TransSiberian_Drums';
[x1, fs1, NBITS1] = wavread(wavfile1);
[x2, fs2, NBITS2] = wavread(wavfile2);
% Default to left channel for mono treatment of stereo input files
x1t = x1(:,1);
x2 = x2(:,1);
blockTime = 20e-3; %20 ms
blockLength = floor(blockTime*fs1);
blockNos = min( ceil( [length(x1) length(x2)]/blockLength ) );
y = zeros((blockLength*(blockNos+1)),1);
% Define window function
t = transpose(linspace(0,1,blockLength*2+1));
window = (1-cos(2*pi*t))/2;
% Perform convolution
for i = 0:blockNos-1
offset = 1 + i * blockLength;
27
Tim Perry
V00213455
2009-05-21
CurrentBL = min([blockLength length(x1)-offset length(x2)-offset]);
BlockConvolved = conv( x1(offset:offset+CurrentBL),
x2(offset:offset+CurrentBL));
BlockConvolved = window(1:length(BlockConvolved)).*BlockConvolved;
y(offset:offset+length(BlockConvolved)-1) =
y(offset:offset+length(BlockConvolved)-1) + BlockConvolved;
end
y = (1/(2.*max(y))).*y;
Filter Specs/Constants
= 4; % delay
= 0.9; % delay gain
= 1024; % FFT window size
% Filter coefficients
b = zeros(1,M+1);
b(1) = 1;
b(M+1) = g;
a = [1];
%------------------------------------------% Frequency Response
%------------------------------------------H_w = freqz(b,a,N);
w = linspace(0,pi,N);
figure(1)
% Magnitude response plot
subplot(2,1,1)
plot(w, abs(H_w));
grid on;
28
Tim Perry
V00213455
2009-05-21
axis([0 pi 0 2])
title('Magnitude Response of FIR Comb Filter')
xlabel('Normalized Frequency (radians/s)')
ylabel('|H(e^jw)|')
% Phase response plot
subplot(2,1,2)
plot(w, angle(H_w));
grid on;
axis([0 pi -pi pi])
title('Phase Response of FIR Comb Filter')
xlabel('Normalized Frequency (radians/s)')
ylabel('Arg(H(e^jw)) (radians)')
%------------------------------------------% Impulse Response
%------------------------------------------H_whole = freqz(b,a,N,'whole');
h = ifft(H_whole,N);
nSamples = linspace(0,N,N);
figure(2)
% Impulse response plot
stem(nSamples, h,'.','b-','MarkerSize',15);
grid on;
axis([-5 35 -0.2 1.2])
title('Impulse Response of FIR Comb Filter')
xlabel('n')
ylabel('h[n]')
Filter Specs/Constants
= 4;
% delay
= 0.8; % delay gain
= 1;
% input signal gain
= 1024; % FFT window size
% Filter coefficients
b = [c];
a = zeros(1,M+1);
a(1) = 1
a(M+1) = -g;
29
Tim Perry
V00213455
2009-05-21
%------------------------------------------% Frequency Response
%------------------------------------------H_w = freqz(b,a,N);
w = linspace(0,pi,N);
figure(1)
% Magnitude response plot
subplot(2,1,1)
plot(w, abs(H_w));
grid on;
axis([0 pi 0 max(H_w)+1])
title('Magnitude Response of IIR Comb Filter')
xlabel('Normalized Frequency (radians/s)')
ylabel('|H(e^jw)|')
% Phase response plot
subplot(2,1,2)
plot(w, angle(H_w));
grid on;
axis([0 pi -pi pi])
title('Phase Response of IIR Comb Filter')
xlabel('Normalized Frequency (radians/s)')
ylabel('Arg(H(e^jw)) (radians)')
%------------------------------------------% Impulse Response
%------------------------------------------H_whole = freqz(b,a,N,'whole');
h = ifft(H_whole,N);
nSamples = linspace(0,N,N);
figure(2)
% Impulse response plot
stem(nSamples, h,'.','b-','MarkerSize',15);
grid on;
axis([-5 60 -1 1.2])
title('Impulse Response of IIR Comb Filter')
xlabel('n')
ylabel('h[n]')
30
Tim Perry
V00213455
2009-05-21
31
Tim Perry
V00213455
2009-05-21
figure(1)
% Impulse response plot
stem(samples, y,'.','b-','MarkerSize',15);
grid on;
axis([-5 numSamples -1 1])
title('FIR Comb Filter Output')
xlabel('n')
ylabel('h[n]')
32
Tim Perry
V00213455
2009-05-21
% write output audio file
wavwrite(y, f_s, nbits, file_out);
%------------------------------------------% Plot IR of output file
%------------------------------------------samples = linspace(0,numSamples,numSamples);
figure(1)
% Impulse response plot
stem(samples, y,'.','b-','MarkerSize',11);
grid on;
axis([-5 numSamples -1 1])
title('IIR Comb Filter Output')
xlabel('n')
ylabel('h[n]')
wavplay(y, f_s);
for n=1:(LEN-1)
M=MODFREQ;
MOD=sin(M*2*pi*n);
ZEIGER=1+DELAY+WIDTH*MOD;
i=floor(ZEIGER);
frac=ZEIGER-i;
Delayline=[x(n);Delayline(1:L-1)];
%---Linear Interpolation----------------------------y(n,1)=Delayline(i+1)*frac+Delayline(i)*(1-frac);
%---Allpass Interpolation-----------------------------%y(n,1)=(Delayline(i+1)+(1-frac)*Delayline(i)-(1-frac)*ya_alt);
%ya_alt=ya(n,1);
End;
33
Tim Perry
V00213455
2009-05-21
34
Tim Perry
V00213455
2009-05-21
35
Tim Perry
V00213455
2009-05-21
axis([0 f_s/2 -pi pi])
title('Phase Response of Allpass Filter')
xlabel('Frequency (Hz)')
ylabel('Arg(H(e^jw)) (radians)')
% Group delay plot
subplot(3,1,3)
plot(f, gd);
grid on;
axis([0 f_s/2 0 max(gd)*1.1])
title('Group Delay of Allpass Filter')
xlabel('Frequency (Hz)')
ylabel('Group Delay (samples)')
36