# Difference between two sine generators

I have two sine oscillators and I get these two different spectrum analysis (let's disregard the slight frequency difference). Is there any deductions that can be made about the "quality", or sine approximation error or any other type of information about the sine generators derived by these graphs? Why the second is more steep? Is it normal? Which of the two is closer to the ideal sine FFT spectrum? What to read so to understand differences of this type?

The sample rate is 32k and there are 8192 frequency bins.

The code that produces this difference is:

a. (upper graph)

double freq;
static double sine_rate;

sine_rate += freq;
*var = (long) ( sin( sine_rate ) * 2142483647.0 );


b.

double freq;
static double sine_rate;

sine_rate += freq;
*var = (long) ( sin( sine_rate * PI ) * 2142483647.0 );


double "freq" is provided when the function is called and can be any double between 0.0 and 1.0. The difference is the multiplication by 3.14.

• The bottom one is narrower, and thus closer to a "true" sine.
– MBaz
Commented Apr 22, 2019 at 18:12
• Did you use a window function other than rectangular? Commented Apr 23, 2019 at 3:41
• @Olli Niemitalo No the FFT function is the same. The first used sin(counter++) and the secondary sin( (counter++) * PI ). So the difference is that the second is wrapped by PI and the first is not. I would like to be able to understand how the sine function works and hoped someone would give me some hints here. Commented Apr 23, 2019 at 6:14
• How is counter related to the sample number? They can't be equal because the frequency should be 16 k whereas your lower graph shows a frequency of about 200. What do you mean by wrapping? It would be more clear to post also the code in the question. Commented Apr 23, 2019 at 6:29
• @Olli Niemitalo I will do it in a moment. Yes it is simplified as I posted in the comment. By wrapping I mean constrain. Commented Apr 23, 2019 at 7:13

The two oscillator types are equivalent, because the factor PI can be moved to freq and need not be present in the final equation.
With the oscillator of type a, if freq is of form some_integer*2*PI/N, where N is the DFT length, then the sine frequency is one of the harmonic frequencies seen by DFT and there will be no spectral leakage.