%% %% *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