📄 adc_1_differential_m7.m
字号:
clc; clear; clf;
% Audio lossless differential codding
% difficulties:
% 1). Audio samples have real values,
% in oposition with image samples (integers, in general)
% A solution is scalling to an integer interval, [-128:127], for example
% p = 'D:\adorel\a_master_DC\standard_test_audio\';
% filename = 'Windows XP Startup.wav';
% file = strcat(p,filename);
file = 'Windows XP Startup.wav';
[I_all, fs, nbits] = wavread(file); % int16 format...Matlab 7.0 syntax
% [I_all,fs,nbits, opts] = wavread(file); % matlab6 syntax
% Ia1 = I_all .* 2^15;
% Ia = int16(Ia1);
% break;
% [I_all,fs,nbits, opts] = wavread(file); % int16 format...
% I_all = double(I_all);
% I_all = (I_all(:,1) + I_all(:,2) )./2;
Ns = length(I_all);
Ns = 1e3;
I = I_all(1:Ns);
% scale to [-1,1]:
y = double(I);
mx = max(abs(y));
a = y ./ mx;
a = double(a);
% scale to [-128, 127];
a = a .* 128;
a = int8(a);
% compute differencess ...
da = zeros(1,length(a));
da(1) = a(1);
for i=2:length(a),
% da(i) = a(i) - a(i-1);
da(i) = double(a(i)) - double(a(i-1));
end;
% check properties ... (value distribution)
max_a = 128;
step = 1;
ta = [-max_a : step : max_a - step];
% apdf = hist(a,ta);
apdf = hist(double(a),ta);
t = (0:Ns-1)./fs;
subplot(221), plot(t,a); title('Original signal'); xlabel('t[s]');
subplot(223), plot(ta,apdf); title('Probability density function');
max_da = max(abs(da));
% max_da = 128;
tda = [- max_da : 1 : max_da] ;
da = int8(da);
% dapdf = hist(da,tda);
dapdf = hist(double(da),tda);
subplot(222), plot(t,da); title('Succesive differences of the original signal');
xlabel('t[s]');
subplot(224), plot(tda, dapdf);
title('Probability density function');
save data_input.mat t I a da dapdf mx
% prepare the inputs for Huffman coding
S = int8(tda);
% adjust zero values to ones... only to compute probabilities..
dapdf_new = dapdf + 1;
P = dapdf_new / sum(dapdf_new);
save SP.mat S P
disp('Finished..');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -