1
0
Эх сурвалжийг харах

change calibration procedure for 8 capsule microphone to new one

Fernando Pablo Lopez-Lezcano 7 жил өмнө
parent
commit
85edacc68b

+ 24 - 24
calibration/src/sphear_octa_af_calibrate.m

@@ -40,37 +40,37 @@ function [] = sphear_octa_af_calibrate(measurements, keep, fade, suffix);
   %% read the convolution kernel
   [ref, Fs] = wavread('../data/current/cal/drc-filter.wav');
 
-  %% window the DRC generated filter, eliminate the stuff before the main
-  %% peak and limit the length to the approximate useful length of the
-  %% original recorded impulse response
-  
-  [peaks, locs] = findpeaks(abs(ref));
-  [value, index] = max(peaks);
-  loc = locs(index);
-  
-  %% truncate before the main peak
-  b_len = 4;
-  before = tukeywin(2 * b_len, 0.9)(1:end/2) .* ref(loc-2*b_len:loc-b_len-1);
-  %% useful samples
-  samples = keep * Fs/2;
-  during = ref(loc-b_len:loc+samples-1);
-  %% fade out after useful samples
-  a_len = fade * Fs/2;
-  after = tukeywin(2 * a_len, 0.9)(end/2:end) .* ref(loc+samples:loc+samples+a_len);
-  %% and the whole thing is:
-  trunc = cat(1, before, during, after);
-
-  capnames = cellstr(['LF'; 'RF'; 'LB'; 'RB']);
   octanames = cellstr(['1'; '2'; '3'; '4'; '5'; '6'; '7'; '8']);
+  loc_min = intmax;
+  loc_max = 0;
   %% all requested measurements
   for m = measurements
     printf("processing measurement %d\n", m);
     %% read in capsule signals and normalize them
     for c = 1:8
       sig = wavread(["../data/current/af/a-format-" sprintf("%s%03d", suffix, m) "-" char(octanames(c)) ".wav"]);
-      cal_sig(:,c) = conv(trunc, sig);
-      wavwrite(cal_sig(:,c), Fs, ["../data/current/af/a-format-cal-" sprintf("%s%03d", suffix, m) "-" char(octanames(c)) ".wav"]);
+      cal_sig(m,c,:) = conv(ref, sig);
+      %% find first non-zero sample of convolved signal
+      head = find(cal_sig(m,c,:)!=0, 1, 'first');
+      if (head < loc_min)
+	loc_min = head;
+      end
+      if (head > loc_max)
+	loc_max = head;
+      end
+    end
+  end
+  %% now write all the calibrated impulse responses
+  %% choose a arbitrary multiple of input size... sigh
+  out_size = 4 * size(sig, 1);
+  range = loc_min - 1:loc_min - 1 + out_size;
+  %% 5% end window
+  wend = tukeywin(2 * out_size, 0.9)(end/2:end)';
+  printf("start sample: min = %f, max = %f, output size = %f\n", loc_min, loc_max, out_size);
+  for m = measurements
+    for c = 1:8
+      wavwrite(cal_sig(m,c,:)(range) .* wend, Fs, ["../data/current/af/a-format-cal-" sprintf("%s%03d", suffix, m) "-" char(octanames(c)) ".wav"]);
     end
-    wavwrite(cal_sig, Fs, ["../data/current/af/a-format-cal-" sprintf("%s%03d", suffix, m) ".wav"]);
+    %% wavwrite(cal_sig, Fs, ["../data/current/af/a-format-cal-" sprintf("%s%03d", suffix, m) ".wav"]);
   end
 end