endfunction
-function [AmdB_ residual] = piecewise_model(AmdB, Wo)
+function [AmdB_ residual fvec fvec_] = piecewise_model(AmdB, Wo, vq, vq_m)
L = length(AmdB);
l1000 = floor(L/4);
AmdB_ = ones(1,L);
fmin = 0.150;
lmin = floor(L*fmin/4);
[mx mx_ind] = max(AmdB(lmin+1:l1000));
+ amp(1) = mx;
mx_ind += lmin;
AmdB_ = parabolic_resonator(mx_ind*Wo*4/pi, mask_sample_freqs_kHz) + mx;
fr1 = mx_ind*Wo*4/pi;
fmin = 1;
- lmin = round(L*fmin/4);
+ lmin = round(fmin*L/4);
[mx mx_ind] = max(AmdB(lmin+1:L));
+ amp(2) = mx;
mx_ind += lmin;
AmdB_ = max(AmdB_, parabolic_resonator(mx_ind*Wo*4/pi, mask_sample_freqs_kHz) + mx);
fr2 = mx_ind*Wo*4/pi;
% fit a third resonator, must be +/- 300 Hz after 2nd resonator
residual = AmdB;
- residual(1:lmin) = 0;
+ residual(1:lmin) = -40;
fr2 = mx_ind*Wo*4/pi;
fmin = fr2 - 0.300;
lmin = max(1, round(L*fmin/4));
lmax = min(L, round(L*fmax/4));
- residual(lmin:lmax) = 0;
+ residual(lmin:lmax) = -40;
[mx mx_ind] = max(residual);
+ amp(3) = mx;
AmdB_ = max(AmdB_, parabolic_resonator(mx_ind*Wo*4/pi, mask_sample_freqs_kHz) + mx);
fr3 = mx_ind*Wo*4/pi;
+ % 4th resonator
+
+ fmin = fr3 - 0.300;
+ fmax = fr3 + 0.300;
+
+ lmin = max(1, round(L*fmin/4));
+ lmax = min(L, round(L*fmax/4));
+ residual(lmin:lmax) = 0;
+ [mx mx_ind] = max(residual);
+ amp(4) = mx;
+ AmdB_ = max(AmdB_, parabolic_resonator(mx_ind*Wo*4/pi, mask_sample_freqs_kHz) + mx);
+ fr4 = mx_ind*Wo*4/pi;
+
%figure(3);
%plot(mask_sample_freqs_kHz, residual);
- printf("\nfr1: %f fr2: %f fr3: %f\n", fr1, fr2, fr3);
+ %printf("\nfr1: %f fr2: %f fr3: %f fr4: %f\n", fr1, fr2, fr3, fr4);
+ [fvec fvec_ind] = sort([fr1 fr2 fr3 fr4]);
+
+ % optional VQ of freqeuncies
+
+ if nargin == 4
+ AmdB_ = ones(1,L);
+ [mes fvec_ ind] = mbest(vq, fvec, vq_m);
+ for i=1:4
+ an_amp = amp(fvec_ind(i));
+ AmdB_ = max(AmdB_, parabolic_resonator(fvec_(i), mask_sample_freqs_kHz) + an_amp);
+ end
+ end
+
endfunction
% Or with a little more processing:
% codec2-dev/build_linux/src$ ./c2sim ../../raw/hts2a.raw --amread hts2a_am.out --awread hts2a_aw.out --phase0 --postfilter --Woread hts2a_Wo.out -o - | play -q -t raw -r 8000 -s -2 -
-
% process a whole file and write results
-function newamp1_batch(samname, optional_Am_out_name, optional_Aw_out_name)
+function fvec_log = newamp1_batch(samname, optional_Am_out_name, optional_Aw_out_name)
newamp;
more off;
max_amp = 80;
+ load vq;
model_name = strcat(samname,"_model.txt");
model = load(model_name);
% encoder loop ------------------------------------------------------
+ fvec_log = [];
+
for f=1:frames
printf("%d ", f);
AmdB_(mx_ind) += 6;
#}
- AmdB_ = piecewise_model(AmdB, Wo);
+ [AmdB_ res fvec] = piecewise_model(AmdB, Wo, vq, 2);
+ fvec_log = [fvec_log; fvec];
#{
l1000 = floor(L/4);
AmdB_ = AmdB;
function newamp1_fbf(samname, f=10)
newamp;
more off;
- plot_spectrum = 1;
- mask_en = 1;
+ quant_en = 0;
+
+ load vq;
% load up text files dumped from c2sim ---------------------------------------
AmdB_(mx_ind) += 6;
#}
- [AmdB_ residual] = piecewise_model(AmdB, Wo);
+ if quant_en
+ [AmdB_ residual fvec fvec_] = piecewise_model(AmdB, Wo, vq, 2);
+ else
+ [AmdB_ residual fvec] = piecewise_model(AmdB, Wo);
+ end
figure(2);
clf;
hold on;
plot((1:L)*Wo*4000/pi, AmdB,";Am;r+-");
plot(Am_freqs_kHz*1000, AmdB_, ';model;c');
- plot(Am_freqs_kHz*1000, residual, ';model;g');
+ plot(fvec*1000, 60*ones(1,4), ';fvec;go');
+ if quant_en
+ plot(fvec_*1000, 60*ones(1,4), ';fvec q;ro');
+ end
hold off;
% interactive menu ------------------------------------------
- printf("\rframe: %d menu: n-next b-back q-quit m-mask_en", f);
+ printf("\rframe: %d menu: n-next b-back q-quit m-quant_en", f);
fflush(stdout);
k = kbhit();
if (k == 'm')
- if mask_en
- mask_en = 0;
+ if quant_en
+ quant_en = 0;
else
- mask_en = 1;
+ quant_en = 1;
end
endif
if (k == 'n')