LTSpice .measure magnitude at certain frequency - Page 1
Forum section: electronics / beginners

author: Zeyneb
author_rank: Regular Contributor
timestamp: December 12, 2020, 07:10:31 pm
content: Hi there,Ok, so I have a little SMPS error amplifier opamp circuit in LTSpice and I'm doing an AC analysis.I want to add a .measure command to my spice netlist to get the magnitude and phase of a node at a certain frequency. 5 KHz in this case.I'm very annoyed by the terse syntax description of the LTSpice help documentation.Something like this should be straightforward.The signal is plotting just fine. I do add:Code:.measure AC mag(V(o2)) at 5kto my netlist. Assuming "at" is just the horizontal axis value like time in transient and frequency in AC analysis, or not?but I'm just getting:Code:mag(V(o2)) (null):(null) AT 5000It's nice though LTSpice is free but this really makes me angry. Anyone who can help me getting the coreect syntax for this?Kind regards.

author: RoGeorge
author_rank: Super Contributor
timestamp: December 12, 2020, 08:25:18 pm
content: http://ltwiki.org/LTspiceHelp/LTspiceHelp/_MEASURE_Evaluate_User_Defined_Electrical_Quantities.htmOnce you place a .meas SPICE directive in the schematic, right click on the .meas text and a GUI editor will pop, has a Test button, too, very good if you don't know the syntax by heart.You didn't say what to measure or what expression to evaluate at 5k. Example of a working syntax for measuring the voltage of a node called Vout:Quote

author: Non-Abelian
author_rank: Contributor
timestamp: December 12, 2020, 08:59:27 pm
content: There's an example in the ltspice manual. Assuming you have a node labeled "out":.measure ac tmp max mag(V(out))if you want the width of the peak (at 3db down), add:.measure ac bw trig mag(V(out))=tmp/sqrt(2) rise=1+ targ mag(V(out))=tmp/sqrt(2) fall=lastif you want the frequency add:.options meascplxfmt=cartesian.measure ac cfreq when mag(V(out))=tmpif you want the Q for the peak:.measure ac filterq PARAM Re (cfreq/bw)This only works for a positive peak. If you are looking for a min, you have to modify the above.

author: Zeyneb
author_rank: Regular Contributor
timestamp: December 12, 2020, 09:47:16 pm
content: Hi, Thanks for the help.QuoteOk, this works. Now I understand the first V(Vout) is just a label name. Maybe foolish of me, but the LTSpice help culture is certainly not aligned with my style of understanding. I want to see a table there that elaborately spell out what each part of the measure statement does. So, if Analog Devices people read this They should know THEY SHOULD DO A BETTER JOB OF THIS!Now for the phase of V(o2). I just want to get the value of the dotted line that is plotted at 5 kHz.QuoteIn the error log I read:QuoteThis is certainly not according to the value at the dotted line.How do I get the phase correctly?

author: Zeyneb
author_rank: Regular Contributor
timestamp: December 12, 2020, 10:04:03 pm
content: Sorry, a measure command like:QuoteDoes provide both answers, the magnitude and phase.

author: RoGeorge
author_rank: Super Contributor
timestamp: December 12, 2020, 11:08:56 pm
content: Disappointment is nothing but wrong expectation.Other said, it's the expectations that need an adjustment, not the LTspice. LTspice is a tool, you need to learn the tool, because the tool can not learn you. Go ahead and write a better one if you don't like this.This is how SPICE works.SPICE is not made by Linear Technology (or Analog Devices now), SPICE is a very old open project with many, many decades of history, coming from the times when computers were just mainframes with teletypes (printers-like) instead of a screen or a monitor.There are many flavors of SPICE, some free, some not free, etc. LTspice is one of the easiest to use from all there are out there.By ranting against a free and open tool you only punish yourself. Better adapt to it instead of getting angry for why the world is not how you imagined it.Maybe just tell what you are trying to achieve, or what problem you want to solve with LTspice, chances are there might be an easier way to find your answer without using .meas, IDK.

