+ Post New Thread

Results 1 to 3 of 3

- 5th November 2016, 21:13 #1

- Join Date
- Nov 2005
- Location
- Switzerland
- Posts
- 68
- Helped
- 0 / 0
- Points
- 2,320
- Level
- 11

## FFT alternates '0' for a quantized SIN wave

Hello,

Doing FFT exercises in Matlab I've discovered that for some frequencies (defined by**k**) the FFT of quantized SIN wave alternates '0'.

For k I used primary numbers.

With k = 11, 13, 17, 19, 23, 29, 31, 37 it's Ok

With K = 3, 5, 7, 41, 53, 67, 101, 127 FFT alternates '0'.

Any ideas ?

Thanks in advance.

Pavel.

Code:close all; % clear all; L = 2^14; res = 10; A = 1; Fs = 1e+5; k = 41; f1 = k/L*Fs; t = (0:L-1)/Fs; y = A*sin(2*pi*f1*t); % Display Original Signal figure(1) plot(t, y); grid on; % Quantization dA = (2*A)/2^res; partition = (-A+dA:dA:A-dA); codebook = (0:2^res-1); [index,yq] = quantiz(y,partition,codebook); yq = (yq - 2^(res-1))/2^res*2*A; % Display Quantized Signal figure(2); plot(t,yq); grid on; % Display Quantization Error figure(3); plot(t, y-yq); grid on; P2 = abs(fft(yq, L))/L; P1 = P2(1:L/2+1); P1(2:end-1) = 2*P1(2:end-1); f = Fs*(0:(L/2))/L; % Display FFT figure(4); plot(f, mag2db(P1)); grid on;

- 5th November 2016, 21:13

- 6th November 2016, 12:00 #2

- Join Date
- Nov 2005
- Location
- Switzerland
- Posts
- 68
- Helped
- 0 / 0
- Points
- 2,320
- Level
- 11

- 6th November 2016, 12:00

- 7th November 2016, 15:24 #3

- Join Date
- Nov 2005
- Location
- Switzerland
- Posts
- 68
- Helped
- 0 / 0
- Points
- 2,320
- Level
- 11

## Re: FFT alternates '0' for a quantized SIN wave

Resolved.

The problem was in erroneous quantization.

Here is the correct quantization code:

% Quantization

dy = (2*A)/(2^res-1);

partition = (-A+A/2^res:dy:A-A/2^res);

codebook = (0:2^res-1);

[index,yq] = quantiz(y,partition,codebook);

yq = 2*A*yq/(2^res-1)-A;

where:

y - SIN waveform values

A - amplitude of SIN waveform

res - resolution of quantizer

+ Post New Thread

Please login