melvq;
-function [maskdB_ maskdB_cyclic Dabs dk_] = decimate_in_freq(maskdB, cyclic=1, k=7, vq)
+function [maskdB_ maskdB_cyclic Dabs dk_ D1 ind] = decimate_in_freq(maskdB, cyclic=1, k=7, vq)
% Lets try to come up with a smoothed, cyclic model. Replace
% points from 3500 Hz to 4000Hz with a sequence that joins without
D = fft(maskdB);
end
Dabs = abs(D); % this returned for plotting
+ D1 = D(1); % pass energy back for training
% truncate D to rate k, convert to 2k length real vector for quantisation and transmission
+ % note we remove DC term as this is the frame energy that we quantise elsewhere
Dk = [0 D(2:k-1) real(D(k)) D(L-k+1:L)];
- dk = real(ifft(Dk));
+ dk = real(ifft(Dk)); % Q: why is there any imag part at all?
% quantisation
if nargin == 4
- [res dk_ ] = mbest(vq, dk, 4);
- std(dk_ - dk)
+ [res dk_ vq_ind] = mbest(vq, dk, 4);
+ [D1_ D1_ind] = quantise(0:(2000/15):2500, D1);
+ ind = [vq_ind D1_ind];
+ printf(" vq: %4.1f D1: %4.1f\n", std(dk_ - dk), D1_- D1);
else
dk_ = dk;
+ D1_ = D1;
end
% convert quantised dk back to rate L magnitude spectrum
Dk_ = fft(dk_);
D_ = zeros(1,L);
- D_(1) = D(1); % lets assume energy comes through separately
+ D_(1) = D1; % energy seprately quantised
D_(2:k-1) = Dk_(2:k-1);
D_(L-k+1:L) = Dk_(k+1:2*k);
d_ = ifft(D_); % back to spectrum at rate L
ypts = [ maskdB_(anchor-1) maskdB_(anchor) (maskdB_(anchor)-10)];
mask_pp = splinefit(xpts, ypts, 1);
maskdB_ = [maskdB_(1:anchor) ppval(mask_pp, anchor+1:L)];
-
+
endfunction
+
function tp = est_pf_locations(maskdB_)
% find turning points - used for finding PF freqs when we decimate in time
% quantise input sample to nearest value in table, optionally return bianry code
-function [quant_out bits] = quantise(levels, quant_in)
+function [quant_out best_i bits] = quantise(levels, quant_in)
% find closest quantiser level
left_fraction = 1 - mod((f-1),decimate)/decimate;
right_fraction = 1 - left_fraction;
- printf("f: %d left_f: %d right_f: %d left_fraction: %f right_fraction: %f \n", f, left_f, right_f, left_fraction, right_fraction)
+ printf("f: %d left_f: %d right_f: %d left_fraction: %3.2f right_fraction: %3.2f \n", f, left_f, right_f, left_fraction, right_fraction)
% fit splines to left and right masks
% process a whole file and write results
-function dk_log = newamp_batch(samname, optional_Am_out_name, optional_Aw_out_name)
+function [dk_log D1_log] = newamp_batch(samname, optional_Am_out_name, optional_Aw_out_name)
newamp;
more off;
dec_in_time = 1;
synth_phase = 1;
vq_en = 1;
- dk_log = [];
+ D_log = []; dk_log = []; D1_log = []; ind_log = [];
train = 0;
model_name = strcat(samname,"_model.txt");
maskdB_(a_non_masked_m) = maskdB_(a_non_masked_m) + 9;
end
- AmdB_ = maskdB;
+ AmdB_ = AmdB;
if dec_in_freq
if vq_en
- [AmdB_ tmp1 D dk_] = decimate_in_freq(maskdB, 1, 10, vq);
+ [AmdB_ tmp1 Dabs dk_ D1 ind] = decimate_in_freq(maskdB, 1, 10, vq);
+ ind_log = [ind_log; ind];
else
- [AmdB_ tmp1 D dk_] = decimate_in_freq(maskdB, 1, 10);
+ [AmdB_ tmp1 D dk_ D1] = decimate_in_freq(maskdB, 0, 10);
+ end
+ if train
+ dk_log = [dk_log; dk_];
+ D1_log = [D1_log D1];
end
- dk_log = [dk_log; dk_];
end
+ %AmdB_(1:L/8) = maskdB(1:L/8);
AmdB_pf = AmdB_*1.5;
AmdB_pf += max(AmdB_) - max(AmdB_pf);
- %sd_sum += sum(maskdB - AmdB_pf);
+ sd_sum += std(maskdB - AmdB_);
%AmdB_pf = AmdB_;
Am_ = zeros(1,max_amp);
Am_ = 10 .^ (AmdB_pf(1:L-1)/20);
model_(f,3:(L+1)) = Am_;
end
- printf("\nsd_sum: %5.2f\n", sd_sum/frames);
% decoder loop -----------------------------------------------------
fclose(faw);
end
+ printf("\nsd_sum: %5.2f\n", sd_sum/frames);
printf("\n");
endfunction
dec_in_freq = 1;
dec_in_time = 0;
vq_en = 0;
- mask_en = 0;
+ mask_en = 1;
% load up text files dumped from c2sim ---------------------------------------
%plot(Am_freqs_kHz*1000, maskdB, ';mask;g');
if mask_en
- AmdB_ = maskdB;
+ AmdB_ = AmdB = maskdB;
else
- AmdB_ = AmdB;
+ AmdB_ = AmdB = AmdB;
end
if dec_in_freq
[tmp1 tmp2 D] = decimate_in_freq(AmdB, 0);
if vq_en
[AmdB_ AmdB_cyclic D_cyclic dk_] = decimate_in_freq(AmdB, 1, 10, vq);
+ plot(Am_freqs_kHz*1000, AmdB_, ';mask trunc vq;c');
else
[AmdB_ AmdB_cyclic D_cyclic dk_] = decimate_in_freq(AmdB_, 1, 10);
+ plot(Am_freqs_kHz*1000, AmdB_, ';mask trunc;c');
end
plot(Am_freqs_kHz*1000, AmdB_cyclic, ';mask cyclic;b');
- plot(Am_freqs_kHz*1000, AmdB_, ';mask trunc;c');
AmdB_pf = AmdB_*(1.5);
- AmdB_pf += mean(AmdB) - mean(AmdB_pf);
+ AmdB_pf += max(AmdB_) - max(AmdB_pf);
%max(AmdB_pf)-max(AmdB_)
%AmdB_pf -= max(AmdB_pf)-max(AmdB_);
end
%AmdB_pf = AmdB_*(1.5);
%AmdB_pf += mean(AmdB) - mean(AmdB_pf);
- AmdB_pf = AmdB_;
- plot(Am_freqs_kHz*1000, AmdB_pf, ';mask trunc pf;g');
+ %AmdB_pf = AmdB_;
+
+ %plot(Am_freqs_kHz*1000, AmdB_pf, ';after pf;g');
+ axis([0 4000 20 80]);
% Optional decimated parameters
% need to general model_ parameters either side
figure(5)
clf
- stem(dk_)
+ stem(dk_);
+ axis([0 20 -60 60])
end
% interactive menu ------------------------------------------