I am working on a code where digital mixing is to be performed for down-conversion of incoming signal. The mixer signal is created using the phase accumulation approach. However it was observed that the phase error between a signal created with phase accumulation vs that created with a fixed duration time signal had some error which was observed to grow. Can anyone explain the difference and suggest how to avoid this. Code and example result below.
clear all;close all; fs=25e3; sim_time=40e-3; f_mix=5e3; t=0:1/fs:100*sim_time-(1/fs); sig_mix_lref=cos(2*pi*f_mix*t)+j*sin(2*pi*f_mix*t);%create mixer reference ph_ref=wrapToPi(2*pi*f_mix*t);%phase ref for comparison with accumulated phase ph_acc(1)=0;%init phase ph_inc=2*pi*f_mix*1/fs;%phase increment at desired rate ind=2; for i=1:2048:length(sig_mix_lref)-2048 for k=1:2048 sig_mix_l_c(k)=exp(1*j*ph_acc(ind-1));%create mixer block later appended for comparison with reference ph_acc(ind)=ph_acc(ind-1)+ph_inc; ph_acc(ind)=wrapToPi(ph_acc(ind)); %do block mixing here with incoming data stream ind=ind+1; end sig_mix_l(i:i+2048-1)=sig_mix_l_c; end sig_mix_lref=sig_mix_lref(1:length(sig_mix_l)); ph_ref=ph_ref(1:length(ph_acc)); figure;plot(real(sig_mix_lref)-real(sig_mix_l),'-*r') title('mixer comparison error real part') figure;plot(imag(sig_mix_lref)-imag(sig_mix_l),'-*b') title('mixer comparison error imag part') figure;plot(ph_ref-ph_acc,'-*r') title('mixer accum phase error wrt to ref phase')
Although the error scale is negligible, but can anyone explain the reason for growth, how to resolve it?