Signal- und Messdatenverarbeitung


Codes für stochastisch und unabhängig abgetastete, reelle Leistungssignalpaare, ohne Gewichtung

Python Matlab/Octave
Vorbereitung (Laden von Modulen/Paketen)
from numpy import *
from numpy.random import *
from matplotlib.pyplot import *
Generieren von Wertepaaren (tx,i,xi) mit den Messzeitpunkten tx,i und den Messwerten xi mit i=0Nx1 sowie den Wertepaaren (ty,i,yi) mit den Messzeitpunkten ty,i und den Messwerten yi mit i=0Ny1 (zwei korrelierte und gegeneinander verschobene AR1-Prozess als Beispiel, mit Erwartungswerten verschieden von null)
Tx=10000.0
Ty=10100.0
Ti=10.0
drx=1.0
dry=1.5
mxs=3.0
mys=2.0
vxs=1.0
vys=2.0
cc=0.5
c1=sqrt(0.5+0.5*sqrt(1-cc**2/(vxs*vys)))
c2=cc/sqrt(vxs*vys)/(2*c1)
c11=sqrt(vxs)*c1
c12=sqrt(vxs)*c2
c21=sqrt(vys)*c2
c22=sqrt(vys)*c1
tx=[]
ty=[]
x=[]
y=[]
te=0.0
ue=standard_normal()
ve=standard_normal()
while te<maximum(Tx,Ty):
  tp=exponential(1.0/(drx+dry))
  te+=tp
  if te<maximum(Tx,Ty):
    phi=exp(-tp/Ti)
    theta=sqrt(1-phi**2)
    ue=ue*phi+normal(0,theta)
    ve=ve*phi+normal(0,theta)
    if random()<drx/float(drx+dry):
      if te<Tx:
        tx.append(te)
        x.append(c11*ue+c12*ve+mxs)
    else:
      if te<Ty:
        ty.append(te)
        y.append(c21*ue+c22*ve+mys)
      
    
  

