If I want to simulate a digital oscillator (or phasor) to modulate an arbitrarily length signal: $$y(t) = \cos(2\pi f_ct)\quad\text{where}\quad t = \frac{n}{f_s}\quad\text{for sample}\quad n$$
What is the advantage of using a numerically controlled oscillator (Answered hereAnswered here) versus simply incrementing $n$ over the length of the input?
main():
n = 0 # total samples processed
N = len(input) # num samples in input
blksz = N / 16 # don't create phasor all in one call
# calculate phasor over multiple passes
while ( n < N )
update_phasor(blksz)
# calculate phasor
update_phasor(blksz):
for (i = 0; i < blksz; i++)
y[i] = exp(j*2*pi*fc*n/fs)
n++
The NCO referenced above and the pseudocode implementations give different results and I am trying to understand which makes more sense.
Also, what is the best way to synthesize the phasor if the desired frequency needs to change on the fly?