[BUG REPORT]triangle oscillator (e.g.120Hz or 1200Hz) is not periodic
Triangle oscillator is sometimes not periodic even if the frequency is a divisor of the sample frequency (e.g.120Hz or 1200Hz at 48kHz) .
Since 48000Hz/1200Hz is an integer, one would expect a perodic behavior, i.e. f(i)=f(i+40).
Althrough we have periodicity at 375Hz/750Hz/1500Hz/3000Hz/6000Hz/12000Hz, this is not the case for e.g.1200Hz.
TriangleSometimesNOTperiodic.dspproj
Audio Signal Processors
sigma studio
Audio Products
software
sigmaStudio 4.7
adau1467
Version 4.7 Build 0. Rev 1831 4/5/2022
SigmaDSP Audio Processors
adau1466
Show More
Hello Michael,
Thank you for attaching your sample project. I also like the way you used the delay and XOR blocks to demonstrate the observed issue.
As you have found out, the problem doesn't occur for certain frequencies. Any frequency covering a power-of-two number of samples always works. These are not the only frequencies that work. Any case where the number of samples in the period and the number (2f / Fs) * (2^24) are both integers, yields a proper result.
So, what's going on? All the oscillators use the parameter (2f / Fs) for their frequency. For the case of 120 Hz, the correct parameter is 2*120 / 48000 = 0.005. As you can see in the screenshot below, SigmaStudio calculated a slightly lower number. Although 120 Hz covers an integral number of samples, the limited resolution of the 8.24 number format upon the frequency parameter prevents an exact 120 Hz.
Solving the parameter calculation backwards, we see that the actual oscillator frequency is:
f = (Fs/2) * param = 24000 * 0.004999995... = 119.99988 Hz
Thus, the real issue here is that the oscillator cannot resolve exactly 120 Hz. To see a little more on this issue, review this thread:
Tone Generation
Best regards,
Bob
Thank you for the really quick answer(<2h).
"Any frequency covering a power-of-two number of samples always works. These are not the only frequencies that work."
These are the only frequencies that work.
To see this let f the oscillator frequency,Fs the sample frequency.
"Any case where the number of samples in the period and the number (2f / Fs) * (2^24) are both integers, yields a proper result."
Call this integers x and y. Then x = Fs/f and y = (2f/Fs)*2^24 = (f/Fs)*2^25. Therefore x*y = (Fs/f)*(f/Fs)*2^25 = 2^25. Then because of unique prime factorization there is an integer 0<=i<=25 with x=2^i and y=2^(25-i). f=y*Fs/2^25=(2^(25-i))*Fs/2^25= fs/2^i
i.e. f is a "frequency covering a power-of-two number of samples".
Nice to have an oscillator translating this 119.99988 to internal 120 and working by counting samples.
Thanks for the correction. So, we can say that although many frequencies have an exact representation in the 8.24 parameter format, yet only a very few have an exact frequency and an integer number of samples in their period. I had a feeling that this might be the case yet could not prove it one way or the other.
Please log in to reply.
