Procházet zdrojové kódy

added sphear_bf_plot and sphear_af_power

Fernando Pablo Lopez-Lezcano před 10 roky
rodič
revize
cb66639fb0
2 změnil soubory, kde provedl 101 přidání a 0 odebrání
  1. 60 0
      sphear_af_power.m
  2. 41 0
      sphear_bf_plot.m

+ 60 - 0
sphear_af_power.m

@@ -0,0 +1,60 @@
+%%
+%% *SpHEAR Project
+%%
+%% sphear_af_power: return array of power for all capsules in a range of frequencies
+%%
+%% usage:
+%%   [R] = sphear_af_power(fmin, fmax, N, Npre)
+%%
+%% fmin, fmax: range of frequencies to consider
+%% Npre: number of samples before the main impulse
+%% N: total number of samples to analyze
+%%
+%% The names of reference microphone impulse response and capsule measurements are
+%% currently hardwired into this file, this needs to be fixed and turned into
+%% input parameters
+%%
+%% Copyright Fernando Lopez-Lezcano 2016
+%% 
+
+function [R] = sphear_af_power(measurements, fmin, fmax, N, Npre)
+  pkg load signal;
+
+  %% read in reference microphone, select samples to process
+  [ref, Fs] = wavread('../cal/2016.04.20/export/reference-001-1.wav');
+  [peaks, locs] = findpeaks(abs(ref));
+  [~, index] = max(peaks);
+  start = locs(index) - Npre;
+  range = start:(start + N - 1);
+  ref_fft = fft(ref(range), N);
+  
+  %% indexes in array for frequency bins
+  imin = round((N/2) * fmin / (Fs/2));
+  imax = round((N/2) * fmax / (Fs/2));
+
+  capnames = cellstr(['LF'; 'RF'; 'LB'; 'RB']);
+
+  printf("... processing [%d] ", size(measurements));
+  %% all submitted measurements
+  i = 1;
+  for m = measurements
+    printf("%d ", m);
+    %% all capsules
+    for c = 1:4
+
+      %% read in capsule measurement and equalize to reference microphone
+      %% this is only valid for the frequency range covered by the test speaker,
+      %% anything outside is undefined
+      %%
+      capsule = wavread(["../cal/2016.04.20/export/a-format-0" sprintf("%02.0f", m) "-" char(capnames(c)) ".wav"]);
+      equalized = fft(capsule(range), N) ./ ref_fft;
+      
+      %% return total power of signal in frequency range
+      R(i, c) = sqrt(sum(equalized(imin:imax).*conj(equalized(imin:imax)))/size(equalized(imin:imax),1));
+    end
+    i = i + 1;
+  end
+  printf(", done (%d)\n", size(R(:,:))(1));
+  
+end
+

+ 41 - 0
sphear_bf_plot.m

@@ -0,0 +1,41 @@
+%%
+%% *SpHEAR Project
+%%
+%% sphear_bf_plot: plot the polar response of a B format signal
+%%
+%% usage:
+%%   [BF] = sphear_bf_plot(BF, fmin, fmax)
+%%
+%% BF: B format signal array
+%% fmin, fmax: range of frequencies to consider (to title plot)
+%%
+%% Copyright Fernando Lopez-Lezcano 2016
+%% 
+
+function [BF] = sphear_bf_plot(BF, fmin, fmax, rmax)
+  pkg load signal;
+
+  %% to close the polar plots we repeat the first point
+  m = size(BF, 1);
+  BF(m + 1,:) = BF(1,:);
+  theta = (0:m)*(2*pi/m);
+  
+  %% plot it as a function of angle
+  bname = cellstr(['W'; 'X'; 'Y'; 'Z']);
+
+  f = figure;
+  for b = 1:4
+    subplot(2, 2, b);
+    hold on;
+    axis square;
+    axis([-rmax, rmax, -rmax, rmax]);
+    title([char(bname(b)) ": " sprintf("%05.0d", fmin) " to " sprintf("%05.0d", fmax) " Hz"]);
+
+    [xr, yr] = pol2cart(theta', ones(m + 1,1));
+    plot(xr, yr);
+    [x, y] = pol2cart(theta', abs(BF(:,b)));
+    plot(x, y, '.-r', 'LineWidth', 0.5);
+  end
+  print(f, '-dpng','-color',["figures/sphear_polar_multi_" sprintf("%05d", fmin) "_" sprintf("%05d", fmax) ".png"]);
+end
+