s1fir = filter(ciccb,1,pcicfb); %Combine compensation and LPF
t = (1:fs/2);
-scpin = .1*sin(t*pi*2*(3000/8000))*i; % initial complex input
+scpin = e.^(i*(t*pi*2*(3000/8000))); % initial complex input
scpin(1) = 1+i;
intstage1 = zeros(1,2*length(scpin)); %First stage of interpolation, 2x
intstage1(1:2:2*length(scpin))=scpin;
-%scpin = filter(s1fir,1,scpin);
scireal = int32(filter(s1fir,1,real(intstage1))*csf); %separate input into real and imiginary and apply pre-distortion
sciimag = int32(filter(s1fir,1,imag(intstage1))*csf); % also convert to integer. CIC integrator needs integer to work properly
-
%Apply 3 stage comb to real
fdin = scireal;
combout1=0;
scoreal=single(fdnext/(2**20));
fdin=sciimag;
+
%Apply 3 stage comb to imag
combout1=0;
combout2=0;
sducinterp(1:M:length(sduceq)*M) = sduceq;
sdac = filter(1,[1 b1x beta1],sducinterp); %select wanted signal
+sdac = sdac + median(sdac); %Center above zero
+sdac = sdac / max(sdac); %normalize
+sdac = int32(sdac*2000); %integerize
+
figure(1)
subplot(211)
plot(20*log10(abs(fft(sducin)/fi)))
//IIR and FIR filter states. Global for go fast.
float f_1,f_2,f;
-int n1_1,n1_2,n1,n2_1,n2_2,n2;
+int n_1,n_2,n;
/*
Upconvert and bandpass filter a chunk of spectrum from Fs/M to Fs. We're going for 700khz here.
f_2 = f_1;
f_1 = modin[i]; //Scale fir output and convert to fixed.
m = (int)((f/(IN_SCALE))*DAC_SCALE_2); //Scale fir output and convert to fixed
- n1 = m + ((B1SMUL*n1_1)>>B1SHFT) - ((B1MUL*n1_2)>>B1SHFT); //Apply one cycle of IIR. This feeds the fir-ed sample into the output filter
- n1_2 = n1_1;
- n1_1 = n1;
- n2 = n1 + ((B1SMUL*n2_1)>>B1SHFT) - ((B1MUL*n2_2)>>B1SHFT);
- n2_2 = n2_1;
- n2_1 = n2;
- dac_out[k]=(unsigned short)(n2+DAC_SCALE_2);
+ n = m + ((B1SMUL*n_1)>>B1SHFT) - ((B1MUL*n_2)>>B1SHFT); //Apply one cycle of IIR. This feeds the fir-ed sample into the output filter
+ n_2 = n_1;
+ n_1 = n;
+ dac_out[k]=(unsigned short)(n+DAC_SCALE_2);
k++;
//now do the rest of the filtering. Because we're zero-stuffing we can neglect the sample from the fir filter.
for(j=1;j<DUC_M;j++,k++){
n = ((B1SMUL*n_1)>>B1SHFT) - ((B1MUL*n_2)>>B1SHFT);
n_2 = n_1;
n_1 = n;
- n2 = n1 + ((B1SMUL*n2_1)>>B1SHFT) - ((B1MUL*n2_2)>>B1SHFT);
- n2_2 = n2_1;
- n2_1 = n2;
- dac_out[k]=(unsigned short)((n2)+DAC_SCALE_2);
+ dac_out[k]=(unsigned short)((n)+DAC_SCALE_2);
}
}
}