Below the sinewave generator SineAC outputs a fixed 1Vpp 200Hz sine wave in LTspice:

enter image description here

This output goes to another circuit and I can see the output of the entire system in time domain at a particular set frequency, in this case 200Hz.

But is it possible to vary/sweep the frequency of SineAC signal generator above along time(not AC analysis)? The reason is, I would like to see the output of the system in time domain when the frequency changes.

I searched but couldn't find an answer here.


If you want this in transient analysis, basically doing a chirp I guess, then use a behavioral voltage source. They can slow down LTspice's analysis, but they work fine.

These are found in the F2 selection box as BV. Use one of those. Right-click on the F=V() formula that it presents and stuff in an equation you like. A linear chirp will be something like \$2\pi\cdot \left(f+k\cdot time\right)\cdot time\$, but you can pick whatever you want. \$time\$ is a variable that LTspice understands. So you can use that name, exactly. The value for \$f\$ and for \$k\$ are something you'll have to enter in, or else use a .PARAM deck card for those.

One problem will be LTspice's selection for its maximum timestep. In the .TRAN card, make sure you set that small enough to get good data on the highest frequency. Don't trust LTspice to automatically work out the best value. Use your own judgment there and select a definite value.

Here's an example I just produced, using \$f=1\:\textrm{Hz}\$ and \$k=0.5\$:

enter image description here

The suggestion by a-concerned-citizen is actually pretty easy to set up. First off, just go to LTspice's help and do a search for modulate and then select the "Special Functions" offering. There is a short discussion there, plus a reference to an example circuit that can be loaded and examined.

Here's a capture of LTspice where I added one of these and set it up to go from \$1\:\textrm{Hz}\$ to \$100\:\textrm{Hz}\$:

enter image description here

I took the trouble to also show the LTspice dialog box where I inserted the mark and space values, as well.

  • \$\begingroup\$ great way of seeing in time domain. now can we translate a time point on the time axis to frequency as f = 1+.5*time? so for example 10 second in axis relates to 6Hz right? \$\endgroup\$ – user16307 Mar 11 '17 at 18:20
  • \$\begingroup\$ @user16307 I think 'time' is just a double precision float value representing the time in seconds of the simulation. It starts at zero. So in my case I would normally think that the frequency would be 6 Hz at the 10-second mark. However, ... I must be missing a detail here because I think it is closer to twice that. \$\endgroup\$ – jonk Mar 11 '17 at 21:16
  • \$\begingroup\$ A better solution is the modulate, or modulate2. Behavioural sources will lose precision if there are large dynamic ranges to be calculated, be they amplitude or frequency, but the modulate is an A-device and it performs better. \$\endgroup\$ – a concerned citizen Mar 12 '17 at 7:12
  • \$\begingroup\$ @aconcernedcitizen Thanks. I haven't ever needed a chirp in LTspice before and just came up with that on the spot. I will take a look at what you mentioned. \$\endgroup\$ – jonk Mar 12 '17 at 8:07
  • 1
    \$\begingroup\$ @user16307 Done. Just added it. \$\endgroup\$ – jonk Mar 12 '17 at 23:13

For a more generic frequency sweep, try this. Add a BV (behavioral voltage) source with equation: V=sin(6.283*(Fs+(Fe-Fs)/te*time/2)*time)

note that θ = 6.283*(Fs+(Fe-Fs)*time/(te*2))*time

frequency is dθ/dt

f = dθ/dt = 6.283(Fs + (Fe-Fs)*2*time/(te*2))

f = dθ/dt = 6.283(Fs + (Fe-Fs)*time/te)

note: extra 2 in the denominator added b/c d/dt(time^2)=2*time

Fs = Frequency start

Fe = Frequency end

te = time end = how long to simulate

.param Fs 0

.param Fe 32000

.param te 10m

.tran 0 {te} 0

Below example shows sweeping the frequency from 0 to 32kHz. At about 16kHz the circuit is resonant.

enter image description here

  • \$\begingroup\$ This helped me, but only worked if "time to start saving data" value in the .tran (the third parameter in .tran) was 0. \$\endgroup\$ – acker9 Sep 7 '18 at 23:29

There is an alternative, besides the already well written answers, when a logarithmic sweep is needed, to shorten the simulation time, if not else. For this, the [SpecialFunctions]/modulate (or modulate2) can be set up like this:

log sweep

V(freq) is given by B2, which has the formula by which modulate works, and it's not needed, but used here to show that the cursor readings match the .param statements for fmin and fmax. B1 has a calculated formula for a sweep from 0 to 1, and sim is the total simulation time. The FFT window shows a linear decrease in amplitude which, for a logarithmic scale, can only happen if the sweep is logarithmic; q.e.d., in short.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.