+ Post New Thread
Results 1 to 3 of 3
  1. #1
    Member level 4
    Points: 2,320, Level: 11

    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;
    fft_alternates_zeros.jpg

    •   Alt5th November 2016, 20:13

      advertising

        
       

  2. #2
    Member level 4
    Points: 2,320, Level: 11

    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

    Here is resume of FFT calculations for different values of k (picked from primary numbers): y - FFT Ok, n - FFT alternates '0'.
    fft_of_sin_with_differents_f1.jpg



    •   Alt6th November 2016, 11:00

      advertising

        
       

  3. #3
    Member level 4
    Points: 2,320, Level: 11

    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
--[[ ]]--