This repository was archived by the owner on Dec 29, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathreadRSSI.m
81 lines (64 loc) · 2.08 KB
/
readRSSI.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
function [rssi,utcDN,freqHz,raw] = readRSSI(fn,dataType,lc,doPlot)
% Michael Hirsch
%% user parameters
if nargin<2 || isempty(dataType), dataType = 'multifreq'; end
if nargin<3 || isempty(lc), lc='b'; end
if nargin<4 || isempty(doPlot), doPlot = true; end
%% open file
fid = fopen(fn,'r');
if fid<0, error(['Could not open file ',fn]), end
%% get headers
templ = '%s %s';
nHeaders = 5;
hdrs = textscan(fid,templ,nHeaders,...
'Delimiter',',','MultipleDelimsAsOne',true);
FreqInd = ~cellfun(@isempty,regexp(hdrs{1},'Frequency.*','once'));
FreqHz = str2num(hdrs{2}{FreqInd}); %#ok<ST2NM>
AzElInd = ~cellfun(@isempty,regexp(hdrs{1},'Azimuth/Elevation.*','once'));
AzElDeg = str2num(hdrs{2}{AzElInd}); %#ok<ST2NM>
AttInd = ~cellfun(@isempty,regexp(hdrs{1},'Attenuation.*','once'));
AttDB = str2double(hdrs{2}{AttInd});
ModeInd = ~cellfun(@isempty,regexp(hdrs{1},'Mode/Bandwidth.*','once'));
Mode = hdrs{2}{ModeInd}; Mode = Mode(1:3);
%% purge blank lines in an Octave-compatible way (headerlines not handled well)
if isoctave
junkLines = 3;
else %is matlab
junkLines = 4;
end
for i = 1:junkLines
tmp = fgetl(fid);
end
%% read data
templ = '%s%f%f';
raw = textscan(fid,templ,'Delimiter',' ','MultipleDelimsAsOne',true);
utcDN = datenum(raw{1},'yyyy-mm-ddTHH:MM:SS');
rssi = raw{3};
freqHz = raw{2};
fclose(fid);
%% plots
if doPlot
figure(1)
ax = gca;
switch lower(dataType)
case 'singlefreq'
line(utcDN,rssi)
set(ax,'ylim',[-54 54])
datetick
title({[num2str(FreqHz/1e6,'%0.3f'),'MHz: RSSI: ',datestr(utcDN(1),'yyyy-mmm-dd'),' to ',datestr(utcDN(end),'yyyy-mmm-dd')],...
['Az/El(Deg): ',num2str(AzElDeg,'%0.1f'),' Att.(dB): ',num2str(AttDB),' Mode: ',Mode]})
xlabel('Time (Local Boston)')
ylabel('RSSI (uncalibrated)')
grid on
case 'multifreq'
if nargin<3, lc = 'b'; end
line(freqHz/1e6,rssi,'Color',lc)
set(ax,'ylim',[-54 54],'xtick',435:0.25:438)
xlabel('Freq (MHz)')
ylabel('RSSI (uncalibrated)')
otherwise, warning(['plot type ',dataType,' unknown, unable to plot'])
end %switch
end % if doPlot
%%
if nargout==0, clear, end
end