The Designer's Guide Community Forum
https://designers-guide.org/forum/YaBB.pl
Simulators >> Circuit Simulators >> thd function in Calculator
https://designers-guide.org/forum/YaBB.pl?num=1177831778

Message started by ywguo on Apr 29th, 2007, 12:29am

Title: thd function in Calculator
Post by ywguo on Apr 29th, 2007, 12:29am

Hi, Guys,

The thd function is described in WaveScan User Guide. However, it doesn't define how many harmonics are used to calculate thd function. For example, .FOUR in SPICE sums the 2nd harmonic to the 9th harmonic to calculate thd, .FFT in HSPICE sums the 2nd harmonic to the 10th harmonic to calculate thd.

Any comments are appreciated.


Yawei

Title: Re: thd function in Calculator
Post by Andrew Beckett on Apr 30th, 2007, 5:28am

Yawei,

With the thd function, you specify the number of samples to take. This is converted to a power of two (I forget whether it is lower or higher, but it's the same as the dft function). Then it ends up with a waveform internally with a number of harmonics equal to half the power-of-two samples used.

That's how many harmonics are used for the THD calculation (i.e. half the number of samples, provided it is a power of two).

You also specify the frequency of the fundamental, so it doesn't necessarily have to be the first harmonic.

Regards,

Andrew.

Title: Re: thd function in Calculator
Post by ywguo on May 7th, 2007, 10:43pm

Andrew,

It is not easy to use if thd function sums all harmonics up to half the number of samples. I am simulating a DAC with a sine wave input. I measure the output current/voltage. Many points are needed to do FFT and calculate THD. Maybe 8192 points are used for 512 sampling cycles. So we see harmonics at multiple sampling frequencies. Then thd function evaluation gives rediculous large value. I think that it is better to sum the first 9 or 10 harmonics.

Thank you.

Yawei

Title: Re: thd function in Calculator
Post by Andrew Beckett on May 8th, 2007, 7:08am

I don't see why it should be incorrect to include all the harmonics. Why do you need more samples - remember the number of samples affects the number of harmonics - i.e. the maximum frequency. The frequency resolution is the interval you do the FFT over, so if you don't need those higher frequencies, don't do that number of samples...

Regards,

Andrew.

Title: Re: thd function in Calculator
Post by ywguo on May 9th, 2007, 12:00am

Andrew,

When I simulating a DAC for 512 sampling cycles, sure I want to know the dynamic performance like SFDR, THD. I think 512 points is not enough for FFT, because glitch may be lost. I hope there are 16 points or 32 points per sampling cycle are used for FFT. Then totally 8192 points or 16384 points are used for FFT, and the FFT result expands to 8 times or 16 times sampling frequency. Actually I don't care those outside the nyquist band. The harmonics at multiple frequencies are caused by sampling, not the distortion of DAC. right? But they are summed when I use thd function.

By the way, the average function is defined as Returns the average value of a signal. Can I calculate the average value of a signal from time 1 to time 2? The time 1 and time 2 may not be the start time and stop time of a simulation.


Thanks
Yawei

Title: Re: thd function in Calculator
Post by sheldon on May 9th, 2007, 4:52am

Yawei,

  The problem is that you are using the wrong tool to evaluate the
frequency response. If you are simulating a DAC and you want to
evaluate the effect of glitch on the response then you should use
the Fourier integral, .four, not the FFT to evaluate the frequency
response. The Fourier integral evalutes the entire waveform while
the FFT only samples the waveform. So the FFT is great for ADCs,
continuous analog --> discrete analog --> digital since the output
waveforms are sampled. However for DACs, the output waveforms
are not suited for the FFT, digital -->continuous analog. The bottom
line is that FFT is inefficient if you are sampling in small enough time
intervals to capture the glitch.  The downside of the Fourier integral
is that it does not support window functions so if you want to use
for Sigma-Delta DACs, you need to write your own window function
Verilog-A module.

BTW, there was alittle bit if discussion of this in a previous thread,

http://www.designers-guide.org/Forum/YaBB.pl?num=1113231964

                                                            Best Regards,

                                                               Sheldon

Title: Re: thd function in Calculator
Post by Andrew Beckett on May 9th, 2007, 9:54pm

You can use the clip function to pick a range of the waveform, and then average that, to answer your "average" question...

Andrew.

Title: Re: thd function in Calculator
Post by ywguo on May 9th, 2007, 11:17pm


Andrew Beckett wrote on May 9th, 2007, 9:54pm:
You can use the clip function to pick a range of the waveform, and then average that, to answer your "average" question...

Andrew.


Andrew,

Thank you very much.

Title: Re: thd function in Calculator
Post by ywguo on May 10th, 2007, 12:37am

Sheldon,


Quote:
BTW, there was alittle bit if discussion of this in a previous thread,

http://www.designers-guide.org/Forum/YaBB.pl?num=1113231964


I read the previous thread. It seems that a .Fourier analysis cannot be chosen in the ADE. Right? I instantiated the fourier component from analogLib. Is it the same as .Fourier analysis of other SPICE-like tools?

Ken said that he set iteratio large insteading set maxstep. How to set iteratio? What is the default value? I cannot find it using spectre -h.


Thanks
Yawei

Title: Re: thd function in Calculator
Post by Andrew Beckett on May 10th, 2007, 1:38am

The fourier analysis is not quite the same as other simulators (see the chapter in the Designer's Guide to SPICE and SPECTRE which talks about it - first few pages can be seen at http://www.designers-guide.org/Books/dg-spice/ch5.pdf).

lteratio is a transient parameter - you need to run a transient analysis as well. So it's on the transient options form (and can be found in spectre -h tran). The default value is dependent on errpreset. It allows you to loosen the truncation error criteria, and this is particularly useful if you want to tighten tolerances and so gain accuracy without necessarily causing more timesteps to be taken. There's a good discussion of this in the above book.

Regards,

Andrew.

Title: Re: thd function in Calculator
Post by sheldon on May 10th, 2007, 7:05am

Yawei,

  In analogLib is the cell fourier which will instantiate a fourier
analysis component in the schematic and will run a Spectre
fourier analysis after a transient simulation. I would edit the
CDF and add an additional parameter, normharm. Normharm
defines which harmonic to use when normalizing the output
spectrum. The default is to use the first harmonic.

  Just use the normal simulation setup you would typically
use for this simulation. For more information about the
analysis, please see Spectre -h fourier.

                                                      Best Regards,

                                                         Sheldon

Title: Re: thd function in Calculator
Post by driveforce on May 11th, 2007, 1:25am

Hi, Yawei,

Does your cycle here mean input singal cycle or DAC clock cycle?

And secondly, I think harmonics at multiple (clock) frequencies are caused by not only sampling (when you do DFT analysis), but also the image of DAC. DAC's output spectrum (without any FFT sampling) itself has inifinity bandwith and infinity of nyquist band replica, but with sinc shaped.

driveforce



ywguo wrote on May 9th, 2007, 12:00am:
Andrew,

When I simulating a DAC for 512 sampling cycles, sure I want to know the dynamic performance like SFDR, THD. I think 512 points is not enough for FFT, because glitch may be lost. I hope there are 16 points or 32 points per sampling cycle are used for FFT. Then totally 8192 points or 16384 points are used for FFT, and the FFT result expands to 8 times or 16 times sampling frequency. Actually I don't care those outside the nyquist band. The harmonics at multiple frequencies are caused by sampling, not the distortion of DAC. right? But they are summed when I use thd function.

By the way, the average function is defined as Returns the average value of a signal. Can I calculate the average value of a signal from time 1 to time 2? The time 1 and time 2 may not be the start time and stop time of a simulation.


Thanks
Yawei


Title: Re: thd function in Calculator
Post by ywguo on May 12th, 2007, 12:50am

Hi, driveforce,

I mean DAC clock cycle.

Sure I agree with you on the harmonics. They are the image of the DAC.


Yawei

Title: Re: thd function in Calculator
Post by sheldon on May 12th, 2007, 8:50am

Yawei,

  Built a simple example of the testbench that you seem
to be using to test your DAC. If the output spectrum is
showing tones similar to the tones in attached plot, then
modifying the sampling will eliminate the tones.

                                              Best Regards,

                                                 Sheldon

Title: Re: thd function in Calculator
Post by sheldon on May 12th, 2007, 8:52am

Sorry had a problem with the attachment

Title: Re: thd function in Calculator
Post by ywguo on May 13th, 2007, 7:30pm

Hello, Sheldon,

Do you mean that default is wrong? How do you get smoothed?


Thanks
Yawei

Title: Re: thd function in Calculator
Post by sheldon on May 14th, 2007, 12:00am

Yawei,

  Sorry, to clarify

1) From the discussion, I can not visualize the issue you are having.
   In the past, I have seen tones in the response of a DAC and I
   re-created the conditions. Is this frequency spectrum similar to the
   the frequency spectrum you are seeing?

2) If this frequency spectrum is similar to your frequency spectrum,
   then the tones can be eliminated by modifying the input source
   being sampled by the ADC.

