?? f_nonlin_compand.m
字號:
function y = f_nonlin_compand(x, type, V, nbits_in, nbits_out)
% nonlinear transforms compander
% type == 1, % compression;
% else extension
% V is the maximum value of output and input
n = length(x);
if type == 1, % compression;
% define the range
x_min = - 2^nbits_in ;
x_max = + 2^nbits_in -1;
in_range = x_max - x_min;
y_min = - 2^nbits_out ;
y_max = + 2^nbits_out -1;
out_range = y_max - y_min;
if nbits_in < nbits_out, disp('error 1'); end;
for i=1:n,
if x(i) >= 0,
y(i) = out_range * log2(x(i) / in_range + 1) / 2;
else
y(i) = -out_range * log2(x(i) / in_range - 1) / 2;
end;
end;
y = y./(max(abs(y)));
y = y .* V;
else % extension
% define the range
x_min = - 2^nbits_in ;
x_max = + 2^nbits_in -1;
in_range = x_max - x_min;
y_min = - 2^nbits_out ;
y_max = + 2^nbits_out -1;
out_range = y_max - y_min;
if nbits_in > nbits_out, disp('error 2'); end;
for i=1:n,
if x(i) >=0,
xb(i) = in_range * 2^(2*x(i) / out_range) - in_range;
else
xb(i) = - in_range *( -1 / ( 2^(2*x(i) / out_range)) ) + in_range ;
end;
end;
xb = xb./(max(abs(xb)));
xb = xb .* V;
y = xb;
end;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -