source: trunk/src/raw2phys.m @ 35

Last change on this file since 35 was 19, checked in by gostiaux, 15 years ago

the private files have been moved down to the root folder

File size: 5.0 KB
Line 
1%'raw2phys': transform raw signal to physical values using different calibrations laws
2%
3function FieldPhys=raw2phys(Field)
4
5% do not transform if Field already in phys coordinates
6FieldPhys=Field;%default
7if isfield(Field,'CoordType') & isequal(Field.CoordType,'phys')
8    return %no transform if the data are already physical
9else
10    FieldPhys.CoordType='phys';
11end
12
13%Filtering of the initial data
14nbfilter=51;
15nbhalf=floor(nbfilter/2);
16for ivar=1:length(FieldPhys.ListVarName)
17    VarName=FieldPhys.ListVarName{ivar};
18    if ~isequal(VarName,'time')
19        eval(['FirstVal=FieldPhys.' VarName '(1);'])
20        eval(['LastVal=FieldPhys.' VarName '(end);'])
21        FirstVal=ones(nbhalf,1)*FirstVal;
22        LastVal=ones(nbhalf,1)*LastVal;   
23        eval(['FieldPhys.' VarName '=[FirstVal;FieldPhys.' VarName ';LastVal];'])
24        eval(['FieldPhys.' VarName '=conv(ones(1,nbfilter)/nbfilter,FieldPhys.' VarName ');']);
25         eval(['FieldPhys.' VarName '([1:nbfilter-1])=[];']);
26         eval(['FieldPhys.' VarName '([end-nbfilter+2:end])=[];']);
27    end
28end
29
30
31
32ScanRate=240; %data points per second
33VelTranslation=1; % 1 cm/s A VERIFIER
34test_Offset=0;
35test_Thermistance_B=0;
36test_Thermistance_M=0;
37if isfield(Field,'ListVarAttribute')
38    for ilist=1:length(Field.ListVarAttribute)
39        attr_name=Field.ListVarAttribute{ilist}
40        if isequal(attr_name,'PhysUnits')
41            FieldPhys.units =Field.PhysUnits;
42        end
43        if isequal(attr_name,'Offset')
44            test_Offset=1;
45        end
46        if isequal(attr_name,'ThermistanceCalib_B')
47            test_Thermistance_B=1;
48        end 
49        if isequal(attr_name,'ThermistanceCalib_M')
50            test_Thermistance_M=1;
51        end
52    end
53end
54
55
56
57% substract offset
58if test_Offset
59    for ivar=1:length(Field.ListVarName)
60        Val_Offset=Field.Offset{ivar};
61        if isnumeric(Val_Offset)&~isempty(Val_Offset)
62            VarName=Field.ListVarName{ivar};
63            eval(['FieldPhys.' VarName '=FieldPhys.' VarName '-Val_Offset;'])
64        end
65    end
66end
67
68%thermistance calibration
69if test_Thermistance_M & test_Thermistance_B
70    for ivar=1:length(Field.ListVarName)
71        Val_B=Field.ThermistanceCalib_B{ivar};
72        Val_M=Field.ThermistanceCalib_M{ivar};
73        if isnumeric(Val_B) & ~isempty(Val_B) & isnumeric(Val_M) & ~isempty(Val_M)
74            VarName=Field.ListVarName{ivar};
75            eval(['FieldPhys.' VarName '=(Val_M ./ (log( FieldPhys.' VarName ')-Val_B)) -273.15;'])
76        end
77    end
78end
79return
80
81%NON USED
82%density profile
83Density=(Conductivity-B)/A;%calibration
84Density=Density(find(Motor>1));%restrict the record to the time motor on
85Density=flipdim(Density,2)';
86%detect free surface
87[dmax,imax]=max(diff(Density));
88nbpoints=length(Density);
89Pos=linspace(0,nbpoints*VelTranslation/ScanRate,nbpoints);
90Pos=Pos-imax*VelTranslation/ScanRate;
91
92%[dmax,jmax]=max(diff(Conductivity))
93napoints=length(Conductivity);
94Pos1=linspace(0,napoints*VelTranslation/ScanRate,napoints);
95%Pos1=Pos1-jmax*VelTranslation/ScanRate;
96
97figure(2);
98clf
99plot(Pos1,Conductivity)
100grid on
101figure(3);
102size(Pos)
103size(Density)
104plot(Pos,Density)
105hold on
106grid on
107%determination of N
108PosCentr=Pos([floor(nbpoints/4):floor(3*nbpoints/4)]);
109DensityCentr=Density([floor(nbpoints/4):floor(3*nbpoints/4)]);
110p=polyfit(PosCentr,DensityCentr,1);
111LinDens=polyval(p,PosCentr);
112plot(PosCentr,LinDens,'r')
113grad=p(1)
114%find(Motor>1)
115
116% data.conductivity=flipdim(Conductivity(find(Motor>5)),1)';
117% data.deplacement=[100/size(data.conductivity,2):100/size(data.conductivity,2):100];
118%
119% figure;plot(data.deplacement,data.conductivity);hold on;
120
121%data.density=flipdim(Conductivity(find(Motor>1)),1)'*3.4764+15.1367;
122%data.density=flipdim(Conductivity(find(Motor>1)),2)'*5+14.6090;
123%data.density=flipdim(Conductivity(find(Motor>1)),2)'*4.1525+19.50;
124% data.density=flipdim(Conductivity(find(Motor>1)),2)'
125% data.deplacement=[92/size(data.density,2):92/size(data.density,2):92];
126% figure(101)
127% plot(data.deplacement,data.density);hold on;
128
129% t=data.deplacement(find(data.deplacement>20&data.deplacement<80));
130%t=data.deplacement(find(data.deplacement>0&data.deplacement<90));
131% X=[ones(size(t,2),1)';t];
132% Y=data.density(find(data.deplacement>20&data.deplacement<80));
133% %Y=data.density(find(data.deplacement>0&data.deplacement<90));
134% coeff=Y/X;
135
136% plot(data.deplacement,data.deplacement*coeff(2)+coeff(1),'r');
137
138% grad=abs(coeff(2)*100)
139Tbv=2*pi/sqrt(981*0.001*grad)
140N=2*pi/Tbv
141title(strcat('',name,''))
142xpos=get(gca,'XLim')
143ypos=get(gca,'YLim')
144%xtext=xpos(1)+(xpos(2)-xpos(1))*3/4
145xtext=xpos(1)+(xpos(2)-xpos(1))/2
146ytext=ypos(1)+(ypos(2)-ypos(1))/4
147TabText={strcat('Tbv : ',num2str(Tbv),'s'); strcat('Stratification : ',num2str(grad)); strcat('N : ',num2str(2*pi/Tbv),'rad.s-1')}
148text(xtext,ytext,TabText)
149% text(xtext,13,strcat('Tbv : ',num2str(Tbv),'s'));
150% text(55,10,strcat('Stratification : ',num2str(grad)));
151% text(55,16,strcat('N : ',num2str(2*pi/Tbv),'rad.s-1'));
Note: See TracBrowser for help on using the repository browser.