| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- %%
- %% *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_fons(fmin, fmax, N, Fs, plotz)
- pkg load signal;
- %% indexes in array for frequency bins
- imin = round((N/2) * fmin / (Fs/2));
- imax = round((N/2) * fmax / (Fs/2));
- r_start = 0;
- r_end = 0;
-
- %% all measurements
- for m = 1:16
- %% all b format components, 4 channel soundfile
- bsignal = wavread(["../cal/2016.08.03/fons/b-format-rendered-" sprintf("%03.0f", m) "-16.wav"]);
- %% transform from FUMA to SN3D (the encoder is outputing FUMA)
- %% bsignal(:,1) = bsignal(:,1) * (sqrt(2)/2);
-
- %% find first peak, read samples around it
- Npre = 64;
- Nbuf = 256;
- [index, value] = findmaxpeak(bsignal(:,1));
- r_start = index - Npre;
- r_end = r_start + Nbuf -1;
- range = r_start:r_end;
- printf("%d: samples = %d -> %d (%d), imin:imax %d:%d\n", m, r_start, r_end, r_end-r_start, imin, imax);
- bfft = fft(bsignal(range,:), N);
- if (plotz == 0)
- %% calculate a forward facing cardiod
- cfft = fft(bsignal(range,1) + 1.0 * bsignal(range,2), N);
- end
- %% return total power of signal in frequency range
- scaler = 8;
- B(m, :) = sqrt(sum(bfft(imin:imax,:).*conj(bfft(imin:imax,:)))/size(bfft(imin:imax,:),1)) / scaler;
- %% make a cardiod if we don't want Z
- if (plotz == 0)
- B(m, 4) = sqrt(sum(cfft(imin:imax).*conj(cfft(imin:imax)))/size(cfft(imin:imax),1)) / (2 * scaler);
- end
- end
-
- end
|