When I recreate a signal it seems to look great. But when I try and increase it's frequency (which is done in a for loop and the variable new_freq=2) it starts to drift.
See Image below (The top image is 1hz and the bottom image is 2hz. I circled the image with the problem). I also noticed when I increase the sample frequency the problem gets even more noticeable. Notice the top one is at 8000 as the sample frequency and the bottom one is at sample frequency of 44100.
I've posted the for loop below any ideas why the variables aa_sig_rebuilt_norm_bin and aa_sig_combined_norm_bin are drifting so much? Please note I'm using much more complex signals than just sine waves (if I were just using sine waves I would use the sinwave equation to increase the frequency. I used a sinewave as an example)
The whole for loop is base on rebuilding a signal using the equation AmplitudeCos(freqtime+phase) I did an fft/ifft to get all the frequencies/amplitudes/phases then just change the frequency to what I want
I do want to vectorize this for loop but at the moment I'm trying to fix the drift
new_freq=; %increase frequency fn_array=; array1=[xfreq_orig,yamp_orig,yamp_inv,phase_orig,mod(phase_in_deg,360),phase_in_rad,phase_adjindeg,phase_adjinrad]; %have degs only go up to 360 t_rebuilt=linspace(0,2*pi,fs); for zz=1:1:length(new_freq); % zz %needs to be in for loop to reset variables for next new_freq aa_sig_rebuilt_norm=zeros(1,length(t_rebuilt)); aa_sig_rebuilt_norm_bin=zeros(1,length(t_rebuilt)); aa_sig_combined_norm=zeros(1,length(t_rebuilt)); aa_sig_combined_norm_bin=zeros(1,length(t_rebuilt)); sig_norm=zeros(1,length(t_rebuilt)); sig_norm_bin=zeros(1,length(t_rebuilt)); for kk=1:1:length(xfreq_orig); aa_sig_rebuilt_norm = array1(kk, 2)*cos (array1(kk,1)*t_rebuilt+(array1(kk, 4))); aa_sig_combined_norm = aa_sig_combined_norm + aa_sig_rebuilt_norm; aa_sig_rebuilt_norm_bin = array1(kk, 2)*cos ((new_freq(zz,1))*array1(kk,1)*t_rebuilt+(array1(kk, 4))); %binural section aa_sig_combined_norm_bin = aa_sig_combined_norm_bin + aa_sig_rebuilt_norm_bin; end; %have it export to file sig_norm=(aa_sig_combined_norm/max(abs(aa_sig_combined_norm))*.8); %normalize signal sig_norm_bin=(aa_sig_combined_norm_bin/max(abs(aa_sig_combined_norm_bin))*.8); %normalize signal wavwrite([sig_norm' sig_norm_bin'] ,fs,16,strcat(dirpathtmp,fn_LR_norm_bin)); %export file end;