author: Zeyneb
author_rank: Regular Contributor
timestamp: December 13, 2020, 01:16:22 am
content: Ok, I disagree completely.My judgement is very healthy. I strongly believe the LTSpice help does have many opportunities for improvement.I also use Python for example. It is not a circuit simulation tool but getting something done in Python makes much more sense than finding reasonable workarounds for LTSpice quirks.You act as if you are never facing an obstacle getting some job done with software. If nothing will bother you getting some job done with a tool then I don't believe you do care for quality and efficiency.

author: RoGeorge
author_rank: Super Contributor
timestamp: December 13, 2020, 11:07:23 am
content: Yes, the interface looks cumbersome at first, especially when compared with other nowadays tools. I've had similar frustration myself, at first. SPICE is a tool from the 60's, from the dawn of computing, and it is unfair to compare it with something like Python:https://en.wikipedia.org/wiki/SPICE#OriginsAt first it didn't had a GUI, it was all text, including the schematic. Despite that it kept most of the backward compatibility and is still a very useful tool 60 years later, but it needs more than a couple of hours to get used to it.With time you'll get used to it and its quirks, too, you'll see. My point was that, by getting angry against a tool you will firstly hurt yourself.The constructive approach is to read the docs, or file a bug report, or write something better, or simply to not use what you don't like.To get back on track- yes, you got it correct, the first V(Vout) is just a label, I should have used just V_to_print instead, or so, my bad- I don't know why both the magnitude and the phase are printed when you wrote only mag(something), might be a bug, but I suspect it's not a bug and the docs probably explain it somewhere. Most probably because in a "Bode"plot both the amplitude and the phase are of interest, but I almost never use .meas directive so I might be wrong. I am usually just plot what I need to look at, without ".meas"- after running a simulation, you can click on the schematic window, then click on various nodes you want to plot- by default, both the magnitude and the phase are plotted in a "Bode" chart for AC type of analysis. To remove the phase, right click on the y axis on the righthand side of the plot (the one showing phase degrees) and click "Don't plot phase" to disable the plotting for phase. Similar, but with the lefthand y axis, to disable the magnitude plotting.- right clicking on the x axis can let you put there some other measurement and plot something similar with "scater" type of charts- right clicking on the left y axis can also change the chart from Bode plot to Nyquist to Cartesian type.- there is also a cursor tool you can place on a plot chart to read the values at any frequency.- there is also a "goal" function to seek for certain points or conditions and mark them on a plot (don't know the interface for them in LTspice, PSpice use to have "Goal" in a right click menu or so)- aside from the "normal" plotting, there is another option to open the log after running the simulation (View -> SPICE Error Log), right click on the text table produced by a .step directive, and click "Plot .step'ed .meas data" to make a plot where the steps of the parameter are placed on a x axis, for example to see how a circuit will respond at 5kHz only when you change (with the help of a .step parameter) a capacitor from, let's say, 1nF to 1uF.- if you need text tables for data post-processing, you can either export the plot data as text, or read the data files produced at each simulation (can retain all the nodes or only the specified ones, can skip a period at first, etc.)Putting a capture with the schematic, attaching the .asc file and saying the goal might help getting the type of answers you are looking for.

author: gnuarm
author_rank: Super Contributor
timestamp: March 07, 2023, 11:38:10 pm
content: Quote from: RoGeorge on December 13, 2020, 11:07:23 amI love when someone points out very valid criticisms of tools and others have to criticize the criticism. So it's up to me to criticize the criticism of the criticism.Yes, it is perfectly valid to criticize a tool in current context, no matter how old the tool might be. When they still made the VW Beetle, did people continue to buy it in droves rather then comparing it to other cars available? No, the Beetle was discontinued because people criticized it instead of buying it.QuoteYes, anything other than discuss it in a group like this?I have no understanding of why people feel the need to complain when someone asks for help with a tool that has a poor UI.

author: Tomorokoshi
author_rank: Super Contributor
timestamp: March 08, 2023, 02:16:55 am
content: I just did an LTspice run that was 97,000,000 kilobytes!