LTspice Measurements

Feb 23, 2013 12 Replies

I have always found the documents for LTspice to be rather spartan at best. It looks like there are a lot of third parties who are helping by chipping in their shots at tutorials and docs. But they are mostly introductions and getting started guides covering only the most basic stuff.



I am trying to do what should be some simple measurements on a tuned circuit. I want to see how various additions to a circuit alter the tuned frequency, bandwidth and Q. So it would be nice to get these numbers automagically. I've figured out how to get the bandwidth and the tuned frequency and even the Q. But it printed the frequency and Q in dB. The tuned frequency is no problem as it is also displayed linearly, but I can't find a way to display the calculated Q as a simple number other than doing the reverse dB calculation so it displays the proper number but with a dB label... obviously not my first choice.



I can't find any docs on how I might tell LTspice how to format a measurement display. Does that exist somewhere? Here are the commands I am using...



.MEAS AC tmp max mag(V(N002,N001)); find the peak response and call it "tmp" .MEAS AC BW trig mag(V(N002,N001))=tmp/sqrt(2) rise=1



  • targ mag(V(N002,N001))=tmp/sqrt(2) fall=last .MEAS AC centerfreq WHEN mag(V(N002,N001))=tmp .MEAS AC Q PARAM pow(10,centerfreq/(BW*20))

Here is what this displays



tmp: MAX(mag(v(n002,n001)))=(40.5139dB,0°) FROM 59000 TO 61000 bw=565.564 FROM 59716.6 TO 60282.1 centerfreq: mag(v(n002,n001))=tmp AT 60000 q: pow(10,centerfreq/(bw*20))=(106.089dB,0°)



It would be a bit nicer if this last line just displayed...



q: centerfreq/bw=106.089


Rick

Try setting: .opt meascplxfmt cartesian

"For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." (Richard Feynman)

Thanks for the reply.

--------------------------- LTspice IV

--------------------------- .option syntax error, unrecognized option: "meascplxfmt"

--------------------------- OK

---------------------------

I'm running the current version. 4.18a, updated Jan 30, 2013. I updated before I started this project. Funny thing is I see this in the manual. But it just doesn't seem to work...

Rick

I just tried it here (4.12u), same result.

I'm sure I used it in the past. That's progress!

"For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." (Richard Feynman)

"tmp"

If you can post or otherwise make the full sim .asc file available i could take a crack at it. NO promises though, the trick may be beyond me. There is an active Yahoo group though.

?-)

I got it to work eventually. Not sure what the problem was, but it works now. The trouble is it doesn't work for individual lines, it switches the setting for the entire session. When I tried inserting two commands, one to switch it to Cartesian and one to set it back to Bode, it kinda cramped the system and I had to exit and restart LTspice to get control of the setting again.

For parameters that I want displayed linearly I have to calculate the anti-dB so when it takes the dB it is correct. I also have to scale it so it doesn't overflow the intermediate result. Displaying 1300 is a bit too large this way, it has to be 1.3 'k'.

The good news is that in the meantime I am learning a lot about measurement scripts. The docs are rather inadequate, but with enough trial and error things can start to work.

But then I also can't seem to get the simulation to match my calculations... go figure.

Rick

I've started another thread where I asked about the simulation itself. Here is a link to the files.

formatting link

Maybe I should have kept it to one thread?

The measurements are in the schematic, but also in a separate .meas file so it can be run repeatedly without rerunning the simulation. File - Execute .MEAS Script

I've asked about the script in the Yahoo group. It is actually pretty amazing. This guy Helmut responds like it is his full time job!

Rick

Care to tell us what the magic incantation was?

"For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." (Richard Feynman)

On Wed, 27 Feb 2013 22:36:12 -0500, rickman wrote:

That looks horribly convoluted.

I posted this a while back, but you may not have seen it. It's just a demonstration of varying the coupling between two identical circuits, but it might give you a bit of insight into bandwidth measurements.

It shgould plot automatically.

Coupling.asc:

