?? subject re arma matlab code.htm
字號:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0071)http://tyche.mat.univie.ac.at/~rauth/matnews/time.series.ARMA.code.html -->
<HTML><HEAD><TITLE>Subject: Re: ARMA matlab code</TITLE>
<META content="text/html; charset=gb2312" http-equiv=Content-Type>
<META content="MSHTML 5.00.2314.1000" name=GENERATOR></HEAD>
<BODY>
<H3>Subject: Re: ARMA matlab code</H3><PRE>From: <A href="mailto:brown.m.w@nort.bwi.wec.com">brown.m.w@nort.bwi.wec.com</A> (Mark W. Brown)
Reply-To: <A href="mailto:brown.m.w@nort.bwi.wec.com">brown.m.w@nort.bwi.wec.com</A>
Newsgroups: comp.soft-sys.matlab
Subject: Re: ARMA matlab code
Date: Wed, 18 Oct 1995 14:02:41 GMT
Organization: Westinghouse Electronic Systems
Message-ID: <<A href="mailto:DGnDoH.M75@tron.bwi.wec.com">DGnDoH.M75@tron.bwi.wec.com</A>>
References: <<A href="mailto:beser.813606352@aplcomm.jhuapl.edu">beser.813606352@aplcomm.jhuapl.edu</A>>
In article <<A href="mailto:beser.813606352@aplcomm.jhuapl.edu">beser.813606352@aplcomm.jhuapl.edu</A>>, <A href="mailto:beser@aplcomm.jhuapl.edu">beser@aplcomm.jhuapl.edu</A> (Nick Beser) says:
>
>I am trying to track down any time series analysis matlab code (in particular
>code that implements the ARMA (Autoregressive Model).
>
>Thanks,
>
>Nick Beser
>Johns Hopkins University
Nick,
Here's some MATLAB code which computes the AR coefficients
and then plots the resulting power spectral density.
Example Usage: % Given input time series X.
% Want 3rd order AR coeffients.
% Plot 128 points in frequency domain.
[s,b] = arcoeff(3,X);
[p,w] = pspect(s,b,128);
semilogy(w,p);
This was orignially written under MATLAB 3.X. I haven't used
it since then, so I hope it still works. Hope this helps. :-)
-Mark-
--------------------------------------------------------------
function [s,b] = arcoeff(n,x)
% function [s,b] = arcoeff(n,x) returns the nth order
% autoregressive coefficients (b) and sigma (s) given
% a data vector (x).
% Compute the autocorrelation coefficients and find
% the zeroth order lag position:
zero = length(x);
ryy = xcorr(x,'unbiased');
% Initialize the size of some matrices:
d = zeros(n,1);
b = zeros(n,n);
s = zeros(n,1);
% Compute the first order as a special case:
d(1) = ryy(zero+1);
b(1,1) = -d(1)/ryy(zero);
s(1) = ryy(zero)*(1-abs(b(1,1))^2);
% Use the full Levinsons algorithm for orders => 2:
for m=2:n
d(m) = ryy(zero+m);
for k=1:m-1
d(m) = d(m) + b(m-1,k)*ryy(zero+m-k);
end
b(m,m) = -d(m)/s(m-1);
for k=1:m-1
b(m,k) = b(m-1,k) + b(m,m)*b(m-1,m-k)';
end
s(m) = s(m-1)*(1-abs(b(m,m))^2);
end
% Return the desired sigma and autoregressive coefficients:
s = s(n);
b = b(n,:);
--------------------------------------------------------------
function [p,w] = pspect(s,b,N)
% function p = pspect(s,b) computes the autoregressive
% power spectral density (p) given the nth order AR
% coefficients (b) and sigma (s) computed from ARCOEFF.
% N samples of the PSD at frequencies (w) are returned.
% Compute the equivalent transfer function H:
[H,w] = freqz(1,[1 b],N);
% Compute the power spectral density function:
p = s*(H.*conj(H));
--------------------------------------------------------------
</PRE></BODY></HTML>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -