Hello,
So I have a function that has an inverse Lorentzian shape (i.e. -L(x)) and thus it has a local minimum. Now the minimum is at zero, if there is no shift. However as I measure it, the minimum is not exactly at zero, but it is a bit off, i.e. shifted to the left or to the right. What I need is to find this shift. I, of course, don't have the analytical function but the sampled points on it and I assume I can increase the number of samples by interpolation (I use cubic interpolation) without loss of information.
I thought it would be best to use phase correlation to detect this shift.
So now I first take the mirror image of the sampled points I have, thus I have a function that is shifted to the right by s, for example and when I mirror it, I have a function that is shifted to the left by s. And since the Lorentzian is a symmetric function, the both functions look similar except for the location of their minima.
As in wikipedia,
https://en.wikipedia.org/wiki/Phase_correlation, I calculate the phase correlation (pc). However the result of phase correlation gives me a delta peak at zero, i.e. no shift.
I couldn't figure out why I don't get the shift between the two signals with phase correlation, the result should be a delta peak at 2*s in my opinion.
You can find my code as below:
Code:
%to generate the lorentzian:
shift=2;
x=-15:0.1:15;
ls=1/pi * 1./((x-shift).^2 + 1^2);
lsi=-ls;%invert
lsi=lsi-min(lsi);
lsi=lsi./lsi(1);%normalize
lsim=flipdim(lsi,2);%mirror
ns=rand(1,301)*0.1;%add noise, optional
lsin=lsi+ns;
lsimn=lsim+ns;
%calculate the phase correlation
pcab=pcorr(lsi,lsim);
plot(x,fftshift(pcab));
%the pcorr funtion:
function [pc] = pcorr(f1,f2);
F1=fft(f1);
F2=fft(f2);
F2c=conj(F2);
PC=F1.*F2c./abs(F1.*F2c);
pc=ifft(PC);
When I do it theoretically, I get the shift, however not in practice.
Any help appreciated, thanks in advance.
Kerem