pavel47
Member level 4
- Joined
- Nov 8, 2005
- Messages
- 68
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,286
- Location
- Switzerland
- Activity points
- 1,790
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.
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;