COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### Zero Up Crossing for Spectral Analysis

• Email
• Follow

```Hello everyone, I am new in using Matlab but have very great interest to increase my skill in it. I hope you can help me solve one of my problem in solving zero up crossing in ocean wave analysis.

The input data consist of 2 column, the first is time and the second is surface water elevation. What i need to do is to calculate the period and wave height from that data.

I can process the data to get period, but to get wave height proved difficult to me. I already try several algorithm but not good enough. If I can find highest and lowest water elevation between upcrossings, it will solve my problem

fname=input('filename: ', 's');
fid=fopen(fname,'r');
A=fscanf(fid,'%g %g',[2 inf]);
fclose(fid);
B1=A';
B2(:,1)=B1(:,1);
k=1;
% Find Mean
r(:,1)=B1(:,2);
r1=r';
rata=ratarata(r1);
[m,n]=size(r1);
k=1;

% Zero Mean
for k=1:n
B3(k,1)=r1(1,k)-rata;
end

plot(B2, B3);

B=[B2 B3];
[b1,b2]=size(B);

% Upcossing time
j=1;
o=1;
for k=1:b1
if k+1>b1
break
end
y1=B(k,2);
y2=B(k+1,2);
if(y1==0)&(k>1)
y1=0.00005;
end
if (y1<y2)&(y1*y2<=0)
Cek(o,5)=y1;
Cek(o,6)=y2;
o=o+1;
x1=B(k,1);
x2=B(k+1,1);
t(j,1)=x1-y1*(x2-x1)/(y2-y1);
j=j+1;
end
end

% Wave Period
k=1;
j=1;
[t1,t2]=size(t);
while k<=(t1-1)
T(j,1)=t(k+1,1)-t(k,1);
k=k+1;
j=j+1;
end

% Find maximum between crossing
d=1;
o=1;
g=1;
for k=1:b1
if k+1>b1
break
end
b3=B(k,2);
b4=B(k+1,2);
if(b3==0)&(k>1)
b3=0.0000005;
end
if ((b3<b4)&&((b3*b4)<=0))
Cek(o,1)=b3;
Cek(o,2)=b4;
o=o+1;
l=1;
c=1;
D1=[];
D2=[];
for z=(k+l):(b1-1)
bz1=B(z,2);
bz2=B(z+1,2);
% Maximum Matrix
D1(c,1)=B(z-1,1);
D2(c,1)=B(z-1,2);
c=c+1;
if(bz1==0)&(k>1)
bz1=0.0000005;
end
if((bz1<bz2)&&((bz1*bz2)<=0))
Cek(g,3)=bz1;
Cek(g,4)=bz2;
g=g+1;
break
end
end
D3=max(max(D2));
for a=k:z
if(B(a,2))==D3
disp(D3);
disp(a);
disp(k);
%Parabolic equation to find estimated highest elevation
x1=B(a-1,1);
x2=B(a,1);
x3=B(a+1,1);
y1=B(a-1,2);
y2=B(a,2);
y3=B(a+1,2);
P2=[y1;y2;y3];
P1=[x1^2,x1,1;x2^2,x2,1;x3^2,x3,1];
P=(inv(P1))*P2;
a=P(1,1);b=P(2,1);c=P(3,1);
xmax=(-1*b)/(2*a);
ym(d,1)=(xmax^2)*a+xmax*b+c;
d=d+1;
end
end
end
end
if(t1<=d)
ym((d-1),:)=[];
end
%Find minimum between crossing
d=1;
for k=2:b1
if k+1>b1
break
end
b5=B(k,2);
b6=B(k+1,2);
if(b5==0)&(k>1)
b5=0.0000005;
end
if ((b5<b6)&&((b5*b6)<=0))
l=1;
c=1;
D4=[];
D5=[];
for z=(k+l):(b1-1)
bz3=B(z,2);
bz4=B(z+1,2);
% Minimum Matrix
D4(c,1)=B(z-1,1);
D5(c,1)=B(z-1,2);
c=c+1;
if((bz3<bz4)&&((bz3*bz4)<=0))
break
end
end
D6=min(min(D5));
for a=k:(b1-1)
if(B(a,2))==D6
%Parabolic equation to find estimated lowest elevation
x1=B(a-1,1);
x2=B(a,1);
x3=B(a+1,1);
y1=B(a-1,2);
y2=B(a,2);
y3=B(a+1,2);
P2=[y1;y2;y3];
P1=[x1^2,x1,1;x2^2,x2,1;x3^2,x3,1];
P=(inv(P1))*P2;
a=P(1,1);b=P(2,1);c=P(3,1);
xmin=(-1*b)/(2*a);
ymin(d,1)=(xmin^2)*a+xmin*b+c;
d=d+1;
end
end
end
end
if(t1<=d)
ymin((d-1),:)=[];
end
[m,n]=size(ym);
[m1,n1]=size(ymin);
if(m>m1)
ym((m1+1),:)=[];
end

%Wave Height
H=ym-ymin;

%Result Matrix
U=[T H];
disp(U);
```
 0

