forked from MarineBioAcousticsRC/Triton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
retrieveTransferFunction.m
96 lines (81 loc) · 2.53 KB
/
retrieveTransferFunction.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
function [xfr_f, id] = retrieveTransferFunction(DataFile, bin_kHz)
% function [xfr_f, id] = retrieveTransferFunction(DataFile, bin_kHz)
%
% Retrieve the appropriate transfer function for the site and deployment
% the file was recorded at. Assumes proper file naming
%
% Input:
% DataFile - File name
% {project name}{deployment ID}{site}_YYmmDD_HHMMSS.x.wav
% bin_kHz - frequencies we are concerned with
%
% Output:
% xfr_f - PreAmp / Transfer function
% id - Name/Id of PreAmp, for reference
xfr_f=[];
[pathdir, fileName, ext] = fileparts(DataFile);
undscr = strfind(fileName, '_');
fileInfo = fileName(1:undscr(1)-1);
id = 'Not Found';
% Parse through the file name to get the project, deployment and site
% information
% old file naming convention
m = regexp(fileName, ...
'(?<project>[A-Z]+[^0-9])(?<deployment>[0-9]+)(?<site>[^_]*)?_.*', ...
'names');
% new file naming convention - first used 7/2015;
% standardized 2/2016
if size(m) == 0
m = regexp(fileName, ...
'(?<project>^[A-Za-z]+)_(?<site>[A-Z]+[0-9]*)_(?<deployment>[0-9]+)', ...
'names');
end
pjct = m.project;
dpID = m.deployment;
ste = m.site;
% Fix known problems with encodings of project names in files
switch pjct
case 'SCAL'
pjct = 'SOCAL';
case 'PALMRA'
pjct = 'PAL';
ste = 'WT'; % Site not encoded properly
end
if strcmp(ste, 'SN') == 1
ste = 'N';
end
1;
% Get deployment from bandolero.ucsd.edu on port 9779
server = 'bandolero.ucsd.edu';
port_num = 9779;
q = dbInit('Server', server, 'Port', port_num);
dply = dbDeploymentInfo(q, 'Project', pjct, 'Site', ste, 'DeploymentID', dpID);
if isempty(dply)
return;
end
id = num2str(dply.Sensors.Audio.PreampID);
% Remove the "H" in front
% !! TEMPORARY !! Remove this when the database is fixed.
if id(1) == 'H'
id = id(2:end);
end
% !! TEMPORARY !!
previous_id = id;
switch id
case '306'
id = '309'; % No tf available, use something close
case '*'
id = '320'; % Unknown
end
if ~strcmp(id, previous_id)
fprintf('Project %s Site %s Deployment %s - Override TF %s --> %s\n', ...
pjct, ste, dpID, previous_id, id);
end
transf = dbGetTransferFn(q, id);
if isempty(transf)
return;
end
bin_Hz = bin_kHz * 1000;
xfr_f = interp1(transf(:,1), transf(:,2), bin_Hz, 'linear', 'extrap');
% figure; semilogx(tf(:,1),tf(:,2)); xlabel('Hz'); ylabel('dB');
end