Why Low Pass Filter Doesn’t Work in SPICE – Troubleshooting

ngspicespice

I just started working with spice and I feel like I'm making some sort of obvious mistake but unsure what.

This works fine:

R1 in out 1k
R2 out 0 1k
Vin in 0 dc 0 ac 1 sin(0 1 500)

.control
ac dec 1000 10 15kHz
plot 20*log(out/in)
.endc

.end

(As in the simulation runs, but it gives me something strange for the gain) Certainly it makes no sense to do a frequency analysis on a simple voltage divider, but it's just a sanity check for the real circuit I'm trying to simulate:

R1 in out 1k
C1 out 0 100nF
Vin in 0 dc 0 ac 1 sin(0 1 500)

.control
ac dec 1000 10 15kHz
plot 20*log(out/in)
.endc

.end

I simply replace R2 with a 100 nF capacitor, and the simulation fails.

The first error I get is:

Warning: singular matrix:  check nodes out and out 

This doesn't make any sense to me.

I feel like perhaps I'm doing something wrong with the "Vin" line, as I'm not exactly sure how the "ac" line knows to change Vin (since it's not ever referenced on that line) I am simply trying to sweep 1V AC from 10 hz to 15kHz.

Best Answer

There are a few issues regarding your code:

  • In both examples, you end the section with .end. But this .end defines the end of the netlist, but you didn't (purposely) define the start of the netlist.
    The parser now will parse R1 in out 1k as title, so there is no conenction between node "in" and node "out", leaving a floating out node.
    That will give you the Warning: singular matrix: check nodes out and out
    You can solve this by starting with plain text as first line, or even a white line will do, or use the .title statement.
  • You use plot to plot a bode diagram, plot only plots the real part, not the magnitude.
    Use plot vdb(out) and plot ph(out) instead.

So, I'd suggest to change your code to

Just plain text here, or even a white line will do, or use the .title statement
R1 in out 1k
C1 out 0 100nF
Vin in 0 dc 0 ac 1 sin(0 1 500)

.control
ac dec 1000 10 15kHz
plot vdb(out)
plot ph(out)
.endc

.end