Author Topic: Accurate phase and magnitude measurement in LTSPICE  (Read 15111 times)

0 Members and 1 Guest are viewing this topic.

Offline AlfBaz

  • Super Contributor
  • ***
  • Posts: 2007
  • Country: au
Accurate phase and magnitude measurement in LTSPICE
« on: January 09, 2015, 04:42:35 pm »
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 again

In 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 this :)

Apologies if this is common knowledge, I googled around a bit but haven't found this yet

 

Offline f5r5e5d

  • Frequent Contributor
  • **
  • Posts: 346
Re: Accurate phase and magnitude measurement in LTSPICE
« Reply #1 on: January 10, 2015, 04:29:40 am »
if you want single frequencies the ftt of the transient analysis can give high resolution

I 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 waveform

the .four analysis can be used too - but you're back to viewing the log file text
 

Offline Jay_Diddy_B

  • Super Contributor
  • ***
  • Posts: 1809
  • Country: ca
Re: Accurate phase and magnitude measurement in LTSPICE
« Reply #2 on: January 10, 2015, 06:03:23 am »
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 again

In 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 this :)

Apologies if this is common knowledge, I googled around a bit but haven't found this yet


AlfBaz 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_B




And the results in the time domain (Transient Analysis):




I have attached a zipfile with the LTspice model.

Regards,

Jay_Diddy_B

« Last Edit: January 10, 2015, 12:58:01 pm by Jay_Diddy_B »
 

Offline Jay_Diddy_B

  • Super Contributor
  • ***
  • Posts: 1809
  • Country: ca
Re: Accurate phase and magnitude measurement in LTSPICE
« Reply #3 on: January 10, 2015, 06:16:32 am »
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 LOG
Right click in the window
Selected plot Step'ed meas data
Right click in the new window
Select add trace

Here is the Gain and Phase plot:



Regards,

Jay_Diddy_B

« Last Edit: January 10, 2015, 06:18:16 am by Jay_Diddy_B »
 

Offline Pat Pending

  • Regular Contributor
  • *
  • Posts: 160
  • Country: us
Re: Accurate phase and magnitude measurement in LTSPICE
« Reply #4 on: January 10, 2015, 06:54:04 am »
Now that's very useful
Thanks JDB
 

Offline Jay_Diddy_B

  • Super Contributor
  • ***
  • Posts: 1809
  • Country: ca
Re: Accurate phase and magnitude measurement in LTSPICE
« Reply #5 on: January 10, 2015, 01:11:53 pm »
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.02
frequency: 1/ time_1=100.001
time_2=0.00124899 FROM 0.0100001 TO 0.0112491
phase: 360*(time_2 / time_1)=44.9641
mag_vin: RMS(v(vin))=0.706926 FROM 0.0100001 TO 0.02
mag_vout: RMS(v(vout))=0.499858 FROM 0.0112491 TO 0.0212501
gain: 20*(log10(mag_vout/mag_vin))=-3.01054



The 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
 

Offline AlfBaz

  • Super Contributor
  • ***
  • Posts: 2007
  • Country: au
Re: Accurate phase and magnitude measurement in LTSPICE
« Reply #6 on: January 10, 2015, 09:59:32 pm »
Thank you very much Jay

I 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=0

I 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 :palm:
 

Offline AlfBaz

  • Super Contributor
  • ***
  • Posts: 2007
  • Country: au
Re: Accurate phase and magnitude measurement in LTSPICE
« Reply #7 on: January 10, 2015, 10:05:28 pm »
P.S.

I forgot to thank you for showing me how to use .meas for phase and time measurements, very helpful :-+
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf