2012/Projects/OwlPlatform/TransmitterTester: planeplotter.m

File planeplotter.m, 4.4 KB (added by saik, 5 years ago)

The matlab code that plots the XY, YZ and XZ graphs and diplays average power.

Line 
1clear;
2clc;
3TagID=input('What is the TagID: ');
4BrdID=input('What is the Broadcast ID: ');
5
6angleFileID(3)=zeros(size(3,1));
7%% first file
8angleFileID(1)= fopen(strcat('dataFileXY.txt'));
9if angleFileID(1)==-1, error('Cannot Open File dataFileXY.txt' ),end;
10
11
12%% Second file
13angleFileID(2)= fopen(strcat('dataFileXZ.txt'));
14if angleFileID(2)==-1, error('Cannot Open File dataFileXZ.txt'),end;
15
16%% Third file
17angleFileID(3)= fopen(strcat('dataFileYZ.txt'));
18if angleFileID(3)==-1, error('Cannot Open File dataFileYZ.txt'),end;
19
20
21%% Data Analysis
22% Loop through each plane:
23for i=1:3
24    index=1;
25    % Get lines from file
26    while(~feof(angleFileID(i)));
27        signalData=[];
28        line =fgetl(angleFileID(i));
29        % Look for lines starting with Angle:
30        while(~strncmp(line,'Angle:',6) && ~feof(angleFileID(i)))  %%Find word "angle" to indicate start of data
31            line =fgetl(angleFileID(i));  %%leaves while loop when it finds "angle" and processes subsequent lines.
32        end
33       
34        if(~feof(angleFileID(i)))
35            % Get the angle value from the line
36            startIndex=strfind(line ,'Angle:');
37                        %%First line of data after a declaration of angle
38            angleData(index,i)= sscanf(line(1,startIndex:end),'Angle: %f %*[^\n]');  %%angleData is extracted angle value
39            line=fgetl(angleFileID(i));
40            a=0;
41            while(~strcmp(line,'*') && ~feof(angleFileID(i)) );  %%look for * to identify end of data field
42                %default values to indicate missing TagID and BrdID
43                signalID=-1;
44                signalBrdID=-1;
45               
46                %Get signalID from the data line--should correspond to value of TagID entered at start.
47                startIndex=strfind(line ,'TagID:');
48                if size(startIndex,2)~=0,signalID=sscanf(line(startIndex(1,1):end),'TagID:%f %*[^\n]');end;
49                                %%extract TagID from field right after string "TagID:"
50               
51                %Get signalBrdID from data line--should correspond to value of BrdID entered at start
52                startIndex=strfind(line ,'Brd ID:');
53                if size(startIndex,2)~=0,signalBrdID=sscanf(line(startIndex(1,1):end),'Brd ID:%f %*[^\n]');end;
54               
55                %Get RSSI iff BrdID & tagID read from data matches entered BrdID
56                startIndex=strfind(line ,'RSSI:'); 
57                                %%startIndex is empty if no match, otherwise contains locations of all matches
58                                %%if zero size, no RSSI info on the line.
59                if (size(startIndex,2)~=0) && (signalID==TagID) && (signalBrdID == BrdID )
60                    signalData(a+1)=sscanf(line(startIndex(1,1):end),'RSSI:%f %*[^\n]');a=a+1;
61                end;
62               
63                line =fgetl(angleFileID(i));   %%Inside while loop--move to next line of data.
64               
65            end
66            %Set the radius to equal the average of the power as a function of angle for each angle
67            radius(index,i)=mean((10.^(signalData/10))*.001); 
68                        %%radius is the mean of all measurements at a specific angle for a specific plane
69                        %%if tester is moving, it averages over the multipath values at the same angle for a given plane.
70            index=index+1;
71        end
72    end
73fclose(angleFileID(i));   
74end
75
76avgPower=mean(radius);  %%Average over xy, xz, yz planes and return a vector.  avgPower is a 1x3 vector
77totalAvg=mean(avgPower);  %%Average over all three planes
78%%fprintf( 'Average Power in watts: ');
79%%disp(totalAvg);
80fprintf( 'Average Power in dBm: ');
81disp(10*log10(totalAvg*1000));
82
83%%Plot angle dependence of power in watts
84%%figure(1),polar(angleData(:,1)*pi/180,radius(:,1)),camroll(90),title('XY Plane'), legend('Radius in Watts');
85%%figure(2),polar(angleData(:,2)*pi/180,radius(:,2)),camroll(90),title('XZ Plane'),legend('Radius in Watts');
86%%figure(3),polar(angleData(:,3)*pi/180,radius(:,3)),camroll(90),title('YZ Plane'),legend('Radius in Watts');
87
88%%Plot angle dependence of power relative to average power
89dbrelPower=100+10*log10(radius*1000);  %%relative power in dB with an offset of 100dBm
90
91figure(1),polar(angleData(:,1)*pi/180,dbrelPower(:,1)),camroll(90),title('XY Plane'), legend('Radius in Watts');
92figure(2),polar(angleData(:,2)*pi/180,dbrelPower(:,2)),camroll(90),title('XZ Plane'),legend('Radius in Watts');
93figure(3),polar(angleData(:,3)*pi/180,dbrelPower(:,3)),camroll(90),title('YZ Plane'),legend('Radius in Watts');
94
95
96
97
98