%% %% *SpHEAR Project %% %% sphear_af_power: return array of power for all capsules in a range of frequencies %% %% usage: %% [R Fs] = 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 %% 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 . function [R Fs] = 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']); %% all submitted measurements i = 1; for m = measurements %% 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 end