Question

I am trying to shift a signal by numbars and 'extrapolate' the signal by shifting the phase of every frequency by its numbars equivalent. The following code works fine except the last (predicted) numbars wrap around to the first values. Am I doing this wrong or Is this fundamental to the (i)fft (and this method cannot be used to extrapolate the signal)?

    t = 1:97;
    x = sin(2*pi*1/10*t+ 2*pi/4) + -0.5+0.01*t + cos(2*pi*1/20*t+pi/3); % eg signal
    numbars = 3; %shift by 3 bars into the future

    % algorithm:
    N = length(x);
    df = 1/N;
    X = fft(x);
    Q = ceil((N+1)/2); % Q = No. of unique spectral points for real-valued time signals
    fQ = (Q-1)*df; % Maximum real frequency
    if N==2*Q-1 % N odd
        X = [ X(1:Q), fliplr(conj(X(2:Q))) ];
    else % N even (= 2*Q-2)
        X = [ X(1:Q), fliplr(conj(X(2:Q-1))) ];
    end;

    %Convert the unipolar spectrum to the bipolar frequency form
    if N==2*Q-1 % N odd
        Xb = [ fliplr(conj(X(2:Q))), X(1:Q) ];
        fb = [ -fQ: df : fQ ];
    else % N even (= 2*Q-2)
        Xb = [ fliplr(conj(X(2:Q-1))), X(1:Q) ];
        fb = [ -fQ: df : fQ-df ];
    end

    % Now to implement a time advance z(t) = x(t+t0)
    t0 = numbars;
    phi0b = 2*pi*fb*t0;
    newsig1 = real(ifft (ifftshift (exp(-1i*phi0b).* Xb)));
    plot([x' newsig1']);

The problem is the last numbars of signal are not 'right', seem to wrap to beginning of signal - the last 3 extrapolated bars should be going up, but they go down instead to the region where the shifted signal started (don't have enough reputation to add an image, please plot in matlab).

Was it helpful?

Solution

The basis vectors of the FFT and IFFT transforms are all circular if extrapolated as longer pure sinusoids. So any data "extrapolation" using reconstruction with only these basis vectors will necessarily be circular, with the end wrapping around to the beginning of the data window.

This is fundamental to the IFFT (of the same length as the FFT).

To possibly remove some of this circular effect, you can try interpolating all the spectral peaks of frequencies in the FFT result, and then using any interpolated frequency peaks that are not periodic in the original window aperture for an extrapolated reconstruction, instead of FFT bins near these peaks that are periodic. Any non-periodic-in-aperture frequencies so estimated will not wrap around circularly in the original FFT length. You can create a signal using frequencies not periodic in the original FFT length by using an IFFT of a much longer length, or by simply summing sinusoids, for your (re)construction or attempt at an extrapolation.

Added: An auto-regressive, linear prediction or maximum likelihood algorithm (instead of an initial FFT for analysis) may also be more suitable for extrapolation use.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top