# How do I vary the frequency of a signal source in LTspice?

I'm trying to test the bandwidth of a common emitter amplifier for an electronics practical using LTspice. I need to vary the frequencies from 10Hz, 20Hz, 50Hz then decade by decade up to 1MHz, using the .step param function, but I do not know how to go about it.

• Why don't you run an ac analysis instead? You set the dc operating point and then excite the circuit with an ac source. You will then plot the magnitude and phase of your circuit automatically. Commented Aug 7 at 10:17

If you want to get the frequency response of a circuit you can run an AC analysis instead. For that, you'll need to configure your signal source:

And the simulation command:

Above is just an example i.e. you are free to change the values.

If you run the simulation and plot the output node, you'll get the frequency response (solid green: gain, dotted green: phase):

You can find the -3 dB point by putting a cursor on the frequency response plot and moving it manually, or you can ask LTspice to find it for you with .meas command:

.meas ac f find frequency when mag(V(out))=0.707

After the simulation you can open the SPICE Error Log and see the result:

If you still want to use a voltage source with varying frequency then you can define a function for the frequency interpolation and pass it to a behavioural source:

.param start_f 1
.param stop_f 1Meg
.func fot(sim_t) { start_f + time * (stop_f - start_f) / sim_t }


The function above makes a linear interpolation between start_f and stop_f which are the start and stop frequencies, respectively. sim_t is the simulation duration which is the value you pass to .tran function normally.

Now you can use the function in a behavioural source:

The result may look a bit off:

• Thank you , this was very helpful. The graph I got was flipped however, and I'm getting almost double the gain I was getting when I took measurements of the practical circuit (around 30dB). Commented Aug 7 at 11:50
• Okay , I fixed it. I accidentally connected my Vcc to ground . Commented Aug 7 at 12:50
• @ColbyKlassen If this answer is satisfactory, then you should click on the checkmark under the answer score. More info here: meta.stackexchange.com/a/5235 Commented Aug 8 at 2:50