001 function covplot(rn,L,plotflag,lintype)
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036 if ndims(rn.R)>2
037 error('Can only handle one- and two dimensional ACF')
038 end
039 if (nargin <3 | isempty(plotflag))
040 plotflag=1;
041 end
042 if nargin<4|isempty(lintype)
043 lintype='b-';
044 end
045 if ~isfield(rn,'norm')
046 rn.norm=0;
047 end
048
049 n=length(rn.R);
050
051 if prod(size(rn.R))==n,
052 ih=ishold;
053
054 if n<2,
055 error('The vector must have more than 2 elements!')
056 end
057
058 if (nargin <2 | isempty(L)),
059 L=n-1;
060 else
061 L=min(L,n-1);
062 end
063 names=fieldnames(rn);
064 ind=find(strcmp(names,'x')+strcmp(names,'t'));
065 vari=lower(names{ind});
066 t=getfield(rn,vari);
067 dT=t(2)-t(1);
068 if strcmpi(vari,'t')
069 unit=' (sec)';
070 else
071 unit=' (m)';
072 end
073
074 if isfield(rn,'stdev') & ~isempty(rn.stdev),
075 Stdev=rn.stdev(1:(L+1));
076 size(Stdev)
077 else
078 Stdev=[];
079 end
080
081
082 if (dT==1 ),
083 plotflag=1;
084 end
085
086 if (plotflag == 3), subplot(211), end
087
088 r = rn.R(1:(L+1));
089 tau = (0:L) ;
090 mx=max(abs(r));
091 if (plotflag == 2) |(plotflag == 3)
092
093 plot(tau,r,lintype) , hold on
094 plot([tau(1) tau(L+1)],[0 0],'k-')
095 if ~isempty(Stdev),
096 plot(tau,2*Stdev,'r--')
097 plot(tau,-2*Stdev,'r--')
098 end ,if ~ih, hold off, end
099 if dT==1,
100 xlabel(['Lag Lag',unit])
101 else
102 xlabel('Lag')
103 end
104 ylabel('ACF')
105 grid on
106 if ih, a=axis; else a=zeros(1,4); end
107 axis([0 max(tau(L+1),a(2)) min(-1.01*mx,a(3)) max(1.01*mx,a(4)) ])
108 if rn.norm,
109 title('Auto Correlation Function (ACF)' )
110 else
111 title('Auto Covariance Function (ACF)' )
112 end
113 end
114
115 if (plotflag == 3)
116 subplot(212)
117 end
118
119 if (plotflag == 1) |(plotflag == 3)
120 tau = tau*dT ;
121 plot(tau,r,lintype),hold on
122 plot([tau(1) tau(L+1)],[0 0],'k-')
123 if ~isempty(Stdev),
124 plot(tau,2*Stdev,'r--')
125 plot(tau,-2*Stdev,'r--')
126 end, if ~ih,hold off,end
127 xlabel(['Lag',unit])
128 ylabel('ACF')
129 grid on
130 if ih, a=axis; else a=zeros(1,4); end
131 axis([0 max(tau(L+1),a(2)) min(-1.01*mx,a(3)) max(1.01*mx,a(4)) ])
132 if rn.norm,
133 title('Auto Correlation Function (ACF)' )
134 else
135 title('Auto Covariance Function (ACF)' )
136 end
137 end
138 subplot(111)
139 if ih, hold on, end
140 else
141
142 [nx,nt]=size(rn.R);
143 if (nargin <2 | isempty(L)),
144 L=[nx-1, nt-1];
145 elseif length(L)==1
146 L=[min(L,nx-1) min(L,nt-1)];
147 else
148 L=[min(L(1),nx-1) min(L(2),nt-1)];
149 end
150
151 names=fieldnames(rn);
152 ind=find(strcmp(names,'x')+strcmp(names,'t')+strcmpi(names,'y'));
153
154 vari1=names{ind(1)};
155 vari2=names{ind(2)};
156 if strcmpi(vari2,'t')
157 unit=' [sec]';
158 else
159 unit=' [m]';
160 end
161 x=eval(['rn.',vari1]);
162 t=eval(['rn.',vari2]);
163 if strcmp(vari2,'y')
164 rn.R=rn.R';
165 end
166 if plotflag == 1
167 if strcmp(rn.type,'polar')
168 if rn.y(1)>=0
169 c=contour([-rn.y(end:-1:2);rn.y],rn.x,[rn.R(:,end:-1:2) rn.R]);
170 else
171 c=contours(rn.y,rn.x,rn.R);
172 end
173 limit = size(c,2);
174 ix = 1;
175 while(ix < limit)
176 z_level(ix) = c(1,ix);
177 npoints = c(2,ix);
178 nexti = ix+npoints+1;
179 c(:,ix)=NaN;
180 ix = nexti;
181 end
182 polar(c(1,:),c(2,:),'b');
183 else
184 contour(x,t,rn.R',lintype)
185 xlabel([vari1 ' [m]'])
186 ylabel([vari2 unit])
187 end
188 if rn.norm,
189 title('Auto Correlation Function (ACF)' )
190 else
191 title('Auto Covariance Function (ACF)' )
192 end
193 elseif plotflag==2
194 surf(x,t,rn.R')
195 shading interp
196 if rn.norm,
197 title('Auto Correlation Function (ACF)' )
198 else
199 title('Auto Covariance Function (ACF)' )
200 end
201 xlabel([vari1 ' [m]'])
202 ylabel([vari2 unit])
203 else
204 subplot(211)
205 plot(x,rn.R(:,t==0),lintype)
206 ih=ishold;
207 hold on
208 plot([x(1) x(end)],[0 0],':')
209 if ~ih, hold off, end
210 if rn.norm,
211 title('Auto Correlation Function (ACF)' )
212 else
213 title('Auto Covariance Function (ACF)' )
214 end
215 xlabel([vari1 ' (m)'])
216 subplot(212)
217 plot(t,rn.R(x==0,:),lintype)
218 ih=ishold;
219 hold on
220 plot([t(1) t(end)],[0 0],':')
221 if ~ih, hold off, end
222 if rn.norm,
223 title('Auto Correlation Function (ACF)' )
224 else
225 title('Auto Covariance Function (ACF)' )
226 end
227 xlabel([vari2 unit])
228 end
229 end
230