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

📄 predict.m

📁 英文书《Digital Signal Processing with Examples in MATLAB》附带的MATLAB实例
💻 M
字号:
function [e,b]=predict(x,N,c)
% [e,b]=predict(x,N,c)
%
% Least-squares one-step prediction of a single waveform.
% Note: this version has rounding and is used mainly in signsl comprssion.
% Inputs:
%    N  = filter size.
%    x  = input vector to FIR predictor. 
%         NOTE: x is rounded to integers.
%    c  = omitted or 0 for covariance; 1 for correlation.
%         NOTE: correlation is much faster than covariance.
% Outputs:  
%    e  = prediction error, e(1:length(x)), rounded to integers.
%    b  = optimal weight vector with N elements.
%
% See also: unpredict, lms_predict, lms_filter
x=round(col_vec(x));                    %x is rounded
if max(abs(x))==0
    error ('No prediction possible because x=0 after rounding.')
end
if nargin<3,
    c=0;
elseif c~=0 & c~=1,
    error ('Third argument (c) is not 0 or 1.')
end
K=length(x);
if c==0,
    Rff=autocovar_mat(x,N);           %covariance if c=0
    rfd=crosscovar([0; x(1:K-1)],x,N);
else
    Rff=autocorr_mat(x,0,N);            %correlation if not
    rfd=crosscorr([0; x(1:K-1)],x,0,N);
end
b=Rff\rfd;                              %optimal weights
g=filter([0; b],1,x);                   %one-step prediction
e=x-round(g);                           %e is rounded by rounding g

⌨️ 快捷键说明

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