NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

root/DPWP/trunk/DPWP/nortek/nortek_radialtouvw.m

Revision 314 (checked in by gdusek, 14 years ago)

changes to mulitple files due to recent merge

Line 
1 function [ID,SM,EP]=nortek_radialtouvw(pressure,range,orbit,sysinfo,data_type)
2
3
4 %This code takes the loaded orbit, pressure and system info data from an
5 %ADCP waves output and computes the uvw velocities in earth coordinates.
6 %It also interpolates to remove bad data points and prepares the data
7 %structure required for running the DIWASP program.  The output will be in
8 %the structures ID, SM and EP.
9
10 %data_type is:
11 %1 to use uvw and pressure to generate the data structures,
12 %2 to use ranges
13 %3 to use radial velocity data
14
15
16
17 %make sure to load: pressure=load('pressure data'),
18 %orbit=load('orbital data'),sysinfo=load('sysinfo data') and range
19
20 %what is the transducer face height off the bottom?
21 adcpheight=0.5;
22
23 %whats the magnetic variation
24 magvar=-10;
25
26 %set up pressure
27 press=pressure/1000;
28
29 %find the average depth
30 avgdepth=mean(press)+adcpheight;
31
32 %set up range
33 range=range/1000;
34 meanrange=mean(range);
35 meanrange=repmat(meanrange,4096,1);
36 dmrange=range-meanrange;
37 std_range=std(dmrange);
38
39 %need to decrease the number of range samples
40
41 dmrange=decimate(dmrange,2);
42
43
44 %set up sysinfo file
45 heading=sysinfo(6,:);
46 pitch=sysinfo(7,:);
47 roll=sysinfo(8,:);
48 binheight=sysinfo(11,:);
49
50 %Find the std deviation of orbitals
51 orbit=orbit/1000;
52 std_orbit=std(orbit);
53 orbitnew=orbit;
54
55 %interpolate to take out any NaNs
56 for i=1:3
57     ibad=find(abs(orbit(:,i)) > 5*std_orbit(:,i));
58     orbit(ibad,i)=NaN;
59     time=[1:1:length(orbit(:,i))];
60     NaNs=isnan(orbit(:,i));
61     igood=find(NaNs == 0);
62     ibad=find(NaNs == 1);
63
64     intValues= interp1(time(igood),orbit(igood,i),time(ibad));
65     orbitnew(ibad,i)=intValues;   
66 end
67
68 % Do the same for the range data
69 rangenew=dmrange;
70
71 ibad=find(abs(dmrange(:)) > 5*std_range(:));
72 dmrange(ibad)=NaN;
73 time=[1:1:length(dmrange(:))];
74 NaNs=isnan(dmrange(:));
75 igood=find(NaNs == 0);
76 ibad=find(NaNs == 1);
77
78 intValues= interp1(time(igood),dmrange(igood),time(ibad));
79 rangenew(ibad)=intValues;
80
81 dmrange=rangenew;
82    
83 %change heading, pitch, roll into degrees
84      
85 heading = heading/10;
86 pitch=pitch/10;
87 roll=roll/10;
88
89 %compute the original x,y,z positions for each beam for each bin to be accurate we need to take out the adcpheight
90
91 xyzpos=ones(3,3);
92 height=binheight;
93 pos=height*tan(25*pi/180);
94
95 xyzpos(:,1)=[0,pos,height];
96 xyzpos(:,2)=[pos*cos(30*pi/180),-pos*.5,height];
97 xyzpos(:,3)=[-pos*cos(30*pi/180),-pos*.5,height];
98 beam4xpos=mean(press)*tan(roll*(pi/180));
99 beam4ypos=mean(press)*tan(-pitch*(pi/180));
100
101  
102 % set up the new coordinate transformation matrix
103 CH = cos((heading+magvar)*pi/180);
104 SH = sin((heading+magvar)*pi/180);
105 CP = cos((pitch)*pi/180);
106 SP = sin((pitch)*pi/180);
107 CR = cos((-roll)*pi/180);
108 SR = sin((-roll)*pi/180);
109
110 %  let the matrix elements be ( a b c; d e f; g h j);
111 a = CH.*CR - SH.*SP.*SR;  b = SH.*CP; c = -CH.*SR - SH.*SP.*CR;
112 d = -SH.*CR - CH.*SP.*SR; e = CH.*CP; f = SH.*SR - CH.*SP.*CR;
113 g = CP.*SR;              h = SP;     j = CP.*CR;
114
115 %transform the original x,y,z positions to the new positions accounting for
116 %heading, pitch and roll... we also add adcpheight back in
117
118 new_xyzpos(1,:)=xyzpos(1,:)*a+xyzpos(2,:)*b+xyzpos(3,:)*c;
119 new_xyzpos(2,:)=xyzpos(1,:)*d+xyzpos(2,:)*e+xyzpos(3,:)*f;
120 new_xyzpos(3,:)=xyzpos(1,:)*g+xyzpos(2,:)*h+xyzpos(3,:)*j+adcpheight;
121 new_xyzpos(:,4)=[beam4xpos,beam4ypos,avgdepth];%this is for the vertical beam...the z position will always =the avg depth
122
123 xyzpositions=new_xyzpos;
124
125
126
127
128 %compute the x,y positions for each beam for each bin and the surface
129
130 %sin45=0.7071
131 xypositions=ones(1,4);
132
133    
134 %beam 1
135 bearing=(heading+magvar)*(pi/180);
136 distfromz=binheight*tan((25-pitch)*(pi/180));
137 xpos=sin(bearing)*distfromz;
138 ypos=cos(bearing)*distfromz;
139
140 distroll=binheight*tan(roll*(pi/180));
141 beam1xpos=xpos+0.7071*distroll;
142 beam1ypos=ypos+0.7071*distroll;
143
144 %beam 2
145 bearing=bearing+2/3*pi;
146 distfromz=binheight*tan(25*(pi/180));
147 xpos=sin(bearing)*distfromz;
148 ypos=cos(bearing)*distfromz;
149 beam2xpos=xpos+binheight*tan(roll*(pi/180));
150 beam2ypos=ypos+binheight*tan(-pitch*(pi/180));
151
152 %beam 3
153 bearing=bearing+2/3*pi;
154 distfromz=binheight*tan(25*(pi/180));
155 xpos=sin(bearing)*distfromz;
156 ypos=cos(bearing)*distfromz;
157 beam3xpos=xpos+binheight*tan(-roll*(pi/180));
158 beam3ypos=ypos+binheight*tan(-pitch*(pi/180));
159
160
161
162 xypositions=[beam1xpos beam2xpos beam3xpos beam4xpos; beam1ypos beam2ypos beam3ypos beam4ypos];
163
164
165 %Put into structures for DIWASP
166
167 %sampling frequency
168 ID.fs=2;
169 %depth
170 ID.depth=(adcpheight+mean(press));
171 %the spectral matrix structure
172 SM.freqs=[0.01:0.01:0.4];
173 SM.dirs=[-180:2:180];
174 SM.xaxisdir= 90;
175 %the estimation parameter
176 EP.method= 'IMLM';
177 EP.iter=3;
178
179 if data_type == 1
180     %For radial velocities and the range beam
181     % the datatypes
182     ID.datatypes={'elev' 'radial' 'radial' 'radial'};
183     % the layout
184     ID.layout = [xyzpositions(1,4) xyzpositions(1,1) xyzpositions(1,2) xyzpositions(1,3);xyzpositions(2,4) xyzpositions(2,1) xyzpositions(2,2) xyzpositions(2,3);
185     xyzpositions(3,4) xyzpositions(3,1) xyzpositions(3,2) xyzpositions(3,3)];
186     % the data
187     ID.data = horzcat(dmrange, orbitnew(:,1), orbitnew(:,2), orbitnew(:,3));
188
189 end
190
191
192
193
194  
195
196
197
198
199
200
Note: See TracBrowser for help on using the browser.