⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 quant.m

📁 英文书《Digital Signal Processing with Examples in MATLAB》附带的MATLAB实例
💻 M
字号:
function [y,scl,shft]=quant(x,n)
% [y,scl,shft]=quantize(x,n)
%
% Inputs:    x =vector with real elements.
%            n =number of bits per quantized element of x.
%
% Outputs:   y =quantized x with n-bit integer elements.
%               The elements of y range from 0 to 2^n-1.
%          scl =scaling factor used to approximate x from y.
%         shft =shifting factor used to approximate x from y.
%               x may be approximated by (y-shft)*scl.
if n<1 | n>32,
    error('Number of bits (n) is out of range.');
end

y=x;                        %initially, y=x
x=row_vec(x);               %make x a row vector
if range(x)==0,
    return                  %if range(x)=0, y=x (no change)
end
scl=range(x)/(2^n-1);
x=x/scl;
%scale x to range 2^n-1.
shft=-min(x);
x=x+shft;                   %shift so min(x)=0.
y(:)=round(x);              %convert x to integers in y.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -