How to “normalize”(?) a vector after fft in MATLAB?
Show older comments
I want to change from real-space repr. to momentum-space repr. I have a Hamilton-operator (Anderson-model), and I calculated some kind of entropy of its eigenstates (this is working, I see what I want). Next I want to change to momentum repr. using fft, and now my eigenstates in momentum space are not normalized (?). E.g. if I calculate the sum of the eigenstates^2, it has to be 1, but it does not work.
I tried to sum the eigenstates^2 and normalized with them, but It does not work (I show the code without any failed trying).
N=100; %dim of matrix
Nx=15; %number of points
%because of log scale
xmin = -3.0;
xmax = 3.0;
dx = (xmax - xmin)/(Nx-1);
x = zeros(1,Nx); %x axis pre
ss = zeros(1,Nx); %entropy pre
spp=zeros(1,Nx); %entropy in Fourier space pre
eps=1.0e-6;
for ix=1:Nx
%log scale
x(ix) = xmin + (ix-1)*dx;
xx = 10.0^x(ix);
average_s=0;
average_spp=0;
%anderson modell
W=xx;
r=rand(1,N)*W-(W/2);
A=diag(ones(1,N-1),1)+diag(ones(1,N-1),-1)+diag(r);
%diagonalization
[V,D]=eig(A);
%PROBLEM HERE:
%Fourier transformation
P=fft(V)/(sqrt(2*pi)*N);
P=abs(P);
for j=1:N
four_sum=0; square_sum=0; entropy=0;
four_sum_p=0; square_sum_p=0; entropyp=0;
for i=1:N
%Fou
probp=(P(i,j)).^2;
square_sum_p=square_sum_p+probp;
if probp>eps
entropyp=entropyp-probp*log(probp);
end;
four_sum_p=four_sum_p+probp.^2;
%Real
prob=V(i,j).^2;
square_sum=square_sum+prob;
if prob>eps
entropy=entropy-prob*log(prob);
end;
four_sum=four_sum+prob.^2;
end
qp=square_sum_p.^2/(four_sum_p);
average_spp=average_spp+entropyp-log(qp);
q=square_sum.^2/(four_sum);
average_s=average_s+entropy-log(q);
end
ss(ix)=average_s/N;
spp(ix)=average_spp/N;
end
plot(x,ss,x,spp);
The structural entropy in real space (ss vector) has the correct form, but in momentum space (spp) after fft is not look like what I want, and it is not normalized.
Answers (0)
Categories
Find more on Fast Fourier 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!