فهرست منبع

added sphear_bf_power and sphear_a2b_fir_all

Fernando Pablo Lopez-Lezcano 10 سال پیش
والد
کامیت
edf296ed62
2فایلهای تغییر یافته به همراه105 افزوده شده و 0 حذف شده
  1. 60 0
      sphear_a2b_fir_all.m
  2. 45 0
      sphear_bf_power.m

+ 60 - 0
sphear_a2b_fir_all.m

@@ -0,0 +1,60 @@
+%%
+%% *SpHEAR Project
+%%
+%% sphear_a2b_all: calculate A2B matrixes for frequency ranges
+%%
+%% usage:
+%%   [F FE A2BF] = sphear_a2b_all(m, fmin, fmax, Noct, Fs, Nsamp, Npre, plt)
+%%
+%% m: vector of measurement numbers to take into account
+%% fmin, fmax: lower and upper frequency limits
+%% Noct: width of frequency ranges in fractions of an octave, this
+%%       will be changed slightly so that the frequency range is
+%%       covered by equally spaced frequency bands
+%% Fs: sampling rate
+%% Nsamp: time domain samples to use
+%% Npre: samples to use before the main impulse peak
+%%
+%% 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/>.
+
+function [B] = sphear_a2b_fir_all(fmin, fmax, Noct, Nfft, Fs, plt)
+
+  %% calculate number of frequency bands spaced Noct
+  n = floor(log(fmax/fmin)/log(2^(1/Noct)));
+  %% adjust width of band so they fit exactly in frequency range
+  N = log(2)/(log(fmax/fmin)/n);
+  printf("%d frequency bands, %f bands per octave\n", n, N);
+
+  %% first center frequency
+  fcmin = fmin * 2^(1/(N * 2));
+  %% all center and edge frequencies
+  fc = fcmin * 2.^((0:n - 1)/N)';
+  fe = fmin * 2.^((0:n)/N)';
+
+  %% normalize amplitude with respect to W between 600 and 1200 Hz
+  ref = sphear_bf_power(600, 1200, Nfft, Fs);
+  norm = mean(ref(:,1));
+
+  for i = (1:size(fc))
+    B(:,:,i) = sphear_bf_power(fe(i), fe(i + 1), Nfft, Fs) / norm;
+    if (plt == 1)
+      sphear_bf_plot(B(:,:,i), fe(i), fe(i + 1), 1.5);
+    end
+  end
+
+end
+

+ 45 - 0
sphear_bf_power.m

@@ -0,0 +1,45 @@
+%%
+%% *SpHEAR Project
+%%
+%% sphear_a_power: return array of power for all capsules in a range of frequencies
+%%
+%% usage:
+%%   [R] = sphear_a_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 [B] = sphear_bf_power(fmin, fmax, N, Fs)
+  pkg load signal;
+
+  %% R = zeros(16, 4);
+
+  %% indexes in array for frequency bins
+  imin = round((N/2) * fmin / (Fs/2));
+  imax = round((N/2) * fmax / (Fs/2));
+
+  bnames = cellstr(['w'; 'x'; 'y'; 'z']);
+
+  %% all measurements
+  for m = 1:16
+    %% all b format components
+    for b = 1:4
+
+      bsignal = wavread(["../cal/2016.04.20/export/b-format-" char(bnames(b)) "-" sprintf("%02.0f", m) ".wav"]);
+      bfft = fft(bsignal, N);
+      
+      %% return total power of signal in frequency range
+      B(m, b) = sqrt(sum(bfft(imin:imax).*conj(bfft(imin:imax)))/size(bfft(imin:imax),1));
+    end
+  end
+  
+end
+