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

📄 quantiz.m

📁 很多matlab的源代码
💻 M
字号:
function [y,t,snr]=quantiz(x,l,a,ty,ty2)
% QUANTIZ Quantization by rounding or truncation
%
%       [Y,T,SNR]=QUANTIZ(F,L,A,TY,TY2) quantizes signal F to A levels.
%	If F is an array, L = [low,hi] =lower/upper time limits.
%	If F is a string of T, L=[low,hi,N] where N = # of sampling intervals. 
%	TY= 't' for truncate,  'r' for round, 's' for sign magnitude
%       TY2 is a plotting argument: TY2 > 0 generates a plot [Default: 1]
%	DEFAULTS: N = 100, TY = 'r' , TY2 = 1
%       Y returns the quantized values, T the time array,
%	SNR is a 3 element vector of the quantization SNR
%	SNR = [actual SNR; statistical SNR; analytical SNR (if string F)]
%
%        USAGE: QUANTIZ(T,Y) will plot the quantized signal.
%
%        QUANTIZ (with no input arguments) invokes the following example:
%
%         % Round y=sin(pi*t) over [0 2] to 8 levels at 50 intervals
%	  % and find the quantization SNR
%         >>[yq,tq,snry]=quantiz('sin(pi*t)',[0 2 50],8);


% ADSP Toolbox: Version 2.0 
% For use with "Analog and Digital Signal Processing", 2nd Ed.
% Published by PWS Publishing Co.
%
% Ashok Ambardar, EE Dept. MTU, Houghton, MI 49931, USA
% http://www.ee.mtu/faculty/akambard.html
% e-mail: akambard@mtu.edu
% Copyright (c) 1998



if nargin==0,help quantiz,disp('Strike a key to see results of the example')
pause,
 vx=matverch;
 if vx < 4, eval('clg');else,eval('clf');end
[yq,tq,snry]=quantiz('sin(pi*t)',[0 2 50],8);pause,snry,return,end

if nargin<5,ty2=1;end,
if nargin<4,ty='r';end
str=0;
if nargin<3,a=8;end,
if isstr(x),str=1;
  if length(l)>2,n=l(3);else,n=100;end,
 else,n=length(x)-1;
end
t=l(1):(l(2)-l(1))/n:l(2);
if isstr(x),f=eval(x);else,f=x;end
if a<=0,a=8;end
d=max(f)-min(f);a0=a/d;
if ty=='t',y=floor(a0*f)/a0;
  elseif ty=='s',
  y=(f<=0).*ceil(a0*f)/a0+(f>0).*fix(a0*f)/a0;
 else,y=round(a0*f)/a0;
end
%FOR SNR
e=f-y;sm=sum(f.*f);snr=10*log10(sm/sum(e.*e));
add=20*log10(a)-20*log10(d)+10.8;
snr=[snr;10*log10(sm/(n+1))+add];
if str==1,ps=enerpwr(x,[l(1) l(2)],l(2));snr=[snr;10*log10(ps)+add];end
%FOR PLOTTING
if ty2>0,plot(t,f,':'),hold on
if str==1,digiplot(t,y),else,dtplot(t,y,'.'),end,
grid,hold off,end

⌨️ 快捷键说明

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