Is it possible to 'interpolate' in FFT data?
8 views (last 30 days)
Show older comments
We kmow OTF and PSF are continuous, can be interpolate inside it (<cutoff freq ) even when we express them wIth matrix use integer row&col coordinate .
now I have a image, and get its FFT2, and find some feature like max or min only with row and col,
but I know true max or min not at that integer row and col exactly, It is really at a fraction position near that integer row and col in matrix.
How to get it if I know fraction or decimal position ?
In frequency domain, can exten matrix size with 0, but can not interpolate although we can interpolate at time domain.
How to do ?
Maybe I can do so like such method : in time domain , matrix .* with exp( - j ke), {ke is a decimal number part }, to realize freq shift effect, after that, FFT, now at that row&col coordinate really is a value corresponding to [ row&col + decimal ke ] position, so I get it .
Such idea is right ? I am not expert at FFT, who can tell me , Is it Right ?
or how to find the feature not exactly at discrete integer row&col coordinate ?
I need some value at real flot number row&col coordinate ?
-----------------------------------------------------------------------------------------------------------------
I mean :
For simple example:
there are 512 data point with coordinate 1~512, transfer to freq domain with FFT, it is 512 mag and phase with coordinate -256~255 * 1/256 .
now if I specially add a cosine wave with freq 10.324 *1/512 to 512 data point (I used it as a special inner reference), then transfer to freq domain with FFT.
here , how to find mag and phase information of this added cosine wave in freq domain ?
freq 10.324 , is not a integer -256~255 coordinate, so how to find it ?
now sample code in 1D list below. ( I need work in 2D in real world) : Is it possible? how?
% Time domain
t = linspace(1,512,512);
g = 2*sin(2*pi*t*16/512) + 0.5*sin(2*pi*t*64/512)+ 0.4*sin(2*pi*t*128/512);
% g = 2*sin(2*pi*t*16/512);
gadd = g+0.2*cos(2*pi*t*180.327/512);
% gadd = g + sin(2*pi*t*10.327/512);
% now add 180.324 or can be any another not N/512
subplot(2,2,1);
plot(g);
title("Time domain 3 sin")
subplot(2,2,2);
plot(g);
title("Time domain, 3 sin + cos")
% freq domain
fco = linspace(-256,255,512);
F=fftshift(fft(g));
F1=fftshift(fft(gadd));
subplot(2,2,3);
stem (fco,real(F));
title("Freq domain, 3 sin")
subplot(2,2,4);
stem (fco,real(F1));
title("Freq domain, 3 sin + cos")
% how to find that 180.327 accuratly ?
% watch freq plot, this wave's energe distrbute on 180 and 181 two point,but how to get 180.327 's ?
% condition : prior I know that freq wave inside them , how to get its information like mag or phase ?
% Maybe should I use Fourier formula directly by myself ?
% like result = sum(data.*exp(-i*2*pi*k*t));
% k is I needed freq, only not any n/datalength limited by data count --- integer numbers!
% if try :
result = sum(gadd.*exp(-1i*2*pi*t*180.327/512));
% now get result is 50.2839072265070 - 0.424971233625617i
% How relate this complex number with wave's Amp=0.2, and phase =0 ?
% try try
Amp=2*real(result)/512;
theta=angl(result);
% get 0.196 and -0.0085, compare with 0.2 and 0,
% not too bad, % I will try other..... Maybe OK can be usded.
% but still do not know how to do for 2D ? my god !
15 Comments
Star Strider
on 27 Jan 2025
‘Interpolating’ risks creeating data that did not previously exist.
If you zero-pad before calculating the Fourier transform, you increase the frequency resolution of the transform. Those will be the actual, calculated results at more frequencies, so no interpolation is necessary, and you do not create data where none previously existed.
Accepted Answer
Paul
on 8 Feb 2025
Hi xd.
Here is one way to think about this problem.
Let c[n] = A*cos(w_0*n + phi) be the reference signal where -pi <= w_0 <= pi and -pi <= phi <= pi.
Let w[n] be a window function that is 0 for n < 0 and n >= N.
The Discrete Time Fourier Transform (DTFT) of g[n] = c[n]w[n] is
where W(w) is the DTFT of w[n].
Hence, if we know G(w) at some frequency we can, in principal, recover A and phi. However, that equation doesn't have a closed form solution for A and phi. But, if we choose a frequency where W(w - w0) is large and W(w + w0) is small, e.g., at w = w0, then we have an approximation

from which A and phi are readily obtained.
The DTFT of a rectangular window of length N is

(implemented this way this function can be a bit wonky for w very close to non-zero, integer multiples of 2*pi, but it's good enough for this exercise):
W = @(w,N) fillmissing((1-exp(-1j*w*N))./(1-exp(-1j*w)),'constant',N);
%W = @(w,N) sum(exp(-1j*w.*(0:N-1).'),1); % straight implementation by definiton
For example
N = 512;
w_0 = 2*pi*180.327/N;
A = 1.8;
phi = 148.123*pi/180;
n = 0:N-1;
g = A*cos(w_0*n + phi);
Compute G(w0)
Gw_0 = sum(g.*exp(-1j*w_0*n));
Divide by the approximate contribution of the window
C = Gw_0/((W(0,N)/2));
Recover amplitude and phase and compare to truth
[abs(C),A]
[angle(C),phi]*180/pi
We see that for this case the effect of the window is basically negligible.
Let's plot the separate contributions of the window
w = (0:2^14-1)/2^14*2*pi;
figure
plot(w,abs(W(w-w_0,N)),w,abs(W(w+w_0,N))),grid
xline(w_0,'g')
xlabel('\omega (rad/sample)');ylabel('abs')
legend('W(\omega-\omega_0)','W(\omega+\omega_0)')
We see that W(w+w0) is very small at w = w_0.
What happens if we increase the frequency of the reference to something closer to pi rad/sample
w_0 = 2*pi*253.327/N;
g = A*cos(w_0*n + phi);
Gw_0 = sum(g.*exp(-1j*w_0*n));
C = Gw_0/((W(0,N)/2));
[abs(C),A]
[angle(C),phi]*180/pi
The estimates of A and phi are a bit off because the W(w+w0) contribution is not quite negligible at w = w_0 for the parameters of this problem (try instead setting w_0 = 2*pi*253/N as an experiment).
figure
plot(w,abs(W(w-w_0,N)),w,abs(W(w+w_0,N))),grid
xline(w_0,'g')
xlabel('\omega (rad/sample)');ylabel('abs')
legend('W(\omega-\omega_0)','W(\omega+\omega_0)')
xlim([-0.1,0.1]+w_0)
In this case, we can resort to solving for A and phi numerically
f1 = @(x) Gw_0 - (x(1))/2*(exp(1j*(x(2)))*W(w_0-w_0,N) + exp(-1j*(x(2)))*W(w_0+w_0,N));
f2 = @(x) [real(f1(x)),imag(f1(x))];
x = fsolve(f2,[abs(Gw_0)/(N/2),angle(Gw_0)]);
[x(1),A]
[x(2),phi]*180/pi
If g[n] includes components in addition to the reference signal, e.g.,
g[n] = s[n]w[n] + c[n]w[n]
then by linearity the DTFT of g[n] is
where F(*) denotes the DTFT of the argument. If that first term on the right is small at a frequency where the second term on the right is large, such as w_0, then we can probably reasonably recover A and phi using the same procedure as above. If not (assuming the specific form of F(s[n]w[n]) is unknown), then there may be limitations as to how accurately A and phi can be estimated.
More Answers (0)
See Also
Categories
Find more on Transforms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



