function [decmaskdB masker_freqs_kHz min_error mse_log1 mse_log2] = make_decmask_abys(maskdB, AmdB, Wo, L, mask_sample_freqs_kHz, freq_quant, amp_quant)
- Nsamples = 4;
+ Nsamples = 3;
% search range
% then quantise differences
- for i=2:4
+ % create table of freq quantiser levels with log spacing
+ %m = (log10(2)-log10(0.2))/(8-1); c = log10(0.2)-m;
+ %logf_steps = 10.^(m*(1:8)+c)
+ logf_steps = [0.4 0.7 1 1 1.3 1.6 2 2.4];
+
+ for i=2:Nsamples
targ = masker_freqs_kHz(i) - masker_freqs_kHz(i-1);
- [q_freq abits] = quantise(0.2:0.2:1.6, targ);
+ [q_freq abits] = quantise(logf_steps, targ);
bits = [bits abits];
masker_freqs_kHz(i) = masker_freqs_kHz(i-1) + q_freq;
end
% Fit straight line
f = masker_freqs_kHz*1000;
- [gradient intercept] = linreg(f, masker_amps_dB, 4);
+ [gradient intercept] = linreg(f, masker_amps_dB, Nsamples);
% use quantised gradient to take into account quantisation
% errors in rest of quantisation
gradient_ = quantise(-0.04:0.005:0.04, gradient);
%gradient_ = gradient;
- printf("gradient; %f gradient_: %f\n", gradient, gradient_);
+ %printf("gradient; %f gradient_: %f\n", gradient, gradient_);
% determine deltas, or errors in straight line fit
clf;
plot(f, masker_amps_dB, 'r+', 'markersize', 10, 'linewidth', 2)
- fplt = 0:100:3900
+ fplt = 0:100:3900;
hold on;
plot(fplt, fplt*gradient + intercept, 'b')
- fplt*gradient + intercept
% plot lines for deltas
y2 = masker_amps_dB(i);
plot([f(i) f(i)], [y1 y2], 'markersize', 10, 'linewidth', 2)
end
+ axis([0 4000 0 80])
hold off;
- end
- % quantise the deltas
+ end
- masker_amps_dB_lin_delta_ = zeros(4,1);
+ masker_amps_dB_lin_delta_ = zeros(Nsamples,1);
if amp_quant == 1
- for i=1:4
+ for i=1:Nsamples
masker_amps_dB_lin_delta_(i) = quantise(-21:3:21, masker_amps_dB_lin_delta(i));
- printf("dlin: %f dlin_: %f\n", masker_amps_dB_lin_delta(i), masker_amps_dB_lin_delta_(i));
+ %printf("dlin: %f dlin_: %f\n", masker_amps_dB_lin_delta(i), masker_amps_dB_lin_delta_(i));
% masker_amps_dB_lin_delta_(i) = masker_amps_dB_lin_delta(i);
end
end
- masker_amps_dB = f*gradient_ + masker_amps_dB_lin_delta_ + intercept;
+ masker_amps_dB = f*gradient + masker_amps_dB_lin_delta_ + intercept;
%decmaskdB = determine_mask(masker_amps_dB, masker_freqs_kHz, mask_sample_freqs_kHz);
decmaskdB = determine_mask(masker_amps_dB, masker_freqs_kHz, mask_sample_freqs_kHz);
end
+ if 0
printf("\n");
- for i=1:4
+ for i=1:Nsamples
printf("freq: %f amp: %f\n", masker_freqs_kHz(i), masker_amps_dB(i));
end
+ end
endfunction
maskdB_ = left_fraction*maskdB_left + right_fraction*maskdB_right;
else
maskdB_ = maskdB;
- printf("\n");
+ %printf("\n");
end
endfunction
decimate_in_time = 1;
synth_phase = 1;
freq_quant = 1;
- amp_quant = 1;
+ amp_quant = 2;
non_masked_f_log = [];
non_masked_m_log = [];
non_masked_amp_log = [];
end
fam = fopen(Am_out_name,"wb");
+ if synth_phase
+ faw = fopen(Aw_out_name,"wb");
+ end
for f=1:frames
- printf("%d ", f);
+ %printf("%d ", f);
L = min([model(f,2) max_amp-1]);
Wo = model(f,1);
Am = model(f,3:(L+2));
if synth_phase
% synthesis phase spectra from magnitiude spectra using minimum phase techniques
fft_enc = 512;
- model(f,3:(L+1)) = Am_(2:L);
- phase = determine_phase(model, f);
+ model_ = model;
+ model_(f,3:(L+1)) = Am_(2:L);
+ phase = determine_phase(model_, f);
assert(length(phase) == fft_enc);
Aw = zeros(1, fft_enc*2);
Aw(1:2:fft_enc*2) = cos(phase);
plot_spectrum = 1;
freq_quant = 0;
amp_quant = 0;
+ abys = 1;
sn_name = strcat(samname,"_sn.txt");
Sn = load(sn_name);
% decimate in frequency
mask_sample_freqs_kHz = (1:L)*Wo*4/pi;
- [decmaskdB masker_freqs_kHz min_error mse_log1 mse_log2] = make_decmask_abys(maskdB, AmdB, Wo, L, mask_sample_freqs_kHz, freq_quant, amp_quant);
+ if abys == 1
+ [decmaskdB masker_freqs_kHz min_error mse_log1 mse_log2] = make_decmask_abys(maskdB, AmdB, Wo, L, mask_sample_freqs_kHz, freq_quant, amp_quant);
+ end
+ if abys == 2
+ [decmaskdB masker_freqs_kHz min_error mse_log1 mse_log2] = make_decmask_abys2(maskdB, AmdB, Wo, L, mask_sample_freqs_kHz, freq_quant, amp_quant);
+ end
figure(2)
tonef_kHz = masker_freqs_kHz;
legend('boxoff');
%plot(mask_sample_freqs_kHz*1000, min_error);
hold off;
+ grid
figure(3)
clf
% interactive menu
printf("\rframe: %d menu: n-next b-back a-Am ", f);
+
if freq_quant
printf("F");
else
end
printf("-freq_quant ");
if amp_quant
- printf("M");
+ printf("M-amp_quant ");
else
- printf("m");
+ printf("m-amp_quant ");
end
- printf("-amp_quant q-quit");
+ printf("q-quit");
fflush(stdout);
k = kbhit();
endif
if k == 'm'
if amp_quant == 0
- amp_quant = 1;
+ amp_quant = 2;
else
amp_quant = 0;
end