3) My apologizes, the meaning of default and smoothed are not
   clear. The intent was
     - default, the setup I would typically use for testing an ADC
     - smoothed, modified setup for DAC to eliminate concentrating
       quantitazation energy in a few frequency bins.

4) In this case, the input source was changed to make sure that
   that each DAC state gets exercised, or to prevent the quantitazation
   noise from being concentrated in a few frequency bins.

                                                           Best Regards,

                                                               Sheldon

Title: Re: thd function in Calculator
Post by venki_vlsi on May 14th, 2007, 10:44pm

If i am not mistaken,,
No of cycles should be odd or prime. IF i am true u  have taken 512 sampling cycles ans since this is even number extra quantization noise is concentrated in  hormonics.hope this true for dac.

Title: Re: thd function in Calculator
Post by ywguo on May 16th, 2007, 2:49am

Hi, Sheldon,


Quote:
1) From the discussion, I can not visualize the issue you are having.
   In the past, I have seen tones in the response of a DAC and I  
   re-created the conditions. Is this frequency spectrum similar to the  
   the frequency spectrum you are seeing?

I am sorry that I cannot put a waveform here because all the workstations are in a private network in my company. I take a look at my simulation results, they look similar as smoothed in your graph.


Quote:
2) If this frequency spectrum is similar to your frequency spectrum,  
   then the tones can be eliminated by modifying the input source
   being sampled by the ADC.

Do you mean modify the input source to ensure a coherent sampling? Then a sine wave or other periodic signal are sampled at the codes which are evenly distributed. So the quantization noise looks like a white noise in the spectrum, NOT concentrate on some frequency points like default. The point 3) and 4) are tightly related to 2). Right?


Thank you
Yawei

The Designer's Guide Community Forum » Powered by YaBB 2.2.2!
YaBB © 2000-2008. All Rights Reserved.