Hi , my name is Gustavo from Spain.
I have used the equations for simulating a charging capacitor
of your web page, at first it worked but with smaller values for
R and C it didn't worked right.
I was in the internet looking for equations about capacitors so
I could do a program to simulate a RC filter.
I tried some in vain, but I found your page:
There is a program in your page that simulates a capacitor
charging thru a resistor.
You showed how to calculate that, in this way:
1. Find current I => I = (Vo - Vc )/ R
2. Then calculate new Vc => Vc = Vc + I *dt/C
3. calculate VR = I * R
Fast I made a program that simulates a RC filter, but
I use standard 44100hz 16bit stereo .wav files.
I just put the incoming sample in the variable V0, as if the
music was the battery .
The first RC combination I used was C=7.21uF and R=35ohms.
this gives a cutoff point at about 632hz which is the middle of
the audible spectrum.
It worked!! , and if the output was Vc then I had a lowpass
filter and if the output was Vr then I had a highpass filter.
And the frequency response was exactly like the one I
simulated using electronics workbench 5.0. ( I used a logaritmic
frequency sweep from 20hz to 22050hz which lasts one minute,
so I can see the response clearly) (22050hz is the maximum
frequency that a 44100hz wave file can store, I guess you
knew that anyway)
I use dt=1/44100 so it is the time between a sample and the
V0 can be from -32767 volts to 32767 volts, (the interger
values of 16bit samples). This seems to be a very high voltage
but since we simulate ideal capacitors and resistors, these
voltages are just numbers into an equation, and the results
would be the same if I used -1 to 1 volts.
But I have found problems such as the highpass filter had a
tiny gain, (a real RC circuit has 0 gain)
Then I realized that with less "reasonable" smaller values both
for R and C (almost all values should be reasonable) the filter
doesn't work properly , so Vc tends to rise and rise until
reaching infite, (It never should surpass 32767 volts)
If the time interval dt is very small,
integral become summation.
I now try to simulate R=10ohms and C=10nf
(yes I know that the cutoff frequency is about 1.5Mhz and is
far higher than 22050hz , but it shouldn't be a problem, and I
*NEED* to simulate that)
So the cutoff frequency is very high and I though dt was very
large to these values.
So I did resample, first I tried x1024 resample and latter x16384
resample.And the filter stops rising to infite but the response is
still wrong, and the left channel (R=35 C=7.21uf) still has the
same tiny gain as before.Don't worry I use separe variables and
values for each channel so they are independent from each
The resample I use is very primitive, I give exact copies of the
actual sample to the filter 1024 times, and the output is the
first Vr value of them, but It doesn't have any kind of distortion
neither frequency response or aliasing or whatever.
Of course I use dt=1/44100*1024 for x1024 resample
or dt=1/44100*16384 for x16384 resample.
The thing gets really slow , but don't worry I use very short
inputs to check the gain which is always wrong.
with C=10nf and R=10ohms a 20hz frequency should be
thats is lower than the 16bit output can represent, but the real
output is about -54db which is wrong.
a 22050hz frequency should be at -37db but the output gives
somewhat between +6db and +12db. (gain!)
Don't worry about the precision of my equations, I have a
pentium III 500mhz processor, and I use full 80bit floating point
fpu precision to do them, this can represent either incredible
high numbers or incredible low.
So what happens? why the filters doesn't work right?
How can I simulate it properly? (remember that I only have a
sample each 1/44100 seconds).
Can you help me?.
Thanks, your page has been useful for me.
Tu correo gratis en MixMail http://www.mixmail.com
Ya.com ADSL, Router 3Com ：ratis! http://acceso.ya.com/adsl