Version 4 SHEET 1 880 680 WIRE -32 96 -64 96 WIRE 96 96 48 96 WIRE 144 96 96 96 WIRE 336 96 272 96 WIRE 448 96 336 96 WIRE 144 128 144 96 WIRE 272 128 272 96 WIRE 336 128 336 96 WIRE 96 144 96 96 WIRE -64 160 -64 96 WIRE 448 160 448 96 WIRE 96 224 96 208 WIRE 144 224 144 208 WIRE 144 224 96 224 WIRE -64 320 -64 240 WIRE 64 320 -64 320 WIRE 144 320 144 224 WIRE 144 320 64 320 WIRE 272 320 272 208 WIRE 272 320 144 320 WIRE 336 320 336 192 WIRE 336 320 272 320 WIRE 448 320 448 240 WIRE 448 320 336 320 WIRE 64 368 64 320 FLAG 64 368 0 FLAG 272 96 V1 SYMBOL ind2 128 112 R0 SYMATTR InstName L1 SYMATTR Value 1m SYMATTR SpiceLine Rser=0 SYMATTR Type ind SYMBOL cap 112 144 M0 SYMATTR InstName C1 SYMATTR Value 2.53303e-9 SYMBOL voltage -64 144 R0 SYMATTR InstName V1 SYMATTR Value AC 1 SYMBOL res 64 80 R90 WINDOW 0 0 56 VBottom 2 WINDOW 3 32 56 VTop 2 SYMATTR InstName Rg SYMATTR Value 10k SYMBOL ind2 256 112 R0 SYMATTR InstName L2 SYMATTR Value 1m SYMATTR SpiceLine Rser=0 SYMATTR Type ind SYMBOL cap 320 128 R0 SYMATTR InstName C2 SYMATTR Value 2.53303e-9 SYMBOL res 432 144 R0 SYMATTR InstName R1 SYMATTR Value 10k TEXT 96 376 Left 2 !.ac lin 1000 50k 150k TEXT -80 408 Left 2 !.measure tmp max mag(V(V1))\n.measure BW trig mag(V(V1))=tmp/sqrt(2) rise=1 targ mag(V(V1))=tmp/sqrt(2) fall=last TEXT 176 112 Left 2 !K1 l1 l2 {K1} TEXT 80 392 Left 2 !.step param K1 0.01 0.2 0.02 TEXT 312 392 Left 2 !.probe V(V1) TEXT 80 64 Left 2 ;Critical coupling occurs at K1=0.062547893

"For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." (Richard Feynman)

Maybe I mispoke. I got the .options command to work, but it won't do what I want. It doesn't work for just a few selected commands.

Like I said, I don't know what I was doing wrong before. I added the command to the other commands in the script on the schematic and it changes the mode. This change is persistent until it executes another .option command that changes it to another setting. You don't need to use the command on each simulation run.

Also note that it changes the settings for the graph. If you select cartesian it will won't use dB anymore.

Rick

Thanks for the info. But this example doesn't measure the frequency of the resonance peak which is one of the measurements I was having trouble with and it doesn't address the display formatting problem at all.

Rick

mag(V(V1))=tmp/sqrt(2) rise=1 targ mag(V(V1))=tmp/sqrt(2) fall=last

Rick

Both circuits resonate at exactly 100kHz, as can be seen from the plot, most easily on the subcritical coupling runs. They are of equal Q.

Take a look at each BW measurement, then add half of each bandwidth measurement to the respective lower 3dB point.

All that is varied is the coupling, the fundamental resonance remains the same (center frequency), even when the response goes double-humped. That's what it is supposed to demonstrate.

Look up "Universal Selectivity Curves".

Old fashioned 455kHz IF transformers worked just like this. Nothing tricky here, such as stagger tuning.

I guess the only way is to format the Y axis on the plot itself. You can't change the X axis on an .ac analysis, except by changing the .ac directive to one of octal, decade, or linear.

Kraus has useful formulae for the properties of loop antennas, BTW.

"For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." (Richard Feynman)

Thanks, I'll take a look.

Rick

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required