Pages

Monday, 18 March 2013

Ngspice, RC filter with variable resistor

Let's do an AC simulation with a RC  filter. Let's assume that we want obtain the graphs of response (Mag-Phase) with three different value of resistor ($1\,k\Omega$, $10\,k\Omega$, $100\,k\Omega$). Also we want measure the cut-off frequency. This is the circuit:


We can do this with a control command, and a for cycle, varying the three value of resistance, and making an AC simulation and measurement of the cut-off frequency for each value of R.


* RC filter - variable resistor

Vin 1 0 DC 0 AC 1
R 1 2 1k
C 2 0 10n



.CONTROL
foreach val 1k 10k 100k
alter R=$val
echo executing analysis with R=$val
ac dec 600 1 10meg
meas ac fc WHEN v(2)=0.707
end
write sig_plot.raw db(ac1.v(2)) db(ac2.v(2)) db(ac3.v(2))
 +ph(ac1.v(2)) ph(ac2.v(2)) ph(ac3.v(2))
quit
.ENDC
.END

The command "foreach" is a for cycle that change the value of the variable "val" for each cycle. Then the value of the component "R" is changed by the command "alter" and is made the AC simulation for that specific value of resistance.  
The vectors of the different AC simulations, will be saved as "ac1.* ac2.* etc", then after the for cycle we can save in a raw file the magnitude and phase of the vectors for a Bode plot. This time I have used gaw to see the graphs, that is the updated version of gwave.


 The value that I have obtained with the command "meas" are:
$$f_{c1} = 15.91 kHz,\quad f_{c2} = 1.59 kHz,\quad f_{c3} = 159  Hz$$ exactly the same that can be figure out with the formula:$$f_c=\frac{1}{2 \pi R C}$$

That's all even for this time. The circuit was simple, but I think was the best to show how make an AC analysis and varying the value of a component in the same time.

spice file, raw file, output file.

No comments:

Post a Comment