This page discusses some of the issues that come up in numerical circuit simulation for the Virtual Crossover.
I wanted to be able to handle fairly general circuit configurations, including for example magnetic coupling in inductors. Since I have had some experience in circuit simulation, I decided to write my own program, rather than trying to use an existing package such as SPICE. This was partially motivated by the fact that I needed to do some of the analyses in the frequency domain, as I will explain elsewhere, and it wasn't clear to me how to do this with SPICE, although it may be possible.
Even after deciding to do a general numerical
analysis, there are still some issues that
remain. As an example, consider the following
high-pass filter circuit:
The method I use to characterize crossover circuits is to calculate their impulse response. Even though the circuit of Fig. 1 is quite simple, it does present a challenge since it is not band limited, i.e. all frequencies above f0 are passed to the output. Most of the techniques used in digital signal processing require that waveforms are band-limited, otherwise aliasing will occur and the results will not be accurate.
First, consider the ideal impulse response
of this high-pass filter. To obtain the
impulse response, a
Dirac delta function, denoted by
is impressed at the Vin
terminals. The function
is of
infinite magnitude and vanishingly small duration,
but such that its time integral is unity.
In other words,
can be thought of
as having magnitude
lasting for
a time
,
such that
,
and where the limit
is taken.
Formally, the impulse response of
this high-pass filter at the Vout
terminals is given by:
(1)
We can almost guess the result in
Eq.(1) by considering
what happens when an impulse is applied.
Since the impulse
is infinite
and since the voltage on a capacitor can't
change instantaneously, the impulse is
passed through to the resistor nearly
unchanged; this accounts for the first
term in Eq.(1).
Also during the time the impulse is
applied, current of an amount
Amps
flows into
the capacitor, for a time
.
Therefore at the end of the impulse,
the total charge on the capacitor will be
,
or
.
The polarity of this
capacitor voltage will be such that when the
impulse is removed, it will produce a negative
voltage at the output terminals of
Volts. Thereafter, the voltage at the output will
decay exponentially.
The thing that causes the problem is basically
the
function in Eq.(1).
Obviously in any
real numerical calculation we will not have
a function that is infinitely large and exists
for an infinitely short time. So the question
is, how can we come up with a good approximation
for the impulse response of Eq.(1)?
And it has to be done in a general way, we can't
cheat and use the fact that we already know the
formal impulse response for this circuit.
One method that seems quite plausible is to
use the discrete time impulse function,
,
as the excitation at the
Vin terminals. If we are
doing a calculation at discrete points
separated by time step
,
the function
is equal to 1 during
the interval of
seconds denoted
by index 0, and it is equal to 0 otherwise.
In fact, the function
is often described
as the discrete-time equivalent of the
impulse function
for continuous-time
systems.
I have written a program called IMPRSP.C, and
one of its options is to apply a value of 1
at the circuit input for one time step, and then 0
for the remaining simulation time.
Fig.(2) shows
a portion of the resulting
simulation for the circuit of
Fig.(1):
One thing to notice in Fig.(2) is that the first point where the impulse is applied is wrong; we expect it to be 1, but it is smaller than 1, specifically it comes out to be about 0.604. This is because values in Fig.(2) are stored at the end of each time step, and during the time that the impulse function is applied the capacitor is charging up, so that the output voltage across the resistor is reduced from 1. You might think that we could fix this by saving the value at the beginning of the time step instead, however it turns out that if we were simulating a low-pass filter instead, the more accurate thing would be to store the value at the end of the time step, just as we have done in this case. So we can't use that as a general fix. Basically, this is an illustration of the kinds of ambiguities that arise when we try to model a system that is not inherently band-limited using digital sampling techniques.
The abrupt jump to the second waveform point in
Fig.(2) occurs when the discrete
impulse function is removed. It turns out that
this value is in error
also, partially because the initial value
at the beginning of the time step is not
right as discussed above, and also because it takes
some time to simulate the second point (the sampling
time
),
after which the output voltage has
changed. Nevertheless, the general shape of the
waveform in Fig.(2) is correct,
and it displays the general properties of the
true impulse response; also, it doesn't display
any ringing in the time domain that is often
observed in digital signal processing results.
So the question arises, can we use this method?
One way to answer this question is to take the FFT
(Fast Fourier Transform) of the waveform in
Fig.(2) and compare with the
expected high-pass frequency characteristics; after
all, we know the exact solution for the circuit
in Fig.(1). The exact solution
for the output voltage magnitude as a function of
frequency
is:
Fig.(3) shows the magnitude
of the frequency response out to 20kHz
calculated from the FFT
of the time domain waveform in Fig.(2):
The method that I have described thus far is basically what is known as the "impulse invariance" technique of digital filter design [1]. This method starts with the time-domain impulse response of an analog filter and attemps to design a digital filter with the same time domain response at its discrete sample points. Oppenheim and Schafer [1] come to the following conclusion regarding this method: "...the impulse invariance technique is obviously only appropriate for essentially bandlimited filters ... highpass or bandstop filters would require additional bandlimiting to avoid severe aliasing distortion."
One way around this problem, which is indicated
in the above quote, is to apply a band-limited
signal at the Vin terminals,
instead of a non-band-limited impulse function.
That way, even if the circuit itself is not
band-limited, the calculated response will be.
I outlined this technique in a previous article [2],
where I used an equal-ripple
lowpass filter as the band-limited input.
I have written a program called ERLPF.C that
can generate such a waveform. For example,
Fig.(4) shows the
time-domain impulse response of an equal-ripple
lowpass filter with passband edge at 30kHz and
stopband edge at 42.64kHz:
Figure 5
shows the magnitude of the filter response
in the frequency domain:
Figure 6 shows the result of
carrying out the IMPRSP.C calculation
for the high-pass circuit of Fig.(1)
when the
equal-ripple lowpass filter of
Fig.(4) is used as the
input to the circuit:
Even though excellent frequency response agreement is obtained with this method, I am bothered by the introduction of excessive ringing in the time domain to the waveforms. This ringing is essentially at the cutoff frequency of the lowpass filter that is used, in this case in the 30-40kHz range, so it is not within the audio band and may not be important. But an important criterion for me has always been achieving good time domain response in speaker systems, so introducing so much ringing goes against my grain. Unfortunately, at this point I don't see a way around it - we need to band-limit the signal to use digital signal processing techniques, and if we are to use a practical sampling rate such as 96kHz, the signal needs to be band-limited somewhere between 20kHz and 48kHz, which calls for a filter with a sharp cutoff, and which necessarily exhibits ringing in the time domain. Oversampling at a much higher rate and using a gentler filter would certainly help, but if we want to eventually get back down to 96kHz, we still need to be band-limited at 48kHz. If anyone knows of a solution that would eliminate this ringing, I would be very interested to learn about it.
Before leaving this topic I want to mention
one additional simulation technique that can
be used, which yields essentially identical
results to the time-domain simulation approach;
you can also carry out the simulation in the
frequency domain. Imagine decomposing Vin
into its frequency components, so that it becomes
;
then the circuit can be
solved for each frequency point, yielding
,
which can finally be
transformed back to
.
I wrote
another program, IMPRSPZ.C, which does such a
frequency-domain calculation; this program assumes
that the circuit is terminated with a known
impedance as a function of frequency,
.
I will discuss this method further when coupling
the circuit and driver is discussed. The
frequency-domain method is actually much faster
than the time-domain simulation with IMPRSP.C,
because there is no need to over-sample in order
to obtain an accurate solution.