tx=array(tx)
ty=array(ty)
x=array(x)
y=array(y)
plot(tx,x,'o',ty,y,'o')
show()
Tx=10000;
Ty=10100;
Ti=10;
drx=1;
dry=1.5;
mxs=3;
mys=2;
vxs=1;
vys=2;
cc=0.5;
c1=sqrt(0.5+0.5*sqrt(1-cc^2/(vxs*vys)));
c2=cc/sqrt(vxs*vys)/(2*c1);
c11=sqrt(vxs)*c1;
c12=sqrt(vxs)*c2;
c21=sqrt(vys)*c2;
c22=sqrt(vys)*c1;
tx=[];
ty=[];
x=[];
y=[];
te=0;
ue=randn();
ve=randn();
while te<max(Tx,Ty)
tp=-log(1-rand())/(drx+dry);
te=te+tp;
if te<max(Tx,Ty)
phi=exp(-tp/Ti);
theta=sqrt(1-phi^2);
ue=ue*phi+theta*randn();
ve=ve*phi+theta*randn();
if rand<drx/(drx+dry)
if te<Tx
tx(end+1)=te;
x(end+1)=c11*ue+c12*ve+mxs;
end
else
if te<Ty
ty(end+1)=te;
y(end+1)=c21*ue+c22*ve+mys;
end
end
end
end
plot(tx,x,'o',ty,y,'o')
Mittelwerte x=1Nxi=0Nx1xi
y=1Nyi=0Ny1yi
mxe=mean(x)
mye=mean(y)
mxe=mean(x)
mye=mean(y)
Varianzen (ohne Bessel-Korrektur, asymptotisch erwartungstreu) sx2=1Nxi=0Nx1(xix)2=(1Nxi=0Nx1xi2)x2
sy2=1Nyi=0Ny1(yiy)2=(1Nyi=0Ny1yi2)y2
vxe=var(x)
vye=var(y)
vxe=var(x,1)
vye=var(y,1)
Kreuzkorrelationsfunktion und Kreuzleistungsdichtespektrum über Slotkorrelation Ryx,k=Ryx(τk)=Rxy(τk)=i=0Nx1j=0Ny1bk(tjti)xiyji=0Nx1j=0Ny1bk(tjti)
bk(t)={1falls 0<|t|<Δt/20sonst
τk=kΔt
k=K/2(K1)/2
K<min(2Tx,2Ty)/Δt
Syx,j=Syx(fj)=ΔtFFT{Ryx,k}=Δtk=K/2(K1)/2Ryx,k𝐞2π𝐢jk/K
(imaginäre Einheit 𝐢)
fj=jKΔt
j=K/2(K1)/2
from numpy.fft import *
Nx=len(tx)
Ny=len(ty)
dt=1.0
K=200
K=minimum(int(ceil(2*minimum(Tx,Ty)/float(dt)))-1,K)
tau=roll(arange(-(K//2),(K+1)//2)*dt,(K+1)//2)
R1=zeros(K)
R0=zeros(K)
i=0
jb=i
while i<Nx:
  j=jb
  while (jb<Ny) and (ty[jb]<tx[i]+((K-1)//2+0.5)*dt):
    jb+=1
  
  j=jb-1
  while (j>=0) and (ty[j]>tx[i]-(K//2+0.5)*dt):
    k=int(round((ty[j]-tx[i])/float(dt)))
    R1[k]+=x[i]*y[j]
    R0[k]+=1.0
    j-=1
  
  i+=1

Ryx=R1/R0
plot(tau,Ryx,'o',arange(-5*K,5*K)*dt/10.0,cc*sqrt(vxs*vys)*exp(-abs(arange(-5*K,5*K)*dt/10.0/float(Ti)))+mxs*mys)
show()
f=roll(arange(-(K//2),(K+1)//2)/float(K*dt),(K+1)//2)
Syx=dt*fft(Ryx)
p1=1-dt/float(Ti)
loglog(f,real(Syx),'o',arange(1,5*K)/float(10*K*dt),cc*sqrt(vxs*vys)*(1-p1**2)*dt/(1+p1**2-2*p1*cos(2*pi*arange(1,5*K)/float(10*K*dt)*dt)),f,imag(Syx),'o')
show()
Nx=length(tx);
Ny=length(ty);
dt=1.0;
K=200;
K=min(ceil(2*min(Tx,Ty)/dt)-1,K);
tau=circshift((-fix(K/2):fix((K-1)/2))*dt,[0;fix((K+1)/2)]);
R1=zeros(1,K);
R0=zeros(1,K);
i=1;
jb=i;
while i<=Nx
j=jb;
while (jb<=Ny) && (ty(jb)<tx(i)+(fix((K-1)/2)+0.5)*dt)
jb=jb+1;
end
j=jb-1;
while (j>0) && (ty(j)>tx(i)-(fix(K/2)+0.5)*dt)
k=round((ty(j)-tx(i))/dt);
R1(mod(K+k,K)+1)=R1(mod(K+k,K)+1)+x(i)*y(j);
R0(mod(K+k,K)+1)=R0(mod(K+k,K)+1)+1;
j=j-1;
end
i=i+1;
end
Ryx=R1./R0;
plot(tau,Ryx,'o',(-5*K:5*K)*dt/10,cc*sqrt(vxs*vys)*exp(-abs((-5*K:5*K)*dt/10/Ti))+mxs*mys)
f=circshift((-fix(K/2):fix((K-1)/2))/(K*dt),[0;fix((K+1)/2)]);
Syx=dt*fft(Ryx);
p1=1-dt/Ti;
loglog(f,real(Syx),'o',(1:5*K)/(10*K*dt),cc*sqrt(vxs*vys)*(1-p1^2)*dt./(1+p1^2-2*p1*cos(2*pi*(1:5*K)/(10*K*dt)*dt)),f,imag(Syx),'o')
Kreuzkorrelationsfunktion und Kreuzleistungsdichtespektrum über Slotkorrelation (mit lokaler Normierung) Ryx,k=Ryx(τk)=Rxy(τk)=[i=0Nx1j=0Ny1bk(tjti)(xix)(yjy)]sx2sy2[i=0Nx1j=0Ny1bk(tjti)(xix)2][i=0Nx1j=0Ny1bk(tjti)(yjy)2]+xy
bk(t)={1falls 0<|t|<Δt/20sonst
τk=kΔt
k=K/2(K1)/2
K<min(2Tx,2Ty)/Δt
Syx,j=Syx(fj)=ΔtFFT{Ryx,k}=Δtk=K/2(K1)/2Ryx,k𝐞2π𝐢jk/K
(imaginäre Einheit 𝐢)
fj=jKΔt
j=K/2(K1)/2
from numpy.fft import *
Nx=len(tx)
Ny=len(ty)
dt=1.0
K=200
K=minimum(int(ceil(2*minimum(Tx,Ty)/float(dt)))-1,K)
tau=roll(arange(-(K//2),(K+1)//2)*dt,(K+1)//2)
mxe=mean(x)
mye=mean(y)
vxe=var(x)
vye=var(y)
R1=zeros(K)
R2=zeros(K)
R3=zeros(K)
i=0
jb=i
while i<Nx:
  j=jb
  while (jb<Ny) and (ty[jb]<tx[i]+((K-1)//2+0.5)*dt):
    jb+=1
  
  j=jb-1
  while (j>=0) and (ty[j]>tx[i]-(K//2+0.5)*dt):
    k=int(round((ty[j]-tx[i])/float(dt)))
    R1[k]+=(x[i]-mxe)*(y[j]-mye)
    R2[k]+=(x[i]-mxe)**2
    R3[k]+=(y[j]-mye)**2
    j-=1
  
  i+=1

Ryx=sqrt(vxe*vye)*R1/sqrt(R2*R3)+mxe*mye
plot(tau,Ryx,'o',arange(-5*K,5*K)*dt/10.0,cc*sqrt(vxs*vys)*exp(-abs(arange(-5*K,5*K)*dt/10.0/float(Ti)))+mxs*mys)
show()
f=roll(arange(-(K//2),(K+1)//2)/float(K*dt),(K+1)//2)
Syx=dt*fft(Ryx)
p1=1-dt/float(Ti)
loglog(f,real(Syx),'o',arange(1,5*K)/float(10*K*dt),cc*sqrt(vxs*vys)*(1-p1**2)*dt/(1+p1**2-2*p1*cos(2*pi*arange(1,5*K)/float(10*K*dt)*dt)),f,imag(Syx),'o')
show()
Nx=length(tx);
Ny=length(ty);
dt=1.0;
K=200;
K=min(ceil(2*min(Tx,Ty)/dt)-1,K);
tau=circshift((-fix(K/2):fix((K-1)/2))*dt,[0;fix((K+1)/2)]);
mxe=mean(x);
mye=mean(y);
vxe=var(x,1);
vye=var(y,1);
R1=zeros(1,K);
R2=zeros(1,K);
R3=zeros(1,K);
i=1;
jb=i;
while i<=Nx
j=jb;
while (jb<=Ny) && (ty(jb)<tx(i)+(fix((K-1)/2)+0.5)*dt)
jb=jb+1;
end
j=jb-1;
while (j>0) && (ty(j)>tx(i)-(fix(K/2)+0.5)*dt)
k=round((ty(j)-tx(i))/dt);
R1(mod(K+k,K)+1)=R1(mod(K+k,K)+1)+(x(i)-mxe)*(y(j)-mye);
R2(mod(K+k,K)+1)=R2(mod(K+k,K)+1)+(x(i)-mxe)^2;
R3(mod(K+k,K)+1)=R3(mod(K+k,K)+1)+(y(j)-mye)^2;
j=j-1;
end
i=i+1;
end
Ryx=sqrt(vxe*vye)*R1./sqrt(R2.*R3)+mxe*mye;
plot(tau,Ryx,'o',(-5*K:5*K)*dt/10,cc*sqrt(vxs*vys)*exp(-abs((-5*K:5*K)*dt/10/Ti))+mxs*mys)
f=circshift((-fix(K/2):fix((K-1)/2))/(K*dt),[0;fix((K+1)/2)]);
Syx=dt*fft(Ryx);
p1=1-dt/Ti;
loglog(f,real(Syx),'o',(1:5*K)/(10*K*dt),cc*sqrt(vxs*vys)*(1-p1^2)*dt./(1+p1^2-2*p1*cos(2*pi*(1:5*K)/(10*K*dt)*dt)),f,imag(Syx),'o')
Kreuzkorrelationsfunktion und Kreuzleistungsdichtespektrum über direkte Spektralschätzung (Fourier-Transformation, ohne Normierung) Eyx,j=Eyx(fj)=TxTyXj*YjNxNy
Xj=i=0Nx1xi𝐞2π𝐢fjtx,i
Yj=i=0Ny1yi𝐞2π𝐢fjty,i
(imaginäre Einheit 𝐢)
fj=jJΔt
j=J/2(J1)/2
J(Tx+Ty)/Δt
RE,yx,k=RE,yx(τk)=1ΔtIFFT{Eyx,j}=1JΔtj=J/2(J1)/2Eyx,j𝐞2π𝐢fjτk/J
Ryx,k=Ryx(τk)=Rxy(τk)=RE,yx,kmin(Tx,Ty,Tx+τk,Tyτk)
τk=kΔt
k=K/2(K1)/2
K<min(2Tx,2Ty)/Δt
Syx,j=Syx(fj)=ΔtFFT{Ryx,k}=Δtk=K/2(K1)/2Ryx,k𝐞2π𝐢jk/K
fj=jKΔt
j=K/2(K1)/2
from numpy.fft import *
Nx=len(tx)
Ny=len(ty)
dt=1.0
J=int(ceil((Tx+Ty)/float(dt)))
fp=roll(arange(-(J//2),(J+1)//2)/float(J*dt),(J+1)//2)
X=zeros(size(fp))+0j
Y=zeros(size(fp))+0j
for i in range(0,Nx):
  X+=x[i]*exp(-2j*pi*fp*tx[i])

for i in range(0,Ny):
  Y+=y[i]*exp(-2j*pi*fp*ty[i])

Eyx=Tx*Ty*conj(X)*Y/float(Nx*Ny)
REyx=real(ifft(Eyx))/float(dt)
K=200
K=minimum(int(ceil(2*minimum(Tx,Ty)/float(dt)))-1,K)
tau=roll(arange(-(K//2),(K+1)//2)*dt,(K+1)//2)
Ryx=zeros(K)
for k in range(-(K//2),(K+1)//2):
  Ryx[k]=REyx[k]/float(minimum(Tx,minimum(Ty,minimum(Tx+tau[k],Ty-tau[k]))))

plot(tau,Ryx,'o',arange(-5*K,5*K)*dt/10.0,cc*sqrt(vxs*vys)*exp(-abs(arange(-5*K,5*K)*dt/10.0/float(Ti)))+mxs*mys)
show()
f=roll(arange(-(K//2),(K+1)//2)/float(K*dt),(K+1)//2)
Syx=dt*fft(Ryx)
p1=1-dt/float(Ti)
loglog(f,real(Syx),'o',arange(1,5*K)/float(10*K*dt),cc*sqrt(vxs*vys)*(1-p1**2)*dt/(1+p1**2-2*p1*cos(2*pi*arange(1,5*K)/float(10*K*dt)*dt)),f,imag(Syx),'o')
show()
Nx=length(tx);
Ny=length(ty);
dt=1.0;
J=ceil((Tx+Ty)/dt);
fp=circshift((-fix(J/2):fix((J-1)/2))/(J*dt),[0;fix((J+1)/2)]);
X=zeros(size(fp))+0j;
Y=zeros(size(fp))+0j;
for i=1:Nx
X=X+x(i)*exp(-2j*pi*fp*tx(i));
end
for i=1:Ny
Y=Y+y(i)*exp(-2j*pi*fp*ty(i));
end
Eyx=Tx*Ty*conj(X).*Y/(Nx*Ny);
REyx=real(ifft(Eyx))/dt;
K=200;
K=min(ceil(2*min(Tx,Ty)/dt)-1,K);
tau=circshift((-fix(K/2):fix((K-1)/2))*dt,[0;fix((K+1)/2)]);
Ryx=zeros([1,K]);
for k=-fix(K/2):fix((K-1)/2)
Ryx(mod(k+K,K)+1)=REyx(mod(k+length(REyx),length(REyx))+1)/min(min(Tx,Ty),min(Tx+tau(mod(k+K,K)+1),Ty-tau(mod(k+K,K)+1)));
end
plot(tau,Ryx,'o',(-5*K:5*K)*dt/10,cc*sqrt(vxs*vys)*exp(-abs((-5*K:5*K)*dt/10/Ti))+mxs*mys)
f=circshift((-fix(K/2):fix((K-1)/2))/(K*dt),[0;fix((K+1)/2)]);
Syx=dt*fft(Ryx);
p1=1-dt/Ti;
loglog(f,real(Syx),'o',(1:5*K)/(10*K*dt),cc*sqrt(vxs*vys)*(1-p1^2)*dt./(1+p1^2-2*p1*cos(2*pi*(1:5*K)/(10*K*dt)*dt)),f,imag(Syx),'o')
Kreuzkorrelationsfunktion und Kreuzleistungsdichtespektrum über direkte Spektralschätzung (Fourier-Transformation, mit Normierung) Eyx,j=Eyx(fj)=TxTyXj*YjNxNy
Eyx,j=Eyx(fj)=TxTyXj*YjNxNy
Xj=i=0Nx1xi𝐞2π𝐢fjtx,i
Yj=i=0Ny1yi𝐞2π𝐢fjty,i
Xj=i=0Nx1𝐞2π𝐢fjtx,i
Yj=i=0Ny1𝐞2π𝐢fjty,i
(imaginäre Einheit 𝐢)
fj=jJΔt
j=J/2(J1)/2
J(Tx+Ty)/Δt
RE,yx,k=RE,yx(τk)=1ΔtIFFT{Eyx,j}=1JΔtj=J/2(J1)/2Eyx,j𝐞2π𝐢fjτk/J
RE,yx,k=RE,yx(τk)=1ΔtIFFT{Eyx,j}=1JΔtj=J/2(J1)/2Eyx,j𝐞2π𝐢fjτk/J
Ryx,k=Ryx(τk)=Rxy(τk)=RE,yx,kRE,yx,k
τk=kΔt
k=K/2(K1)/2
K<min(2Tx,2Ty)/Δt
Syx,j=Syx(fj)=ΔtFFT{Ryx,k}=Δtk=K/2(K1)/2Ryx,k𝐞2π𝐢jk/K
fj=jKΔt
j=K/2(K1)/2
from numpy.fft import *
Nx=len(tx)
Ny=len(ty)
dt=1.0
J=int(ceil((Tx+Ty)/float(dt)))
fp=roll(arange(-(J//2),(J+1)//2)/float(J*dt),(J+1)//2)
X=zeros(size(fp))+0j
Y=zeros(size(fp))+0j
Xp=zeros(size(fp))+0j
Yp=zeros(size(fp))+0j
for i in range(0,Nx):
  X+=x[i]*exp(-2j*pi*fp*tx[i])
  Xp+=exp(-2j*pi*fp*tx[i])

for i in range(0,Ny):
  Y+=y[i]*exp(-2j*pi*fp*ty[i])
  Yp+=exp(-2j*pi*fp*ty[i])

Eyx=Tx*Ty*conj(X)*Y/float(Nx*Ny)
Eyxp=Tx*Ty*conj(Xp)*Yp/float(Nx*Ny)
REyx=real(ifft(Eyx))/float(dt)
REyxp=real(ifft(Eyxp))/float(dt)
K=200
K=minimum(int(ceil(2*minimum(Tx,Ty)/float(dt)))-1,K)
tau=roll(arange(-(K//2),(K+1)//2)*dt,(K+1)//2)
Ryx=zeros(K)
for k in range(-(K//2),(K+1)//2):
  Ryx[k]=REyx[k]/float(REyxp[k])

plot(tau,Ryx,'o',arange(-5*K,5*K)*dt/10.0,cc*sqrt(vxs*vys)*exp(-abs(arange(-5*K,5*K)*dt/10.0/float(Ti)))+mxs*mys)
show()
f=roll(arange(-(K//2),(K+1)//2)/float(K*dt),(K+1)//2)
Syx=dt*fft(Ryx)
p1=1-dt/float(Ti)
loglog(f,real(Syx),'o',arange(1,5*K)/float(10*K*dt),cc*sqrt(vxs*vys)*(1-p1**2)*dt/(1+p1**2-2*p1*cos(2*pi*arange(1,5*K)/float(10*K*dt)*dt)),f,imag(Syx),'o')
show()
Nx=length(tx);
Ny=length(ty);
dt=1.0;
J=ceil((Tx+Ty)/dt);
fp=circshift((-fix(J/2):fix((J-1)/2))/(J*dt),[0;fix((J+1)/2)]);
X=zeros(size(fp))+0j;
Y=zeros(size(fp))+0j;
Xp=zeros(size(fp))+0j;
Yp=zeros(size(fp))+0j;
for i=1:Nx
X=X+x(i)*exp(-2j*pi*fp*tx(i));
Xp=Xp+exp(-2j*pi*fp*tx(i));
end
for i=1:Ny
Y=Y+y(i)*exp(-2j*pi*fp*ty(i));
Yp=Yp+exp(-2j*pi*fp*ty(i));
end
Eyx=Tx*Ty*conj(X).*Y/(Nx*Ny);
Eyxp=Tx*Ty*conj(Xp).*Yp/(Nx*Ny);
REyx=real(ifft(Eyx))/dt;
REyxp=real(ifft(Eyxp))/dt;
K=200;
K=min(ceil(2*min(Tx,Ty)/dt)-1,K);
tau=circshift((-fix(K/2):fix((K-1)/2))*dt,[0;fix((K+1)/2)]);
Ryx=zeros([1,K]);
for k=-fix(K/2):fix((K-1)/2)
Ryx(mod(k+K,K)+1)=REyx(mod(k+length(REyx),length(REyx))+1)/REyxp(mod(k+length(REyxp),length(REyxp))+1);
end
plot(tau,Ryx,'o',(-5*K:5*K)*dt/10,cc*sqrt(vxs*vys)*exp(-abs((-5*K:5*K)*dt/10/Ti))+mxs*mys)
f=circshift((-fix(K/2):fix((K-1)/2))/(K*dt),[0;fix((K+1)/2)]);
Syx=dt*fft(Ryx);
p1=1-dt/Ti;
loglog(f,real(Syx),'o',(1:5*K)/(10*K*dt),cc*sqrt(vxs*vys)*(1-p1^2)*dt./(1+p1^2-2*p1*cos(2*pi*(1:5*K)/(10*K*dt)*dt)),f,imag(Syx),'o')
Kreuzkorrelationsfunktion und Kreuzleistungsdichtespektrum über direkte Spektralschätzung (Fourier-Transformation, mit lokaler Normierung) Eyx,j=Eyx(fj)=TxTyXj*YjNxNy
Eyx,j=Eyx(fj)=TxTyXj*YjNxNy
Eyx,j=Eyx(fj)=TxTyXj*YjNxNy
Xj=i=0Nx1(xix)𝐞2π𝐢fjtx,i
Yj=i=0Ny1(yiy)𝐞2π𝐢fjty,i
Xj=i=0Nx1𝐞2π𝐢fjtx,i
Yj=i=0Ny1𝐞2π𝐢fjty,i
Xj=i=0Nx1(xix)2𝐞2π𝐢fjtx,i
Yj=i=0Ny1(yiy)2𝐞2π𝐢fjty,i
(imaginäre Einheit 𝐢)
fj=jJΔt
j=J/2(J1)/2
J(Tx+Ty)/Δt
RE,yx,k=RE,yx(τk)=1ΔtIFFT{Eyx,j}=1JΔtj=J/2(J1)/2Eyx,j𝐞2π𝐢fjτk/J
RE,yx,k=RE,yx(τk)=1ΔtIFFT{Eyx,j}=1JΔtj=J/2(J1)/2Eyx,j𝐞2π𝐢fjτk/J
RE,yx,k=RE,yx(τk)=1ΔtIFFT{Eyx,j}=1JΔtj=J/2(J1)/2Eyx,j𝐞2π𝐢fjτk/J
Ryx,k=Ryx(τk)=Rxy(τk)=RE,yx,ksx2sy2RE,yx,kRE,yx,k+xy
τk=kΔt
k=K/2(K1)/2
K<min(2Tx,2Ty)/Δt
Syx,j=Syx(fj)=ΔtFFT{Ryx,k}=Δtk=K/2(K1)/2Ryx,k𝐞2π𝐢jk/K
fj=jKΔt
j=K/2(K1)/2
from numpy.fft import *
Nx=len(tx)
Ny=len(ty)
dt=1.0
mxe=mean(x)
mye=mean(y)
vxe=var(x)
vye=var(y)
J=int(ceil((Tx+Ty)/float(dt)))
fp=roll(arange(-(J//2),(J+1)//2)/float(J*dt),(J+1)//2)
X=zeros(size(fp))+0j
Y=zeros(size(fp))+0j
Xp=zeros(size(fp))+0j
Yp=zeros(size(fp))+0j
Xpp=zeros(size(fp))+0j
Ypp=zeros(size(fp))+0j
for i in range(0,Nx):
  X+=(x[i]-mxe)*exp(-2j*pi*fp*tx[i])
  Xp+=exp(-2j*pi*fp*tx[i])
  Xpp+=(x[i]-mxe)**2*exp(-2j*pi*fp*tx[i])

for i in range(0,Ny):
  Y+=(y[i]-mye)*exp(-2j*pi*fp*ty[i])
  Yp+=exp(-2j*pi*fp*ty[i])
  Ypp+=(y[i]-mye)**2*exp(-2j*pi*fp*ty[i])

Eyx=Tx*Ty*conj(X)*Y/float(Nx*Ny)
Eyxp=Tx*Ty*conj(Xpp)*Yp/float(Nx*Ny)
Eyxpp=Tx*Ty*conj(Xp)*Ypp/float(Nx*Ny)
REyx=real(ifft(Eyx))/float(dt)
REyxp=real(ifft(Eyxp))/float(dt)
REyxpp=real(ifft(Eyxpp))/float(dt)
K=200
K=minimum(int(ceil(2*minimum(Tx,Ty)/float(dt)))-1,K)
tau=roll(arange(-(K//2),(K+1)//2)*dt,(K+1)//2)
Ryx=zeros(K)
for k in range(-(K//2),(K+1)//2):
  Ryx[k]=sqrt(vxe*vye)*REyx[k]/sqrt(REyxp[k]*REyxpp[k])+mxe*mye

plot(tau,Ryx,'o',arange(-5*K,5*K)*dt/10.0,cc*sqrt(vxs*vys)*exp(-abs(arange(-5*K,5*K)*dt/10.0/float(Ti)))+mxs*mys)
show()
f=roll(arange(-(K//2),(K+1)//2)/float(K*dt),(K+1)//2)
Syx=dt*fft(Ryx)
p1=1-dt/float(Ti)
loglog(f,real(Syx),'o',arange(1,5*K)/float(10*K*dt),cc*sqrt(vxs*vys)*(1-p1**2)*dt/(1+p1**2-2*p1*cos(2*pi*arange(1,5*K)/float(10*K*dt)*dt)),f,imag(Syx),'o')
show()
Nx=length(tx);
Ny=length(ty);
dt=1.0;
mxe=mean(x);
mye=mean(y);
vxe=var(x,1);
vye=var(y,1);
J=ceil((Tx+Ty)/dt);
fp=circshift((-fix(J/2):fix((J-1)/2))/(J*dt),[0;fix((J+1)/2)]);
X=zeros(size(fp))+0j;
Y=zeros(size(fp))+0j;
Xp=zeros(size(fp))+0j;
Yp=zeros(size(fp))+0j;
Xpp=zeros(size(fp))+0j;
Ypp=zeros(size(fp))+0j;
for i=1:Nx
X=X+(x(i)-mxe)*exp(-2j*pi*fp*tx(i));
Xp=Xp+exp(-2j*pi*fp*tx(i));
Xpp=Xpp+(x(i)-mxe)^2*exp(-2j*pi*fp*tx(i));
end
for i=1:Ny
Y=Y+(y(i)-mye)*exp(-2j*pi*fp*ty(i));
Yp=Yp+exp(-2j*pi*fp*ty(i));
Ypp=Ypp+(y(i)-mye)^2*exp(-2j*pi*fp*ty(i));
end
Eyx=Tx*Ty*conj(X).*Y/(Nx*Ny);
Eyxp=Tx*Ty*conj(Xpp).*Yp/(Nx*Ny);
Eyxpp=Tx*Ty*conj(Xp).*Ypp/(Nx*Ny);
REyx=real(ifft(Eyx))/dt;
REyxp=real(ifft(Eyxp))/dt;
REyxpp=real(ifft(Eyxpp))/dt;
K=200;
K=min(ceil(2*min(Tx,Ty)/dt)-1,K);
tau=circshift((-fix(K/2):fix((K-1)/2))*dt,[0;fix((K+1)/2)]);
Ryx=zeros([1,K]);
for k=-fix(K/2):fix((K-1)/2)
Ryx(mod(k+K,K)+1)=sqrt(vxe*vye)*REyx(mod(k+length(REyx),length(REyx))+1)/sqrt(REyxp(mod(k+length(REyxp),length(REyxp))+1)*REyxpp(mod(k+length(REyxpp),length(REyxpp))+1))+mxe*mye;
end
plot(tau,Ryx,'o',(-5*K:5*K)*dt/10,cc*sqrt(vxs*vys)*exp(-abs((-5*K:5*K)*dt/10/Ti))+mxs*mys)
f=circshift((-fix(K/2):fix((K-1)/2))/(K*dt),[0;fix((K+1)/2)]);
Syx=dt*fft(Ryx);
p1=1-dt/Ti;
loglog(f,real(Syx),'o',(1:5*K)/(10*K*dt),cc*sqrt(vxs*vys)*(1-p1^2)*dt./(1+p1^2-2*p1*cos(2*pi*(1:5*K)/(10*K*dt)*dt)),f,imag(Syx),'o')
(keine Lomb-Scargle-Methode für Kreuzspektren in Matlab und Python)
Kreuzkorrelationsfunktion und Kreuzleistungsdichtespektrum über Zeitquantisierung (ohne Normierung)
from numpy.fft import *
Nx=len(tx)
Ny=len(ty)
dt=1.0
J=int(ceil((Tx+Ty)/float(dt)))
x1=zeros(J)
y1=zeros(J)
for i in range(0,Nx):
  j=int(floor((tx[i]-T*floor(tx[i]/float(T)))/float(dt)))
  x1[j]+=x[i];

for i in range(0,Ny):
  j=int(floor((ty[i]-T*floor(ty[i]/float(T)))/float(dt)))
  y1[j]+=y[i];

X=fft(x1)
Y=fft(y1)
Eyx=Tx*Ty*conj(X)*Y/float(Nx*Ny)
REyx=real(ifft(Eyx))/float(dt)
K=200
K=minimum(int(ceil(2*minminimum((Tx,Ty)/float(dt)))-1,K)
tau=roll(arange(-(K//2),(K+1)//2)*dt,(K+1)//2)
Ryx=zeros(K)
for k in range(-(K//2),(K+1)//2):
  Ryx[k]=REyx[k]/float(minimum(Tx,minimum(Ty,minimum(Tx+tau[k],Ty-tau[k]))))

plot(tau,Ryx,'o',arange(-5*K,5*K)*dt/10.0,cc*sqrt(vxs*vys)*exp(-abs(arange(-5*K,5*K)*dt/10.0/float(Ti)))+mxs*mys)
show()
f=roll(arange(-(K//2),(K+1)//2)/float(K*dt),(K+1)//2)
Syx=dt*fft(Ryx)
p1=1-dt/float(Ti)
loglog(f,real(Syx),'o',arange(1,5*K)/float(10*K*dt),cc*sqrt(vxs*vys)*(1-p1**2)*dt/(1+p1**2-2*p1*cos(2*pi*arange(1,5*K)/float(10*K*dt)*dt)),f,imag(Syx),'o')
show()
Nx=length(tx);
Ny=length(ty);
dt=1.0;
J=ceil((Tx+Ty)/dt);
x1=zeros([1,J]);
y1=zeros([1,J]);
for i=1:Nx
j=fix((tx(i)-T*fix(tx(i)/T))/dt)+1;
x1(j)=x1(j)+x(i);
end
for i=1:Ny
j=fix((ty(i)-T*fix(ty(i)/T))/dt)+1;
y1(j)=y1(j)+y(i);
end
X=fft(x1);
Y=fft(y1);
Eyx=Tx*Ty*conj(X).*Y/(Nx*Ny);
REyx=real(ifft(Eyx))/dt;
K=200;
K=min(ceil(2*min(Tx,Ty)/dt)-1,K);
tau=circshift((-fix(K/2):fix((K-1)/2))*dt,[0;fix((K+1)/2)]);
Ryx=zeros([1,K]);
for k=-fix(K/2):fix((K-1)/2)
Ryx(mod(k+K,K)+1)=REyx(mod(k+length(REyx),length(REyx))+1)/min(min(Tx,Ty),min(Tx+tau(mod(k+K,K)+1),Ty-tau(mod(k+K,K)+1)));
end
plot(tau,Ryx,'o',(-5*K:5*K)*dt/10,cc*sqrt(vxs*vys)*exp(-abs((-5*K:5*K)*dt/10/Ti))+mxs*mys)
f=circshift((-fix(K/2):fix((K-1)/2))/(K*dt),[0;fix((K+1)/2)]);
Syx=dt*fft(Ryx);
p1=1-dt/Ti;
loglog(f,real(Syx),'o',(1:5*K)/(10*K*dt),cc*sqrt(vxs*vys)*(1-p1^2)*dt./(1+p1^2-2*p1*cos(2*pi*(1:5*K)/(10*K*dt)*dt)),f,imag(Syx),'o')
Kreuzkorrelationsfunktion und Kreuzleistungsdichtespektrum über Zeitquantisierung (mit Normierung)
from numpy.fft import *
Nx=len(tx)
Ny=len(ty)
dt=1.0
J=int(ceil((Tx+Ty)/float(dt)))
x0=zeros(J)
y0=zeros(J)
x1=zeros(J)
y1=zeros(J)
for i in range(0,Nx):
  j=int(floor((tx[i]-T*floor(tx[i]/float(T)))/float(dt)))
  x0[j]+=1.0;
  x1[j]+=x[i];

for i in range(0,Ny):
  j=int(floor((ty[i]-T*floor(ty[i]/float(T)))/float(dt)))
  y0[j]+=1.0;
  y1[j]+=y[i];

X=fft(x1)
Y=fft(y1)
Xp=fft(x0)
Yp=fft(y0)
Eyx=Tx*Ty*conj(X)*Y/float(Nx*Ny)
Eyxp=Tx*Ty*conj(Xp)*Yp/float(Nx*Ny)
REyx=real(ifft(Eyx))/float(dt)
REyxp=real(ifft(Eyxp))/float(dt)
K=200
K=minimum(int(ceil(2*minminimum((Tx,Ty)/float(dt)))-1,K)
tau=roll(arange(-(K//2),(K+1)//2)*dt,(K+1)//2)
Ryx=zeros(K)
for k in range(-(K//2),(K+1)//2):
  Ryx[k]=REyx[k]/float(REyxp[k])

plot(tau,Ryx,'o',arange(-5*K,5*K)*dt/10.0,cc*sqrt(vxs*vys)*exp(-abs(arange(-5*K,5*K)*dt/10.0/float(Ti)))+mxs*mys)
show()
f=roll(arange(-(K//2),(K+1)//2)/float(K*dt),(K+1)//2)
Syx=dt*fft(Ryx)
p1=1-dt/float(Ti)
loglog(f,real(Syx),'o',arange(1,5*K)/float(10*K*dt),cc*sqrt(vxs*vys)*(1-p1**2)*dt/(1+p1**2-2*p1*cos(2*pi*arange(1,5*K)/float(10*K*dt)*dt)),f,imag(Syx),'o')
show()
Nx=length(tx);
Ny=length(ty);
dt=1.0;
J=ceil((Tx+Ty)/dt);
x0=zeros([1,J]);
y0=zeros([1,J]);
x1=zeros([1,J]);
y1=zeros([1,J]);
for i=1:Nx
j=fix((tx(i)-T*fix(tx(i)/T))/dt)+1;
x0(j)=x0(j)+1;
x1(j)=x1(j)+x(i);
end
for i=1:Ny
j=fix((ty(i)-T*fix(ty(i)/T))/dt)+1;
y0(j)=y0(j)+1;
y1(j)=y1(j)+y(i);
end
X=fft(x1);
Y=fft(y1);
Xp=fft(x0);
Yp=fft(y0);
Eyx=Tx*Ty*conj(X).*Y/(Nx*Ny);
Eyxp=Tx*Ty*conj(Xp).*Yp/(Nx*Ny);
REyx=real(ifft(Eyx))/dt;
REyxp=real(ifft(Eyxp))/dt;
K=200;
K=min(ceil(2*min(Tx,Ty)/dt)-1,K);
tau=circshift((-fix(K/2):fix((K-1)/2))*dt,[0;fix((K+1)/2)]);
Ryx=zeros([1,K]);
for k=-fix(K/2):fix((K-1)/2)
Ryx(mod(k+K,K)+1)=REyx(mod(k+length(REyx),length(REyx))+1)/REyxp(mod(k+length(REyxp),length(REyxp))+1);
end
plot(tau,Ryx,'o',(-5*K:5*K)*dt/10,cc*sqrt(vxs*vys)*exp(-abs((-5*K:5*K)*dt/10/Ti))+mxs*mys)
f=circshift((-fix(K/2):fix((K-1)/2))/(K*dt),[0;fix((K+1)/2)]);
Syx=dt*fft(Ryx);
p1=1-dt/Ti;
loglog(f,real(Syx),'o',(1:5*K)/(10*K*dt),cc*sqrt(vxs*vys)*(1-p1^2)*dt./(1+p1^2-2*p1*cos(2*pi*(1:5*K)/(10*K*dt)*dt)),f,imag(Syx),'o')
Kreuzkorrelationsfunktion und Kreuzleistungsdichtespektrum über Zeitquantisierung (mit lokaler Normierung)
from numpy.fft import *
Nx=len(tx)
Ny=len(ty)
dt=1.0
mxe=mean(x)
mye=mean(y)
vxe=var(x)
vye=var(y)
J=int(ceil((Tx+Ty)/float(dt)))
x0=zeros(J)
y0=zeros(J)
x1=zeros(J)
y1=zeros(J)
x2=zeros(J)
y2=zeros(J)
for i in range(0,Nx):
  j=int(floor((tx[i]-T*floor(tx[i]/float(T)))/float(dt)))
  x0[j]+=1.0;
  x1[j]+=x[i]-mxe;
  x2[j]+=(x[i]-mxe)**2;

for i in range(0,Ny):
  j=int(floor((ty[i]-T*floor(ty[i]/float(T)))/float(dt)))
  y0[j]+=1.0;
  y1[j]+=y[i]-mye;
  y2[j]+=(y[i]-mye)**2;

X=fft(x1)
Y=fft(y1)
Xp=fft(x0)
Yp=fft(y0)
Xpp=fft(x2)
Ypp=fft(y2)
Eyx=Tx*Ty*conj(X)*Y/float(Nx*Ny)
Eyxp=Tx*Ty*conj(Xpp)*Yp/float(Nx*Ny)
Eyxpp=Tx*Ty*conj(Xp)*Ypp/float(Nx*Ny)
REyx=real(ifft(Eyx))/float(dt)
REyxp=real(ifft(Eyxp))/float(dt)
REyxpp=real(ifft(Eyxpp))/float(dt)
K=200
K=minimum(int(ceil(2*minminimum((Tx,Ty)/float(dt)))-1,K)
tau=roll(arange(-(K//2),(K+1)//2)*dt,(K+1)//2)
Ryx=zeros(K)
for k in range(-(K//2),(K+1)//2):
  Ryx[k]=sqrt(vxe*vye)*REyx[k]/sqrt(REyxp[k]*REyxpp[k])+mxe*mye

plot(tau,Ryx,'o',arange(-5*K,5*K)*dt/10.0,cc*sqrt(vxs*vys)*exp(-abs(arange(-5*K,5*K)*dt/10.0/float(Ti)))+mxs*mys)
show()
f=roll(arange(-(K//2),(K+1)//2)/float(K*dt),(K+1)//2)
Syx=dt*fft(Ryx)
p1=1-dt/float(Ti)
loglog(f,real(Syx),'o',arange(1,5*K)/float(10*K*dt),cc*sqrt(vxs*vys)*(1-p1**2)*dt/(1+p1**2-2*p1*cos(2*pi*arange(1,5*K)/float(10*K*dt)*dt)),f,imag(Syx),'o')
show()
Nx=length(tx);
Ny=length(ty);
dt=1.0;
mxe=mean(x);
mye=mean(y);
vxe=var(x,1);
vye=var(y,1);
J=ceil((Tx+Ty)/dt);
x0=zeros([1,J]);
y0=zeros([1,J]);
x1=zeros([1,J]);
y1=zeros([1,J]);
x2=zeros([1,J]);
y2=zeros([1,J]);
for i=1:Nx
j=fix((tx(i)-T*fix(tx(i)/T))/dt)+1;
x0(j)=x0(j)+1;
x1(j)=x1(j)+x(i)-mxe;
x2(j)=x2(j)+(x(i)-mxe)^2;
end
for i=1:Ny
j=fix((ty(i)-T*fix(ty(i)/T))/dt)+1;
y0(j)=y0(j)+1;
y1(j)=y1(j)+y(i)-mye;
y2(j)=y2(j)+(y(i)-mye)^2;
end
X=fft(x1);
Y=fft(y1);
Xp=fft(x0);
Yp=fft(y0);
Xpp=fft(x2);
Ypp=fft(y2);
Eyx=Tx*Ty*conj(X).*Y/(Nx*Ny);
Eyxp=Tx*Ty*conj(Xpp).*Yp/(Nx*Ny);
Eyxpp=Tx*Ty*conj(Xp).*Ypp/(Nx*Ny);
REyx=real(ifft(Eyx))/dt;
REyxp=real(ifft(Eyxp))/dt;
REyxpp=real(ifft(Eyxpp))/dt;
K=200;
K=min(ceil(2*min(Tx,Ty)/dt)-1,K);
tau=circshift((-fix(K/2):fix((K-1)/2))*dt,[0;fix((K+1)/2)]);
Ryx=zeros([1,K]);
for k=-fix(K/2):fix((K-1)/2)
Ryx(mod(k+K,K)+1)=sqrt(vxe*vye)*REyx(mod(k+length(REyx),length(REyx))+1)/sqrt(REyxp(mod(k+length(REyxp),length(REyxp))+1)*REyxpp(mod(k+length(REyxpp),length(REyxpp))+1))+mxe*mye;
end
plot(tau,Ryx,'o',(-5*K:5*K)*dt/10,cc*sqrt(vxs*vys)*exp(-abs((-5*K:5*K)*dt/10/Ti))+mxs*mys)
f=circshift((-fix(K/2):fix((K-1)/2))/(K*dt),[0;fix((K+1)/2)]);
Syx=dt*fft(Ryx);
p1=1-dt/Ti;
loglog(f,real(Syx),'o',(1:5*K)/(10*K*dt),cc*sqrt(vxs*vys)*(1-p1^2)*dt./(1+p1^2-2*p1*cos(2*pi*(1:5*K)/(10*K*dt)*dt)),f,imag(Syx),'o')
Kreuzkorrelationsfunktion und Kreuzleistungsdichtespektrum über Interpolation (Sample-and-Hold, mit Filterkorrektur, ohne Normierung)
from numpy.fft import *
Nx=len(tx)
Ny=len(ty)
dt=1.0
J=int(ceil((Tx+Ty)/float(dt)))
xp=zeros(J)
yp=zeros(J)
for i in range(0,Nx):
  for j in range(int(floor(tx[i]/float(dt)))+1,int(floor((tx[(i+1)%Nx]+Tx*((i+1)//Nx))/float(dt)))+1):
    xp[j]=x[i]
  

for i in range(0,Ny):
  for j in range(int(floor(ty[i]/float(dt)))+1,int(floor((ty[(i+1)%Ny]+Ty*((i+1)//Ny))/float(dt)))+1):
    yp[j]=y[i]
  

Xp=fft(xp)
Yp=fft(yp)
Eyxp=dt**2*conj(Xp)*Yp
REyxp=real(ifft(Eyxp))/float(dt)
K=200
K=minimum(int(ceil(2*minimum(Tx,Ty)/float(dt)))-1,K)
tau=roll(arange(-(K//2),(K+1)//2)*dt,(K+1)//2)
Ryx=zeros(K)
cx=exp(-ddx/float(dt))/((1-exp(-ddx/float(dt)))*(1-exp(-ddy/float(dt))))
cy=exp(-ddy/float(dt))/((1-exp(-ddx/float(dt)))*(1-exp(-ddy/float(dt))))
for k in range(-(K//2),(K+1)//2):
  Ryx[k]=((cx+cy+1)*REyxp[k]-cy*REyxp[k-1]-cx*REyxp[k+1])/float(minimum(Tx,minimum(Ty,minimum(Tx+tau[k],Ty-tau[k]))))

plot(tau,Ryx,'o',arange(-5*K,5*K)*dt/10.0,cc*sqrt(vxs*vys)*exp(-abs(arange(-5*K,5*K)*dt/10.0/float(Ti)))+mxs*mys)
show()
f=roll(arange(-(K//2),(K+1)//2)/float(K*dt),(K+1)//2)
Syx=dt*fft(Ryx)
p1=1-dt/float(Ti)
loglog(f,real(Syx),'o',arange(1,5*K)/float(10*K*dt),cc*sqrt(vxs*vys)*(1-p1**2)*dt/(1+p1**2-2*p1*cos(2*pi*arange(1,5*K)/float(10*K*dt)*dt)),f,imag(Syx),'o')
show()
Nx=length(tx);
Ny=length(ty);
dt=1.0;
J=ceil((Tx+Ty)/dt);
xp=zeros([1,J]);
yp=zeros([1,J]);
for i=1:Nx
for j=fix(tx(i)/dt)+2:fix((tx(mod(i,Nx)+1)+Tx*fix(i/Nx))/dt)+1
xp(j)=x(i);
end
end
for i=1:Ny
for j=fix(ty(i)/dt)+2:fix((ty(mod(i,Ny)+1)+Ty*fix(i/Ny))/dt)+1
yp(j)=y(i);
end
end
Xp=fft(xp);
Yp=fft(yp);
Eyxp=dt^2*conj(Xp).*Yp;
REyxp=real(ifft(Eyxp))/dt;
K=200;
K=min(ceil(2*min(Tx,Ty)/dt)-1,K);
tau=circshift((-fix(K/2):fix((K-1)/2))*dt,[0;fix((K+1)/2)]);
Ryx=zeros([1,K]);
cx=exp(-ddx/dt)/((1-exp(-ddx/dt))*(1-exp(-ddy/dt)));
cy=exp(-ddy/dt)/((1-exp(-ddx/dt))*(1-exp(-ddy/dt)));
for k=-fix(K/2):fix((K-1)/2)
Ryx(mod(k+K,K)+1)=((cx+cy+1)*REyxp(mod(k+length(REyxp),length(REyxp))+1)-cy*REyxp(mod(k-1+length(REyxp),length(REyxp))+1)-cx*REyxp(mod(k+1+length(REyxp),length(REyxp))+1))/min(min(Tx,Ty),min(Tx+tau(mod(k+K,K)+1),Ty-tau(mod(k+K,K)+1)));
end
plot(tau,Ryx,'o',(-5*K:5*K)*dt/10,cc*sqrt(vxs*vys)*exp(-abs((-5*K:5*K)*dt/10/Ti))+mxs*mys)
f=circshift((-fix(K/2):fix((K-1)/2))/(K*dt),[0;fix((K+1)/2)]);
Syx=dt*fft(Ryx);
p1=1-dt/Ti;
loglog(f,real(Syx),'o',(1:5*K)/(10*K*dt),cc*sqrt(vxs*vys)*(1-p1^2)*dt./(1+p1^2-2*p1*cos(2*pi*(1:5*K)/(10*K*dt)*dt)),f,imag(Syx),'o')