ソースを参照

start collecting shared functions in sphear_common

Fernando Pablo Lopez-Lezcano 10 年 前
親
コミット
448e6ffcef
1 ファイル変更、57 行追加、0 行削除
  1. 57 0
      sphear_common.m

+ 57 - 0
sphear_common.m

@@ -0,0 +1,57 @@
+%%
+%% *SpHEAR Project
+%%
+%% sphear_common: library of shared functions
+%%
+%% Copyright 2016, Fernando Lopez-Lezcano, All Rights Reserved
+%% nando@ccrma.stanford.edu
+%%
+%%  This program is free software: you can redistribute it and/or modify
+%%  it under the terms of the GNU General Public License as published by
+%%  the Free Software Foundation, either version 3 of the License, or
+%%  (at your option) any later version.
+%%
+%%  This program is distributed in the hope that it will be useful,
+%%  but WITHOUT ANY WARRANTY; without even the implied warranty of
+%%  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+%%  GNU General Public License for more details.
+%%
+%%  You should have received a copy of the GNU General Public License
+%%  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+%% make sure octave treats this as a script file
+1;
+
+%% Render a capsule impulse response through the FIR filter A2B matrix
+%%
+%% m: number of measurement to render
+%% FIR: matrix of A2B FIR filters
+%% range: range of samples to process in file
+%% Nfft: size of FFT to use
+
+function [bf] = sphear_a_to_b(m, FIR, range, Nfft);
+  capnames = cellstr(['LF'; 'RF'; 'LB'; 'RB']);
+  %% read in capsule signals and apply FIR filter
+  for c = 1:4
+    cs(c,:) = wavread(["../cal/2016.04.20/export/a-format-0" sprintf("%02.0f", m) "-" char(capnames(c)) ".wav"]);
+    cr(c,:) = tukeywin(size(range)(2), 0.0) .* cs(c,:)'(range);
+    for b = 1:4
+      bs(c,b,:) = fftfilt(reshape(FIR(b,c,:), 1, [])', cr(c,:), Nfft);
+    end
+  end
+  %% add filtered capsule output to b format components
+  for b = 1:4
+    bf(b,:) = bs(1,b,:) + bs(2,b,:) + bs(3,b,:) + bs(4,b,:);
+  end
+end
+
+%% Find maximum and location of maximum in a signal
+%%
+%% signal: vector with time domain signal
+
+function [i, v] = findmaxpeak(signal);
+  [peaks, locs] = findpeaks(signal, "DoubleSided");
+  [~, index] = max(peaks);
+  i = locs(index);
+  v = peaks(index);
+end