Skip to content

Commit 4c47511

Browse files
committed
new file exchange and dataProcessing code moved here
1 parent e071dfd commit 4c47511

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2289
-0
lines changed
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
% script modified by J. Haxel May 2015 to calculate the long-term time
2+
% averaged spectra of acoustic signals at NRS
3+
% system response = (preAmp + instResp) is removed and energy values are
4+
% normalized to dB re 1uPa @ 1m
5+
%
6+
% CF2 data - need to use *CF2*.m for all subroutines
7+
%
8+
% data info
9+
%c
10+
if (1)
11+
datadir = 'E:\sg639\wav\sg639-1kHz\';
12+
locname = 'GoMex';
13+
fnums = 1:49999;
14+
chan = 1;
15+
frameSize = 1000;
16+
fdates = 'E:\sg639\wav\sg639-1kHz\file_dates-sg639_GoMex_May18-1kHz.txt';
17+
sRate = 1000;
18+
elseif(0)
19+
20+
end
21+
%
22+
% Parameters for time averaging and start/stop times
23+
period = 1/86400; %5/1440 %1/24 %5/1440 %hourly =1/24 %600/(60*60*24); % 600 sec in days
24+
baseyear = 'auto'; % auto means get it from first day of data
25+
zeroPad = 0; % zero-pad the signal
26+
nOverlap = 0; % overlap data points
27+
%
28+
%%%%%%%%%%%%%%%%%%%%%%% Configure data Grab %%%%%%%%%%%%%%%%%%%%%%%%%%%%
29+
%
30+
hIndex = readHarufileDateIndex(fdates);
31+
if (0) %change for the old format of datafile
32+
fn0 = sprintf('%sdatafile.%03d', datadir, fnums(1));
33+
fn1 = sprintf('%sdatafile.%03d', datadir, fnums(end));
34+
elseif (0)
35+
fn0 = sprintf('%s%08d.DAT', datadir, fnums(1));
36+
fn1 = sprintf('%s%08d.DAT', datadir, fnums(end));
37+
else
38+
fn0 = [datadir hIndex.hname{1}(3:end)];
39+
fn1 = [datadir hIndex.hname{end}(3:end)];
40+
end
41+
% NOT NEEDED FOR WORKING WITH WAV FILES
42+
% [dtv0,yr,jd,hr,mn,sc,sRate,t,y]=readCF2hdr(fn0,0);
43+
% [dtv1,yr,jd,hr,mn,sc,sRate,t,y]=readCF2hdr(fn1,0);
44+
dtv0 = hIndex.time(1);
45+
dtv1 = hIndex.time(end);
46+
%
47+
if (ischar(baseyear) && strcmp(baseyear, 'auto'))
48+
% baseyear = sub(datevec(dtv0), 1); % new dt encoding from soundIn
49+
baseyear = sub(datevec(hIndex.time(1)), 1);
50+
end
51+
%
52+
% Get start and stop times that include only whole intervals.
53+
dt0 = ceil(dtv0/period) * period; % get start of first whole period
54+
dt1 = floor(dtv1/period) * period; % get end of last whole period
55+
%
56+
% get the system response to subtract out of power vaues later
57+
%[SR] = get_sys_response(PA_rev,gain,filt_sw,sRate,frameSize);
58+
%[SR] = get_sys_response(9,0,4,double(sRate),frameSize);
59+
60+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
61+
% %%%%%%%%%%%%%%%%% Start the loop for calculating LTSpect %%%%%%%%%%%%%%
62+
%
63+
if (1)
64+
gram = zeros((frameSize+zeroPad)/2, round((dt1-dt0)/period));
65+
fRate = sRate / (frameSize - nOverlap);
66+
printf('%d dots:', nCols(gram))
67+
for i = 1 : nCols(gram)
68+
fprintf(1,'.%s', iff(mod(i,60) == 0, char(10), ''));
69+
dt = dt0 + (i-1) * period;
70+
% Do around 1 million samples at a time.
71+
t0 = dt;
72+
gSum = zeros((frameSize+zeroPad)/2, 1);
73+
ng = 0;
74+
% while (t0 < dt + period)
75+
%t1 = min([dt+period double(t0+1e6/sRate/24/60/60)]); %for big AVG's
76+
t1 = dt + period;
77+
%xt = haruSoundAtTime_CF2_2channel([t0 t1], hIndex, datadir, chan);
78+
% xt = haruSoundAtTime_CF2([t0 t1], hIndex, datadir); %note - calling CF2 specific routine
79+
xt = haruSoundAtTime([t0 t1], hIndex, datadir);
80+
81+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
82+
%xt_2 = xt{1}; %xt_3 = xt_2(:,1); %extra step do to 2 channel data
83+
%x_mn = xt_3 - mean(xt_3); %have to do this in 2 steps now because 2 channel data
84+
x_mn = xt{1} - mean(xt{1}); %remove the sample mean from the chunk of data for 16bit
85+
x = (2.5/(2^16)).*x_mn; % convert to Volts by (Voltrange/bitrange)- for 16bit
86+
%x = (4/(2^12)).*x_mn; %convert to Volts -12bit
87+
g = joespect_LTacoustic(x, frameSize, nOverlap, zeroPad, 'hann', sRate); %5000 for sample rate
88+
89+
% [g,f,t] = spectrogram(x,hann(frameSize),nOverlap,frameSize,sRate);
90+
% g = abs(g(2:end));
91+
% last input on line above is sample rate
92+
if (nCols(g) == 0), break; end % skip partial frame at end of day
93+
gSum = gSum + mean(g,2); % sum up the energy - will divide later
94+
ng = ng + nCols(g);
95+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96+
%t0 = t0 + nCols(g)/.9765624 / 24/60/60; %have to change this to make it run m10 hickup -
97+
t0 = t0 + nCols(g) / fRate / 24/60/60; %change back to this
98+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
99+
% end
100+
grm = 10*log10(gSum); %to convert power to dB
101+
%
102+
%GRAM = grm - SR';
103+
%
104+
%gram(:,i) = GRAM; %must add this in to get system response removed
105+
gram(:,i) = grm;
106+
%
107+
%
108+
end
109+
fprintf(1, '\n');
110+
end
111+
% remove the system gain from the spectra
112+
%LTgram = gram - repmat(SR',1,length(gram(1,:)));
113+
%
114+
%cd E:\ROSS_SEA-2014
115+
%cd C:\haxel\OCEAN_NOISE\YAQ_HEAD\
116+
%cd C:\haxel\LAU_BASIN\ANALYSIS\MATAS
117+
%%
118+
cd C:\Users\haver\Documents\NRS\NRS10\LTSA
119+
120+
save NRS10_20162017_5minAvgSpect_cal070118 gram dt0 dt1 frameSize sRate
121+
122+
%
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
% script modified by J. Haxel May 2015 to calculate the long-term time
2+
% averaged spectra of acoustic signals at NRS
3+
% system response = (preAmp + instResp) is removed and energy values are
4+
% normalized to dB re 1uPa @ 1m
5+
%
6+
% CF2 data - need to use *CF2*.m for all subroutines
7+
%
8+
% data info
9+
%c
10+
if (1)
11+
datadir = 'E:\sg639\wav\sg639-1kHz\';
12+
locname = 'GoMex';
13+
fnums = 1:49999;
14+
chan = 1;
15+
frameSize = 1000;
16+
fdates = 'E:\sg639\wav\sg639-1kHz\file_dates-sg639_GoMex_May18-1kHz.txt';
17+
sRate = 1000;
18+
elseif(0)
19+
20+
end
21+
%
22+
% Parameters for time averaging and start/stop times
23+
period = 1/86400; %5/1440 %1/24 %5/1440 %hourly =1/24 %600/(60*60*24); % 600 sec in days
24+
baseyear = 'auto'; % auto means get it from first day of data
25+
zeroPad = 0; % zero-pad the signal
26+
nOverlap = 0; % overlap data points
27+
%
28+
%%%%%%%%%%%%%%%%%%%%%%% Configure data Grab %%%%%%%%%%%%%%%%%%%%%%%%%%%%
29+
%
30+
hIndex = readHarufileDateIndex(fdates);
31+
if (0) %change for the old format of datafile
32+
fn0 = sprintf('%sdatafile.%03d', datadir, fnums(1));
33+
fn1 = sprintf('%sdatafile.%03d', datadir, fnums(end));
34+
elseif (0)
35+
fn0 = sprintf('%s%08d.DAT', datadir, fnums(1));
36+
fn1 = sprintf('%s%08d.DAT', datadir, fnums(end));
37+
else
38+
fn0 = [datadir hIndex.hname{1}(3:end)];
39+
fn1 = [datadir hIndex.hname{end}(3:end)];
40+
end
41+
% NOT NEEDED FOR WORKING WITH WAV FILES
42+
% [dtv0,yr,jd,hr,mn,sc,sRate,t,y]=readCF2hdr(fn0,0);
43+
% [dtv1,yr,jd,hr,mn,sc,sRate,t,y]=readCF2hdr(fn1,0);
44+
dtv0 = hIndex.time(1);
45+
dtv1 = hIndex.time(end);
46+
%
47+
if (ischar(baseyear) && strcmp(baseyear, 'auto'))
48+
% baseyear = sub(datevec(dtv0), 1); % new dt encoding from soundIn
49+
baseyear = sub(datevec(hIndex.time(1)), 1);
50+
end
51+
%
52+
% Get start and stop times that include only whole intervals.
53+
dt0 = ceil(dtv0/period) * period; % get start of first whole period
54+
dt1 = floor(dtv1/period) * period; % get end of last whole period
55+
%
56+
% get the system response to subtract out of power vaues later
57+
%[SR] = get_sys_response(PA_rev,gain,filt_sw,sRate,frameSize);
58+
%[SR] = get_sys_response(9,0,4,double(sRate),frameSize);
59+
60+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
61+
% %%%%%%%%%%%%%%%%% Start the loop for calculating LTSpect %%%%%%%%%%%%%%
62+
%
63+
if (1)
64+
gram = zeros((frameSize+zeroPad)/2, round((dt1-dt0)/period));
65+
fRate = sRate / (frameSize - nOverlap);
66+
printf('%d bins:\n', nCols(gram))
67+
for i = 1 : nCols(gram)
68+
fprintf(1,'.%s', iff(mod(i,60) == 0, char(10), ''));
69+
dt = dt0 + (i-1) * period;
70+
% Do around 1 million samples at a time.
71+
t0 = dt;
72+
gSum = zeros((frameSize+zeroPad)/2, 1);
73+
ng = 0;
74+
% while (t0 < dt + period)
75+
%t1 = min([dt+period double(t0+1e6/sRate/24/60/60)]); %for big AVG's
76+
t1 = dt + period;
77+
%xt = haruSoundAtTime_CF2_2channel([t0 t1], hIndex, datadir, chan);
78+
% xt = haruSoundAtTime_CF2([t0 t1], hIndex, datadir); %note - calling CF2 specific routine
79+
xt = haruSoundAtTime_sf([t0 t1], hIndex, datadir);
80+
81+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
82+
%xt_2 = xt{1}; %xt_3 = xt_2(:,1); %extra step do to 2 channel data
83+
%x_mn = xt_3 - mean(xt_3); %have to do this in 2 steps now because 2 channel data
84+
x_mn = xt{1} - mean(xt{1}); %remove the sample mean from the chunk of data for 16bit
85+
x = (2.5/(2^16)).*x_mn; % convert to Volts by (Voltrange/bitrange)- for 16bit
86+
%x = (4/(2^12)).*x_mn; %convert to Volts -12bit
87+
g = joespect_LTacoustic(x, frameSize, nOverlap, zeroPad, 'hann', sRate); %5000 for sample rate
88+
89+
% [g,f,t] = spectrogram(x,hann(frameSize),nOverlap,frameSize,sRate);
90+
% g = abs(g(2:end));
91+
% last input on line above is sample rate
92+
if (nCols(g) == 0), break; end % skip partial frame at end of day
93+
gSum = gSum + mean(g,2); % sum up the energy - will divide later
94+
ng = ng + nCols(g);
95+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96+
%t0 = t0 + nCols(g)/.9765624 / 24/60/60; %have to change this to make it run m10 hickup -
97+
t0 = t0 + nCols(g) / fRate / 24/60/60; %change back to this
98+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
99+
% end
100+
grm = 10*log10(gSum); %to convert power to dB
101+
%
102+
%GRAM = grm - SR';
103+
%
104+
%gram(:,i) = GRAM; %must add this in to get system response removed
105+
gram(:,i) = grm;
106+
%
107+
%
108+
end
109+
fprintf(1, '\n');
110+
end
111+
% remove the system gain from the spectra
112+
%LTgram = gram - repmat(SR',1,length(gram(1,:)));
113+
114+
%%
115+
save([datadir 'sg639_GoMex_May18-1kHz-LTSA_1Hz1s.mat'],'gram','dt0','dt1','frameSize','sRate');
116+
117+
%

0 commit comments

Comments
 (0)