2012/Projects/OwlPlatform/TransmitterTester: poweravg.m

File poweravg.m, 2.8 KB (added by silasw, 5 years ago)

MATLAB script for roughly determining the avg. received power for all directions.

Line 
1clear;
2clc;
3TagID=9;
4
5angleFileID(3)=zeros(size(3,1));
6signalFileID(3)=zeros(size(3,1));
7
8%% first file
9angleFileID(1)= fopen(strcat('dataFileXY.txt'));
10if angleFileID(1)==-1, error('Cannot Open File'),end;
11signalFileID(1)= fopen('logfileXY');
12if signalFileID(1)==-1, error('Cannot Open File'),end;
13
14
15%% Second file
16angleFileID(2)= fopen(strcat('dataFileXZ.txt'));
17if angleFileID(2)==-1, error('Cannot Open File'),end;
18signalFileID(2)= fopen('logfileXZ');
19if signalFileID(2)==-1, error('Cannot Open File'),end;
20%% Third file
21angleFileID(3)= fopen(strcat('dataFileYZ.txt'));
22if angleFileID(3)==-1, error('Cannot Open File'),end;
23signalFileID(3)= fopen('logfileYZ');
24if signalFileID(3)==-1, error('Cannot Open File'),end;
25
26% Pre-allocate array,assumes all file have the same number of angles
27% angle()=fscanf(angleFileID(1),'%*s %*f %*s %f %*s %*f');
28% radius = zeros(size(angleData{1,1}),3);
29% angle=zeros(size(angleData{1,1}),3);
30
31%% Data Collection
32i=1;
33while(i<=3)
34    angleTS(:,i)=fscanf(angleFileID(i),'%*s %*f %*s %f %*s %*f');
35    frewind(angleFileID(i));
36    angleData(:,i)=fscanf(angleFileID(i),'%*s %*f %*s %*f %*s %f');
37    fclose(angleFileID(i));
38    line=fgetl(signalFileID(i));
39    signalTS=[];
40    signalID=[];
41    signalData=[];
42    a=0;
43    while(~feof(signalFileID(i)));
44        line=fgetl(signalFileID(i));
45        if(strncmp(line,'Current Time (seconds)',22));
46            signalTS(a+1)=sscanf(line,'Current Time (seconds): %f TS:%*f Dropped:%*f Brd ID:%*f TagID:%*f RSSI:%*f %*[^\n]');
47            signalID(a+1)=sscanf(line,'Current Time (seconds): %*f TS:%*f Dropped:%*f Brd ID:%*f TagID:%f RSSI:%*f %*[^\n]');
48            signalData(a+1)=sscanf(line,'Current Time (seconds): %*f TS:%*f Dropped:%*f Brd ID:%*f TagID:%*f RSSI:%f %*[^\n]');
49            a=a+1;
50        end
51
52    end
53   
54    fclose(signalFileID(i));
55    index=1;
56     len=size(signalData,1);
57     while(index~=len)
58         if(signalData(index)~=TagID)
59             signalID(index)=[];
60             signalData(index)=[];
61             signalTS(index)=[];
62             len=len-1;
63         else
64             index=index+1;
65         end
66     end
67 
68     startIndex=2;
69     for index=1:size(angleData,1)
70         while signalTS(startIndex) < angleTS(index,i)
71             if(startIndex~=size(signalData))
72             startIndex=startIndex+1;
73             else
74             error('Time Stamps Do Not Match');
75             end
76         end
77         signalData(startIndex-1);
78         radius(index,i)=signalData(startIndex-1);
79     end
80
81     %[angleData(:,i),index]=sort(angleData(:,i));
82     %radius=radius(index,i);
83     radius(:,i);
84    i=i+1;
85   
86end
87radius;
88milliwatts = 10.^(radius/10);
89axisavgs_mW = mean(milliwatts)
90totalavg = mean(axisavgs_mW)