"Conrad" wrote in message <jaf3sd$ace$1@newscl01ah.mathworks.com>...
> Hi,
> I have the code below to reconstruct a signal. I'm trying to regenerate y2 from y, so that for each value of x2, there is a corresponding y2 value. For N2=15, the signal appears to be shifted compared to the original. Can anyone tell me how to fix this problem? Thank you
>
> x=[1;2;4;5;6;7;8;10;12;14;15];
> y=[8.46;8.64;8.69;8.69;8.57;8.64;8.46;8.39;8.39;8.93;9.3];
> ff2=fft(y);
> N = length(y);
> N2=x(end); % length of reconstruction
> y2= ff2(1)/(N);
> p = 2*pi*((0:N21)/N2);
> for k = 1:(length(ff2)/2)
> a = ff2(k+1);
> phi = k*p;
> if k < N2/2; s = 2; else s = 1; end
> component = s*(real(a)*cos(phi)  imag(a)*sin(phi))/N;
> y2 = y2 + component;
> end
> x2=1:N2;
> figure; plot(x,y); hold on; plot(x2,y2,'r');
You can use Extended DFT available on fileexchange http://www.mathworks.com/matlabcentral/fileexchange/11020extendeddft
Application of program edft.m is following: put NaNs (NotaNumber) where data are missing
y_nan=[8.46;8.64;NaN;8.69;8.69;8.57;8.64;8.46;NaN;8.39;NaN;8.39;NaN;8.93;9.3];
and run
y2=real(ifft(edft(y_nan,124)));
The first 15 samples of y2 are your data where NaNs are replaced with interpolated values, the rest of y2 are forward/backward extrapolation.
Regards
Vilnis
