# LTspice - How to subtract two .meas variables?

#### Kevil

Joined Jun 28, 2020
138
I am simulating band pass filter and would like to calculate the bandwidth.

Code:
.meas Vmax MAX (mag(V(vout)))
.meas AC f1 FROM 0 TARG mag(V(vout))=Vmax/sqrt(2) RISE=1
.meas AC f2 FROM 0 TARG mag(V(vout))=Vmax/sqrt(2) FALL=1
vmax: MAX(mag(v(vout)))=(37.891dB,0°) FROM 1.4e+009 TO 1.8e+009
f1=1.55052e+009 FROM 0 TO 1.55052e+009
f2=1.60742e+009 FROM 0 TO 1.60742e+009

How to calculate bw = f2 - f1 by LTspice command? It would be nice to format result e.g. "bw=56.9Meg" or "bw=56.9e+6"

#### Papabravo

Joined Feb 24, 2006
19,309
Here is an example of finding the peak of a narrow band Twin-Tee filter. Change the (1+epsilon) expression to SQRT(2) and it will find the -3 dB points on a magnitude plot.

#### eetech00

Joined Jun 8, 2013
3,418
I am simulating band pass filter and would like to calculate the bandwidth.

Code:
.meas Vmax MAX (mag(V(vout)))
.meas AC f1 FROM 0 TARG mag(V(vout))=Vmax/sqrt(2) RISE=1
.meas AC f2 FROM 0 TARG mag(V(vout))=Vmax/sqrt(2) FALL=1
vmax: MAX(mag(v(vout)))=(37.891dB,0°) FROM 1.4e+009 TO 1.8e+009
f1=1.55052e+009 FROM 0 TO 1.55052e+009
f2=1.60742e+009 FROM 0 TO 1.60742e+009

How to calculate bw = f2 - f1 by LTspice command? It would be nice to format result e.g. "bw=56.9Meg" or "bw=56.9e+6"
This is right out of LTspice "help" for .meas:

.MEAS AC tmp max mag(V(out))
.MEAS AC BW trig mag(V(out))=tmp/sqrt(2) rise=1 targ mag(V(out))=tmp/sqrt(2) fall=last

BW measurement at -3dB from 0dB

(It was a little difficult pointing in the graph with the mouse but I think you get the idea)

#### Kevil

Joined Jun 28, 2020
138
Change the (1+epsilon) expression to SQRT(2) and it will find the -3 dB points on a magnitude plot.
Thank you, it's working well.

By the way how to display the frequency ?

.meas Vmax MAX (mag(V(vout)))
vmax: MAX(mag(v(vout)))=(37.891dB,0°) FROM 1.4e+009 TO 1.8e+009

e.g. vmax: MAX(mag(v(vout)))=(37.891dB,0° at 1.5536084GHz)

#### Papabravo

Joined Feb 24, 2006
19,309
Thank you, it's working well.

By the way how to display the frequency ?

.meas Vmax MAX (mag(V(vout)))
vmax: MAX(mag(v(vout)))=(37.891dB,0°) FROM 1.4e+009 TO 1.8e+009

e.g. vmax: MAX(mag(v(vout)))=(37.891dB,0° at 1.5536084GHz)
The results of the .meas directives are written into the Spice Error Log which you can access with the "View" menu
So left click View | Spice Error Log or use keyboard Alt-V, then L
Error Log will be displayed in a separate window
Select the appropriate text from the Spice Error Log
Paste it into a comment text box and place it on the schematic

See the schematic in Post #2 where the values of temp and bw are lines 4 & 5 underneath the title

#### Kevil

Joined Jun 28, 2020
138
I know the Spice Error Log where to look for measured values .

I raised another problem see above:

How to display the frequency ?

.meas Vmax MAX (mag(V(vout)))
vmax: MAX(mag(v(vout)))=(37.891dB,0°) FROM 1.4e+009 TO 1.8e+009

e.g. vmax: MAX(mag(v(vout)))=(37.891dB,0° at 1.5536084GHz)

#### Papabravo

Joined Feb 24, 2006
19,309
You're right, I haven't got the faintest idea what you are asking. Maybe there is somebody else who understands you better. I do know that the syntax of the .meas statement can choose between the quantities normally displayed in the waveform viewer on the vertical axis ang quantities that are normally on the horizontal axis like time an frequency. You have an example, using the keywords TRIG and TARG to display the bandwidth of a filter. There is also my example of determining the resonant frequency of a narrow passband filter. I can't imagine what else you want.