rate_L_sample_freqs_kHz = (1:L)*Wo*Fs/(2000*pi);
- %rate_K_surface(f,:) = interp1(rate_L_sample_freqs_kHz, AmdB, rate_K_sample_freqs_kHz, "spline", "extrap");
- rate_K_surface(f,:) = interp_para(rate_L_sample_freqs_kHz, AmdB, Fs/(2*1000), rate_K_sample_freqs_kHz);
+ rate_K_surface(f,:) = interp1(rate_L_sample_freqs_kHz, AmdB, rate_K_sample_freqs_kHz, "spline", "extrap");
+ %rate_K_surface(f,:) = interp_para(rate_L_sample_freqs_kHz, AmdB, Fs/(2*1000), rate_K_sample_freqs_kHz);
- %printf("\r%d/%d", f, frames);
+ %printf("%d\n", f);
end
%printf("\n");
endfunction
% Take a rate K surface and convert back to time varying rate L
function [model_ AmdB_] = resample_rate_L(model, rate_K_surface, rate_K_sample_freqs_kHz, Fs=8000)
- max_amp = 1600;
+ max_amp = 160;
[frames col] = size(model);
+ AmdB_ = zeros(frames, max_amp);
model_ = zeros(frames, max_amp+2);
for f=1:frames
Wo = model(f,1);
% back down to rate L
- % AmdB_ = interp1(rate_K_sample_freqs_kHz, rate_K_surface(f,:), rate_L_sample_freqs_kHz, "spline", 0);
- AmdB_ = interp_para(rate_K_sample_freqs_kHz, rate_K_surface(f,:), Fs/(2*1000), rate_L_sample_freqs_kHz);
-
- model_(f,1) = Wo; model_(f,2) = L; model_(f,3:(L+2)) = 10 .^ (AmdB_(1:L)/20);
+ AmdB_(f,1:L) = interp1(rate_K_sample_freqs_kHz, rate_K_surface(f,:), rate_L_sample_freqs_kHz, "spline", rate_K_surface(f,1));
+ %AmdB_(f,1:L) = interp_para(rate_K_sample_freqs_kHz, rate_K_surface(f,:), Fs/(2*1000), rate_L_sample_freqs_kHz);
+ %printf("f: %d %f %f %f\n", f, rate_K_sample_freqs_kHz(1), rate_L_sample_freqs_kHz(1), AmdB_(1));
+ model_(f,1) = Wo; model_(f,2) = L; model_(f,3:(L+2)) = 10 .^ (AmdB_(f, 1:L)/20);
end
endfunction
plot(mask_sample_freqs_kHz, residual);
end
- %printf("\nfr1: %f fr2: %f fr3: %f fr4: %f\n", fr1, fr2, fr3, fr4);
+ printf("\nfr1: %f fr2: %f fr3: %f fr4: %f\n", fr1, fr2, fr3, fr4);
[fvec fvec_ind] = sort([fr1 fr2 fr3 fr4]);
amps = amp(fvec_ind(1:4));
for f=1:frames
%printf("%d ", f);
Wo = model_(f,1); L = min([model_(f,2) max_amp-1]); Am = model_(f,3:(L+2));
+ assert(Wo*L < pi);
Am_ = zeros(1,max_amp); Am_(2:L) = Am(1:L-1); fwrite(fam, Am_, "float32");
fwrite(fWo, Wo, "float32");
function [model_ rate_K_surface] = experiment_const_freq(model, mean_removal, vq_filename)
[frames nc] = size(model);
Fs = 8000;
+ fg = 1;
+
+ energy = zeros(1,frames);
+ for f=1:frames
+ L = model(f,2);
+ energy(f) = 10*log10(sum( model(f,3:(L+2)) .^ 2 ));
+ end
melvq;
if length(vq_filename)
size(vq)
end
- rate_K_sample_freqs_kHz = [0.1:0.1:3.9];
+ rate_K_sample_freqs_kHz = [0.1:0.1:4];
K = length(rate_K_sample_freqs_kHz);
rate_K_surface = resample_const_rate_f(model, rate_K_sample_freqs_kHz, Fs);
if length(vq_filename)
[res rate_K_surface_ ind] = mbest(vq, rate_K_surface, m);
sd_per_frame = std(res');
- energy = zeros(1,frames);
- for f=1:frames
- L = model(f,2);
- energy(f) = 10*log10(sum( model(f,3:(L+2)) .^ 2 ));
- end
- figure(1); subplot(211); plot(energy); subplot(212); plot(sd_per_frame);
- figure(2); hist(sd_per_frame);
+ figure(fg++); subplot(211); plot(energy); subplot(212); plot(sd_per_frame);
+ figure(fg); hist(sd_per_frame);
printf("VQ rms SD: %3.2f\n", mean(sd_per_frame));
else
rate_K_surface_ = rate_K_surface;
[model_ AmdB_] = resample_rate_L(model, rate_K_surface_, rate_K_sample_freqs_kHz, Fs);
- sum_sd = 0;
+ % Measure distortion between AmdB and AmdB_, ths includes distortion
+ % in the rate K <-> L transition. Can optionally plot distorted
+ % frames
+
+ plot_sd_thresh = 10;
+ sd = zeros(1,frames);
for f=1:frames
+ Wo = model(f,1);
L = model(f,2);
AmdB = 20*log10(model(f,3:(L+2)));
- sum_sd = std(AmdB(1:L) - AmdB_(f,1:L));
+ sd(f) = std(AmdB(1:L) - AmdB_(f,1:L));
+ if sd(f) > plot_sd_thresh
+ printf("fg: %d f: %d\n", fg, f);
+ figure(fg++); clf; plot((1:L)*Wo*4/pi, AmdB(1:L),'b+-'); hold on; plot((1:L)*Wo*4/pi, AmdB_(f,1:L),'r+-');
+ plot(rate_K_sample_freqs_kHz, rate_K_surface_(f,:), 'c+-'); hold off;
+ end
end
- printf("rate K resampling SD: %3.2f\n", mean(sum_sd));
-
+ printf("rate K resampling SD: %3.2f\n", mean(sd));
+ figure(fg++); clf; subplot(211); plot(energy); subplot(212); plot(sd);
+ figure(fg++); clf; hist(sd);
endfunction