I would like to diagnolize a rank-1 matrix using the well known eigenvalue decomposition as $\mathbf{U}^H\mathbf{A}\mathbf{U} = diag (M, 0,\cdots, 0)$, where $\mathbf{A}$ is a Hermitian matrix and $\mathbf{U}$ is a unitary matrix.
While if we use eig.m in matlab, the resulting $\mathbf{U}$ fails to satisfy the property of unitary matrix $\mathbf{U}^H\mathbf{U} = \mathbf{I}_{M}$ due to the unit round-off error and the use of \pi.
What should I do?
The code can be given:
clc
clear all
close all
c = 340;
j = sqrt(-1);
theta_s = 0;
theta_s = theta_s*pi/180;
M = 6;
delta = 0.012;
M_vector = (0:M-1)';
theta = 0:0.1:360;
theta = theta*pi/180;
f = 4000;
%% eigenvalue decomposition of matrix
omega = 2*pi*f;
d = exp(-j*omega*M_vector*delta/c);
h_DS = 1/M*d;
A = d*d';
[U,D] = eig(A);
Due to round-off errors, MATLAB isn't recognizing that your matrix is Hermitian. You can fix this easily by averaging A with its Hermitian transpose:
Once you've done this, U'*U=I as expected.