-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPhasediff.m
111 lines (96 loc) · 2.6 KB
/
Phasediff.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
clc;
close all;
clear all;
a= arduino;%detect the arduino board
f=1000;%in Hz
c=343;%in m/sec
%v=343;%speed of
samples=input('Enter the input sample size: ');
lambda=c/f; %source wavelength in m
l=.04;%in m
%filename = 'Testdata.xlsx';
v0=zeros(samples,1);%A0
v1=zeros(samples,1);%A1
v2=zeros(samples,1);%A2
v3=zeros(samples,1);%A1
v4=zeros(samples,1);%A2
v5=zeros(samples,1);%A0
v6=zeros(samples,1);%A2
v7=zeros(samples,1);%A0
v8=zeros(samples,1);%A1
while 1
%tic;
%1st for loop(Sampling order= 0 1 2)
for i=1:samples
v0(i) = readVoltage(a,'A0');
v1(i) = readVoltage(a,'A1');
v2(i) = readVoltage(a,'A2');
end
%2nd for loop(Sampling order= 1 2 0)
for i=1:samples
v3(i) = readVoltage(a,'A1');
v4(i) = readVoltage(a,'A2');
v5(i) = readVoltage(a,'A0');
end
%3rd for loop(Sampling order= 2 0 1)
for i=1:samples
v6(i) = readVoltage(a,'A2');
v7(i) = readVoltage(a,'A0');
v8(i) = readVoltage(a,'A1');
end
%Phase Seq 1
phim101 = myphase(v0,v1);
phim112 = myphase(v1,v2);
%Phase seq 2
phim201 = myphase(v5,v3);
phim212 = myphase(v3,v4);
%Phase seq 3
phim301 = myphase(v7,v8);
phim312 = myphase(v8,v6);
phi1=myphase((v0+v5+v7)/3,(v1+v3+v8)/3);
phi2=myphase((v1+v3+v8)/3,(v2+v4+v6)/3);
theta2=(phi1+phi2)/2;
%fprintf('Phi1: %f\t%f\t%f\n',phim101,phim201,phim301);
%fprintf('Phi2: %f\t%f\t%f\n',phim112,phim212,phim312);
P1=phim101*phim112;
P2=phim201*phim212;
P3=phim301*phim312;
if(P1>=0)
if(P2>=0)
if(P3>=0)
ph_diff1=(phim101+phim201+phim301)/3;
ph_diff2=(phim112+phim212+phim312)/3;
else
ph_diff1=(phim101+phim201)/2;
ph_diff2=(phim112+phim212)/2;
end
elseif(P3>=0)
ph_diff1=(phim101+phim301)/2;
ph_diff2=(phim112+phim312)/2;
else
ph_diff1=phim101;
ph_diff2=phim112;
end
elseif(P2>=0)
if(P3>=0)
ph_diff1=(phim201+phim301)/2;
ph_diff2=(phim212+phim312)/2;
else
ph_diff1=phim201;
ph_diff2=phim212;
end
elseif(P3>=0)
ph_diff1=phim301;
ph_diff2=phim312;
else
ph_diff1=pi/2;
ph_diff2=pi/2;
end
AngleOfArrival12=asin((ph_diff1*lambda)/(2*pi*l));
%disp(AngleOfArrival12_deg);
AngleOfArrival23=asin((ph_diff2*lambda)/(2*pi*l));
theta=(AngleOfArrival12+AngleOfArrival23)/2;
polarscatter(theta2,1);
drawnow;
%toc;
end