See related articles to this posting

```On Nov 8, 8:17=A0pm, "Arifian " <akira_shiniz...@yahoo.com> wrote:
> Hello everyone, I am new in using Matlab but have very great interest to =
increase my skill in it. I hope you can help me solve one of my problem in =
solving zero up crossing in ocean wave analysis.
>
> The input data consist of 2 column, the first is time and the second is s=
urface water elevation. What i need to do is to calculate the period and wa=
ve height from that data.
>
> I can process the data to get period, but to get wave height proved diffi=
cult to me. I already try several algorithm but not good enough. If I can f=
ind highest and lowest water elevation between upcrossings, it will solve m=
y problem
>
> fname=3Dinput('filename: ', 's');
> fid=3Dfopen(fname,'r');
> A=3Dfscanf(fid,'%g %g',[2 inf]);
> fclose(fid);
> B1=3DA';
> B2(:,1)=3DB1(:,1);
> k=3D1;
> % Find Mean
> r(:,1)=3DB1(:,2);
> r1=3Dr';
> rata=3Dratarata(r1);
> [m,n]=3Dsize(r1);
> k=3D1;
>
> % Zero Mean
> for k=3D1:n
> B3(k,1)=3Dr1(1,k)-rata;
> end
>
> plot(B2, B3);
>
> B=3D[B2 B3];
> [b1,b2]=3Dsize(B);
>
> % Upcossing time
> j=3D1;
> o=3D1;
> for k=3D1:b1
> =A0 =A0 if k+1>b1
> =A0 =A0 =A0 =A0 break
> =A0 =A0 end
> =A0 =A0 y1=3DB(k,2);
> =A0 =A0 y2=3DB(k+1,2);
> =A0 =A0 if(y1=3D=3D0)&(k>1)
> =A0 =A0 =A0 =A0 y1=3D0.00005;
> =A0 =A0 end
> =A0 =A0 if (y1<y2)&(y1*y2<=3D0)
> =A0 =A0 =A0 =A0 Cek(o,5)=3Dy1;
> =A0 =A0 =A0 =A0 Cek(o,6)=3Dy2;
> =A0 =A0 =A0 =A0 o=3Do+1;
> =A0 =A0 =A0 =A0 x1=3DB(k,1);
> =A0 =A0 =A0 =A0 x2=3DB(k+1,1);
> =A0 =A0 =A0 =A0 t(j,1)=3Dx1-y1*(x2-x1)/(y2-y1);
> =A0 =A0 =A0 =A0 j=3Dj+1;
> =A0 =A0 end
> end
>
> % Wave Period
> k=3D1;
> j=3D1;
> [t1,t2]=3Dsize(t);
> while k<=3D(t1-1)
> =A0 =A0 T(j,1)=3Dt(k+1,1)-t(k,1);
> =A0 =A0 k=3Dk+1;
> =A0 =A0 j=3Dj+1;
> end
>
> % Find maximum between crossing
> d=3D1;
> o=3D1;
> g=3D1;
> for k=3D1:b1
> =A0 =A0 if k+1>b1
> =A0 =A0 =A0 =A0 break
> =A0 =A0 end
> =A0 =A0 b3=3DB(k,2);
> =A0 =A0 b4=3DB(k+1,2);
> =A0 =A0 if(b3=3D=3D0)&(k>1)
> =A0 =A0 =A0 =A0 b3=3D0.0000005;
> =A0 =A0 end
> =A0 =A0 if ((b3<b4)&&((b3*b4)<=3D0))
> =A0 =A0 =A0 =A0 Cek(o,1)=3Db3;
> =A0 =A0 =A0 =A0 Cek(o,2)=3Db4;
> =A0 =A0 =A0 =A0 o=3Do+1;
> =A0 =A0 =A0 =A0 l=3D1;
> =A0 =A0 =A0 =A0 c=3D1;
> =A0 =A0 =A0 =A0 D1=3D[];
> =A0 =A0 =A0 =A0 D2=3D[];
> =A0 =A0 =A0 =A0 for z=3D(k+l):(b1-1)
> =A0 =A0 =A0 =A0 =A0 =A0 bz1=3DB(z,2);
> =A0 =A0 =A0 =A0 =A0 =A0 bz2=3DB(z+1,2);
> =A0 =A0 =A0 =A0 =A0 =A0 % Maximum Matrix
> =A0 =A0 =A0 =A0 =A0 =A0 D1(c,1)=3DB(z-1,1);
> =A0 =A0 =A0 =A0 =A0 =A0 D2(c,1)=3DB(z-1,2);
> =A0 =A0 =A0 =A0 =A0 =A0 c=3Dc+1;
> =A0 =A0 =A0 =A0 =A0 =A0 if(bz1=3D=3D0)&(k>1)
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 bz1=3D0.0000005;
> =A0 =A0 =A0 =A0 =A0 =A0 end
> =A0 =A0 =A0 =A0 =A0 =A0 if((bz1<bz2)&&((bz1*bz2)<=3D0))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Cek(g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A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ym(d,1)=3D(xmax^2)*a+xmax*b+c;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 d=3Dd+1; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
> =A0 =A0 =A0 =A0 =A0 =A0end
> =A0 =A0 =A0 =A0 end
> =A0 =A0 end
> end
> =A0if(t1<=3Dd)
> =A0 =A0 =A0 =A0 ym((d-1),:)=3D[];
> =A0end
> =A0%Find minimum between crossing
> d=3D1;
> for k=3D2:b1
> =A0 =A0 if k+1>b1
> =A0 =A0 =A0 =A0 break
> =A0 =A0 end
> =A0 =A0 b5=3DB(k,2);
> =A0 =A0 b6=3DB(k+1,2);
> =A0 =A0 if(b5=3D=3D0)&(k>1)
> =A0 =A0 =A0 =A0 b5=3D0.0000005;
> =A0 =A0 end
> =A0 =A0 if ((b5<b6)&&((b5*b6)<=3D0))
> =A0 =A0 =A0 =A0 l=3D1;
> =A0 =A0 =A0 =A0 c=3D1;
> =A0 =A0 =A0 =A0 D4=3D[];
> =A0 =A0 =A0 =A0 D5=3D[];
> =A0 =A0 =A0 =A0 for z=3D(k+l):(b1-1)
> =A0 =A0 =A0 =A0 =A0 =A0 bz3=3DB(z,2);
> =A0 =A0 =A0 =A0 =A0 =A0 bz4=3DB(z+1,2);
> =A0 =A0 =A0 =A0 =A0 =A0 % Minimum Matrix
> =A0 =A0 =A0 =A0 =A0 =A0 D4(c,1)=3DB(z-1,1);
> =A0 =A0 =A0 =A0 =A0 =A0 D5(c,1)=3DB(z-1,2);
> =A0 =A0 =A0 =A0 =A0 =A0 c=3Dc+1;
> =A0 =A0 =A0 =A0 =A0 =A0 if((bz3<bz4)&&((bz3*bz4)<=3D0))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 break
> =A0 =A0 =A0 =A0 =A0 =A0 end
> =A0 =A0 =A0 =A0 end
> =A0 =A0 =A0 =A0 D6=3Dmin(min(D5));
> =A0 =A0 =A0 =A0 for a=3Dk:(b1-1)
> =A0 =A0 =A0 =A0 =A0 =A0if(B(a,2))=3D=3DD6
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 %Parabolic equation to find estimated low=
est elevation
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 x1=3DB(a-1,1);
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 x2=3DB(a,1);
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 x3=3DB(a+1,1);
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 y1=3DB(a-1,2);
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 y2=3DB(a,2);
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 y3=3DB(a+1,2);
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 P2=3D[y1;y2;y3];
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 P1=3D[x1^2,x1,1;x2^2,x2,1;x3^2,x3,1];
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 P=3D(inv(P1))*P2;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 a=3DP(1,1);b=3DP(2,1);c=3DP(3,1);
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 xmin=3D(-1*b)/(2*a);
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ymin(d,1)=3D(xmin^2)*a+xmin*b+c;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 d=3Dd+1; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0
> =A0 =A0 =A0 =A0 =A0 =A0end
> =A0 =A0 =A0 =A0 end
> =A0 =A0 end
> end
> =A0if(t1<=3Dd)
> =A0 =A0 =A0 =A0 ymin((d-1),:)=3D[];
> =A0end
> =A0[m,n]=3Dsize(ym);
> =A0[m1,n1]=3Dsize(ymin);
> =A0if(m>m1)
> =A0 =A0 =A0ym((m1+1),:)=3D[];
> =A0end
>
> =A0%Wave Height
> =A0H=3Dym-ymin;
>
> =A0%Result Matrix
> =A0U=3D[T H];
> =A0disp(U);

The title of your post does not relate to what you posted.  I guess
you are a little mixed up.
One uses spectral analysis to get significant wave heights, periods,
etc and zero-crossing analysis to get H1/3 or H1/10 - average of the
highest 3rd or tenth of the waves.

The main algorithm can be executed in one line without any loops:
indx=3Dfind(y(1:end-1)*y(2:end) < 0);
Now, indx contains the addresses of all the zero crossings, so
calculation of the wave height and period is straightforward.
```
 0