Accurate phase and magnitude measurement in LTSPICE - Page 1
Forum section: electronics / projects

author: AlfBaz
author_rank: Super Contributor
timestamp: January 09, 2015, 04:42:35 pm
content: Haven't been able to find a simple way to measure phase and amplitude of waveforms in transient analysis.Simply trying to line up cursors seems a complete waste of time as I get massive errors, and resorting to .MEAS directives sees me wading through the help file time and time againIn desperation I resorted to AC analysis as it gives you phase and magnitude but as I wanted values at only one frequency I tried entering the same freq in both the start and stop fields and when I ran it the waveform viewer didn't pop up. Instead I got thisApologies if this is common knowledge, I googled around abitbut haven't found this yet

author: f5r5e5d
author_rank: Frequent Contributor
timestamp: January 10, 2015, 04:29:40 am
content: if you want single frequencies the ftt of the transient analysis can give high resolutionI prefer the graphical fft window, you do have to move cursors to bins to get the relative phase, amplitude - but the resolution can be ridiculous if you use good fft setup, well settled waveformthe .four analysis can be used too - but you're back to viewing the log file text

author: Jay_Diddy_B
author_rank: Super Contributor
timestamp: January 10, 2015, 06:03:23 am
content: Quote from: AlfBaz on January 09, 2015, 04:42:35 pmAlfBaz and the group,You can automate the phase and amplitude measurements in the transient analysis using .meas statements.I have put a little example together for you. The trig and targ keywords are used to select a single cycle of the waveform for the amplitude measurement.After running the simulation look at the SPICE error log to get the measurements.Here is the model:Note: there is a small error in this model see later post - Jay_Diddy_BAnd the results in the time domain (Transient Analysis):I have attached a zipfile with the LTspice model.Regards,Jay_Diddy_B

author: Jay_Diddy_B
author_rank: Super Contributor
timestamp: January 10, 2015, 06:16:32 am
content: Hi,You can further extend this by introducing the .step command. Here I am stepping the frequency in discrete steps:You get the graph by selecting View -> SPICE Error LOGRight click in the windowSelected plot Step'ed meas dataRight click in the new windowSelect add traceHere is the Gain and Phase plot:Regards,Jay_Diddy_B

author: Pat Pending
author_rank: Regular Contributor
timestamp: January 10, 2015, 06:54:04 am
content: Now that's very usefulThanks JDB

author: Jay_Diddy_B
author_rank: Super Contributor
timestamp: January 10, 2015, 01:11:53 pm
content: Hi group,I made a small error in my model.I used LOG in the gain calculation which is the natural logarithm, base e or ln. I should have used LOG10 which is base 10.Here is the corrected model:This gives this result in the SPICE error log:time_1=0.00999989 FROM 0.0100001 TO 0.02frequency: 1/ time_1=100.001time_2=0.00124899 FROM 0.0100001 TO 0.0112491phase: 360*(time_2 / time_1)=44.9641mag_vin: RMS(v(vin))=0.706926 FROM 0.0100001 TO 0.02mag_vout: RMS(v(vout))=0.499858 FROM 0.0112491 TO 0.0212501gain: 20*(log10(mag_vout/mag_vin))=-3.01054The correct answer for this circuit is 45 degrees and -3.000 dB so now we are getting the correct answer.I have attached a zipfile including the correction.Regards,Jay_Diddy_B

author: AlfBaz
author_rank: Super Contributor
timestamp: January 10, 2015, 09:59:32 pm
content: Thank you very much JayI hadn't noticed VAL was optional with TRIG and TARG.At any rate I had given up on using the .meas directives as I was not getting accurate results that agreed with my calculations, regardless of using the "alternate" solver and plotwinsize=0I downloaded your zip to see what you where doing to get your more accurate RMS values.Took me a bit, but eventually realised I was leaving the "Maximum timestep" field blank in the transient analysis tab. A field I use to always fill in PSPICE but for some reason never have in ltspice

author: AlfBaz
author_rank: Super Contributor
timestamp: January 10, 2015, 10:05:28 pm
content: P.S.I forgot to thank you for showing me how to use .meas for phase and time measurements, very helpful

author: seamusdemora
author_rank: Regular Contributor
timestamp: October 06, 2020, 05:45:47 am
content: This is incredibly useful. Just getting started with LTspice & needed to plot some phase shifts vs frequency and dielectric constant for a moisture sensor. This Q&A could be an entire chapter in a book on LTspice.Jay_Diddy_B for President!

author: BravoV
author_rank: Super Contributor
timestamp: October 06, 2020, 07:11:43 am
content: Quote from: seamusdemora on October 06, 2020, 05:45:47 amWhen it comes to LTSpice, as far I've noticed in this forum for many years, personally I see Jay_Diddy_B is the LTSpice kungfu master.

author: EIghtball009
author_rank: Newbie
timestamp: October 30, 2020, 06:20:01 pm
content: I made an account here for the sole reason to say thank you and