freq.m

来自「英文书《Digital Signal Processing with Examp」· M 代码 · 共 24 行

M
24
字号
function [f,xmin,xmax]=freq(x)
% [f,xmin,xmax]=freq(x)
%
% Computes the amplitude distribution of x in terms of
% frequency vector f.
%
% Input: 
%   x =any INTEGER vector or array. (Real values are rounded.)
%
% Outputs:
%   f =row vector of symbol frequencies in x.
%      f(n)=(number of occurrences of x(xmin+n-1))/length(x),
%      for n=1,2,...,xmax-xmin+1.  Note: Sum(f)=1.
%   xmin,xmax =minimun and maximum elements in x.
x=round(row_vec(x));
xmin=min(x); xmax=max(x);
f=zeros(1,xmax-xmin+1);
for i=1:length(x),
   k=x(i)-xmin+1;
   f(k)=f(k)+1;
end
f=f/length(x);

⌨️ 快捷键说明

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