MATLAB: Initial phase angle calculation

initial phase angle

hello
I have this signal
clear all;clc;
t=0:0.0001:10;
tt=t(1:100000);%take 100 000 samples
a=30*pi/180; %phase (calculated form deg. to rad.)

b=90*pi/180; %phase (calculated form deg. to rad.)
ia=5*cos(2*pi*10*tt-a)+7*cos(2*pi*50*tt-b);
fs=1/0.0001; %sampling frequency
X=fft(ia); %FFT
df=fs/length(X); %frequency resolution
f=(0:1:length(X)/2)*df; %frequency axis
subplot(2,1,1);
M=abs(X)/length(ia)*2; %amplitude spectrum
plot(f,M(1:length(f)));
subplot(2,1,2);
P=angle(X)*180/pi; %phase spectrum (in deg.)
plot(f,P(1:length(f)));
this technique do not give a good results; I want any technique to get the right "a" an "d" the initial phase angle of 10 HZ and 50 HZ;
I know it is a hard question but please help me

Best Answer

I ran your code it and seems to be working as-is. -30 and -90 deg at 10 and 50Hz