# LTSpice: How to use .meas command to find the fundamental frequency of non-sinusoidal signal?

I want to find fundamental frequency of a periodic signal (non-sinusoidal) in certain time window using the .meas command in LTSpice.

I was using the following code to calculate frequency (in kHz).

.meas tran T1 find time when V(OUT)=0 rise 1000 .meas tran T2 find time when V(OUT)=0 rise 1100 .meas tran Frequency param 100/(1000*(T2-T1))

This works fine for certain cases, but when I do the parametric sweep, it gives inaccurate readings because of two issues:

Here, I assume at 1000th cycle, signal reaches its measurement window (say from time=4ms) but sometimes it doesn't. Therefor, I want to specify the absolute time for the measurement. from 4ms in this case, I have added a sample voltage waveform as below (with parametric sweep)

The zoomed waveform from 4ms is

My questions is

Is it possible to specify the starting time for the above code so that it will count cycles from the specified time? ( I tried to use trig-trag and from-to commands but failed)

• If you are only interested in the harmonics, the .four command may be for you – PlasmaHH Apr 6 '18 at 8:45
• @ PlasmaHH, Thanks, But how can we use .four when the fundamental frequency is unknown? Primary goal here to measure the fundamental frequency in a specified time window – Pojj Apr 6 '18 at 9:16
• It sounds a bit like mission impossible: you don't know the fundamental (ok, that's your goal), but you don't know how your circuit will behave (settling time), or how many harmonics it will have (can't rely on .meas). The only thing I see is to run your simulation and then View > FFT, and then decide which one is your fundamental, but this is not an automated process. You say you have a parametric sweep. Can't your harmonics, or anything that you can cling to, be related to the swept parameters? Some correlation? – a concerned citizen Apr 7 '18 at 7:00
• Thanks, actually, the settling time is known. I do not care about harmonies either. Basically, I want an automated way to get an approximate value close to the fundamental from view > FFT - for a zoomed window (e.g. from 1.4ms to 1.5ms) – Pojj Apr 8 '18 at 14:44
• @PlasmaHH, I narrowed down the question. Would you have any recommendations? – Pojj Apr 16 '18 at 7:01

It looks like you know your final simulation time, and the waveforms are about settled at the end of it, so, considering what I see in your picture, you can consider 4.4ms a mark from which you can measure, like this:

.meas t1 find time when v(out)=0 cross=1 td=4.4m
.meas t2 find time when v(out)=0 cross=3 td=4.4m
.meas T param t2-t1


Looking more closely (the grey-ish waveform), it looks like you have skewed sines in there, which will account for harmonics, so you can't really rely on this measurement for detecting the fundamental, only its apparent period. Just thought I should add this.

• Great! this is what I was looking for. – Pojj Apr 16 '18 at 7:44

If I understood correctly your signal is periodic, therefore I would expect a command like this to properly measure your fundamental period:

.MEAS TRAN TRise TRIG when v(out) = 1.65 CROSS = 1 TARG when v(out)=1.65 CROSS=3

where: out is the name of your output pin, CROSS=1 and CROSS=3 stands for "the 1st and the 3rd time the signal crosses the specified value", in this case vdd/2 assuming vdd = 3.3V. I use this to evaluate the propagation delay, also in .param simulations and it worked so far.

Hope this helps! Andrea

• Thanks, But this will also have the same two issues associated with my code in the question. – Pojj Apr 6 '18 at 9:20
• Ok, I think I misunderstood your question then. May I ask you to add to the question a waveform screenshot of the signal you'd like to study? – a_bet Apr 6 '18 at 11:45
• Please refer to the edited question – Pojj Apr 16 '18 at 6:59