Offset effect in FFT magnitude

i will use matlab code just for convenience, i get the same behavior using a C++ code.

I have two signals:

Fp=5;
A=0.00025;
Phi=0;
Off=0.5;

tc=250e-6;
tmax=30;
t=0:tc:tmax;

Buf1= int32 ((A*cos(2.0*pi*t*Fp+ Phi*pi/180.0)+Off)/(KADC_5VOLT));
Buf2= int32 ((A*cos(2.0*pi*t*Fp+ Phi*pi/180.0)+0)/(KADC_5VOLT));

Buf1=double(Buf1);
Buf2=double(Buf2);

performing a FFT on Buf1 i get amplitude 2.4246e-04 for the 5 Hz component ((this values seems to change randomly as a function of A, while A is small); while for Buf2 i get amplitude 2.6287e-04 for the 5 Hz component. If i set A > 0.0015, performing a FFT on Buf1 and Buf2 i get amplitude 0.0015 for the 5 Hz component;

if i use just:

performing a FFT on Buf1 and Buf2 i get amplitude 2.5000e-04 for the 5 Hz component.

What is the reason of that? is seems that the problem is related to a quantization error, but why is the offset so important? Also: how can i get rid of it?

Since your offset is 3/5ths (plus some integer), the truncation fractions will be different, resulting in a different sum of quantization noise. You can get rid of this difference by using an integer offset (including/after scaling) before truncation or rounding. (e.g. not (2^N)/5)

Also, if your signal is not exactly periodic in your FFT aperture, then the result magnitude of very low frequencies will have a small dependence on phase, relative to the window (edge or center), and thus not exactly match the input amplitude.

Firstly you didn't mention your sample rate and how your time vector is defined.

Yes, this is a quantization problem. The maximum amplitude in Buf2 is 1.6. If you quantize that to integers you only end up with the values -2,-1,0,1,2 so you have massive amounts of quantization noise. You are only quantizing this two 2 or 3 bits. The correct way to turn this into fixed point would be the apply proper scaling, i.e using fractionals, Q notation or some reasonable normalization scheme.

Adding the offset just shifts the problem around. The only numbers that you get will be 3275, 3276, 3277 and 3278.

The bigger amplitude in Buf1 is simply just quantization noise from the very large added DC component.

• edited with the information that i didn't mentioned. What surprises me is that Buf2 does not have a large DC component. Its offset is set to zero. – BiA Jul 22 '13 at 13:51
• Sorry, my bad. Buf1 has the large DC offset. Again, you have enormous amounts of quantization noise, so all bets are off. – Hilmar Jul 22 '13 at 15:18