close all
frequency = 3e9;
lambda = 3e8/frequency;
antenna_spacing = lambda/6;
time_spacing = 1/6/frequency;
x_number = 40; t_number = 40;


axis = cell(x_number*t_number,1);
for i = 1:x_number
    for j = 1:t_number
            axis{(i-1)*t_number+j} = [i*antenna_spacing,j*time_spacing];
    end
end

[kernel_matrix] = kernel_calculate(frequency,axis,"4d_ball");
% [kernel_matrix1] = kernel_calculate(frequency,axis,"4d_ball_test");
% 
% %%
% z = inv(kernel_matrix)./inv(kernel_matrix1);
% 
% %%


[eigen_vector,eigen_value] = eig(kernel_matrix);

eigen_vector2matrix = zeros(x_number,t_number);
%for iter = 1600:-1:1600-10 
for iter = 1600:-1:1600-10 
for i = 1:x_number
    for j = 1:t_number
            eigen_vector2matrix(i,j) = eigen_vector((i-1)*t_number+j,iter);
    end
end

figure
[x,y]=meshgrid(1:t_number,1:x_number);
mesh(x,y,abs(eigen_vector2matrix));
xlabel('Time','Interpreter','latex','FontSize',12,'Rotation',15);
ylabel('Space','Interpreter','latex','FontSize',12,'Rotation',-30);
zlabel('Amplitude','Interpreter','latex','FontSize',12);
%plot(eigen_vector2matrix)
%shading interp; 
end

correlation_size = 40;
correlation = zeros(correlation_size);
for i = 1: correlation_size
    for j = 1:correlation_size
        correlation(i,j) = eigen_vector(:,i)'*eigen_vector(:,j);
    end
end
[X,Y] = meshgrid(1:correlation_size,1:correlation_size);

figure
H1=mesh(X,Y,abs(correlation));
grid on
xlabel('Eigenfunction number','Interpreter','latex','FontSize',12,'Rotation',15);
ylabel('Eigenfunction number','Interpreter','latex','FontSize',12,'Rotation',-30);
zlabel('Correlation','Interpreter','latex','FontSize',12);

eigen_value = diag(eigen_value);
eigen_value = flip(eigen_value);

figure
plot(eigen_value,'-s','color','red','Linewidth',1.5,'markersize',4)

grid on
xlabel('number of eigenvalue','Interpreter','latex','FontSize',14);
ylabel('eigenvalue','Interpreter','latex','FontSize',14);