melvq;
-function [maskdB_ maskdB_cyclic Dabs dk_] = decimate_in_freq(maskdB, cyclic=1, Nkeep=7)
+function [maskdB_ maskdB_cyclic Dabs dk_] = 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
+
+if 0
D_ = D; % + 10*randn(1,L) + 10*j*randn(1,L);
D_(Nkeep+1:L-Nkeep) = 0; % truncate
d = ifft(D_); % back to spectrum at rate L
maskdB_ = real(d);
- Dk_ = [0 D(2:Nkeep-1) real(D(Nkeep)) D(L-Nkeep+1:L)]; % build rate Nkeep vector for quantisation
- dk_ = real(ifft(Dk_));
+end
+
+ % truncate D to rate k, convert to 2k length real vector for quantisation and transmission
+
+ Dk = [0 D(2:k-1) real(D(k)) D(L-k+1:L)];
+ dk = real(ifft(Dk));
+
+ % quantisation
- % OK now fix up last 500Hz, taper down 10dB at 4000Hz
+ if nargin == 4
+ [res dk_ ] = mbest(vq, dk, 4);
+ std(dk_ - dk)
+ else
+ dk_ = dk;
+ 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_(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
+ maskdB_ = real(d_);
+
+ % Finally fix up last 500Hz, taper down 10dB at 4000Hz
xpts = [ anchor-1 anchor L];
ypts = [ maskdB_(anchor-1) maskdB_(anchor) (maskdB_(anchor)-10)];
postfilter = 1;
dec_in_time = 0;
synth_phase = 0;
- freq_quant = 0;
- amp_quant = 0;
+ vq_en = 1;
dk_log = [];
model_name = strcat(samname,"_model.txt");
faw = fopen(Aw_out_name,"wb");
end
+ if vq_en
+ load vq;
+ end
+
% encoder loop ------------------------------------------------------
- %pp_bw = gen_pp_bw;
sd_sum = 0;
for f=1:frames
non_masked_m(f,1:length(a_non_masked_m)) = a_non_masked_m;
if dec_in_freq
- [maskdB_ tmp1 D dk_] = decimate_in_freq(maskdB, 1);
+ if vq_en
+ [maskdB_ tmp1 D dk_] = decimate_in_freq(maskdB, 1, 7, vq);
+ else
+ [maskdB_ tmp1 D dk_] = decimate_in_freq(maskdB, 1);
+ end
dk_log = [dk_log; dk_];
end
sd_sum += sum(maskdB - maskdB_);
newamp;
more off;
plot_spectrum = 1;
+ vq_en = 1;
% load up text files dumped from c2sim ---------------------------------------
model = load(model_name);
[frames tmp] = size(model);
+ if vq_en
+ load vq;
+ end
+
% Keyboard loop --------------------------------------------------------------
k = ' ';
[maskdB Am_freqs_kHz] = mask_model(AmdB, Wo, L);
[tmp1 tmp2 D] = decimate_in_freq(maskdB, 0);
- [maskdB_ maskdB_cyclic D_cyclic dk_] = decimate_in_freq(maskdB, 1);
+ if vq_en
+ [maskdB_ maskdB_cyclic D_cyclic dk_] = decimate_in_freq(maskdB, 1, 7, vq);
+ else
+ [maskdB_ maskdB_cyclic D_cyclic dk_] = decimate_in_freq(maskdB, 1);
+ end
plot(Am_freqs_kHz*1000, maskdB, ';mask;g');
plot(Am_freqs_kHz*1000, maskdB_cyclic, ';mask cyclic;b');