Home > . > raw2phys.m

# raw2phys

## PURPOSE

'raw2phys': transform raw signal to physical values using different calibrations laws

## SYNOPSIS

function FieldPhys=raw2phys(Field)

## DESCRIPTION

    'raw2phys': transform raw signal to physical values using different calibrations laws

## CROSS-REFERENCE INFORMATION

This function calls:

This function is called by:

## SOURCE CODE

    0001 %'raw2phys': transform raw signal to physical values using different calibrations laws
    0002 %
    0003 function FieldPhys=raw2phys(Field)
    0004
    0005 % do not transform if Field already in phys coordinates
    0006 FieldPhys=Field;%default
    0007 if isfield(Field,'CoordType') & isequal(Field.CoordType,'phys')
    0008     return %no transform if the data are already physical
    0009 else
    0010     FieldPhys.CoordType='phys';
    0011 end
    0012
    0013 %Filtering of the initial data
    0014 nbfilter=51;
    0015 nbhalf=floor(nbfilter/2);
    0016 for ivar=1:length(FieldPhys.ListVarName)
    0017     VarName=FieldPhys.ListVarName{ivar};
    0018     if ~isequal(VarName,'time')
    0019         eval(['FirstVal=FieldPhys.' VarName '(1);'])
    0020         eval(['LastVal=FieldPhys.' VarName '(end);'])
    0021         FirstVal=ones(nbhalf,1)*FirstVal;
    0022         LastVal=ones(nbhalf,1)*LastVal;
    0023         eval(['FieldPhys.' VarName '=[FirstVal;FieldPhys.' VarName ';LastVal];'])
    0024         eval(['FieldPhys.' VarName '=conv(ones(1,nbfilter)/nbfilter,FieldPhys.' VarName ');']);
    0025          eval(['FieldPhys.' VarName '([1:nbfilter-1])=[];']);
    0026          eval(['FieldPhys.' VarName '([end-nbfilter+2:end])=[];']);
    0027     end
    0028 end
    0029
    0030
    0031
    0032 ScanRate=240; %data points per second
    0033 VelTranslation=1; % 1 cm/s A VERIFIER
    0034 test_Offset=0;
    0035 test_Thermistance_B=0;
    0036 test_Thermistance_M=0;
    0037 if isfield(Field,'ListVarAttribute')
    0038     for ilist=1:length(Field.ListVarAttribute)
    0039         attr_name=Field.ListVarAttribute{ilist}
    0040         if isequal(attr_name,'PhysUnits')
    0041             FieldPhys.units =Field.PhysUnits;
    0042         end
    0043         if isequal(attr_name,'Offset')
    0044             test_Offset=1;
    0045         end
    0046         if isequal(attr_name,'ThermistanceCalib_B')
    0047             test_Thermistance_B=1;
    0048         end
    0049         if isequal(attr_name,'ThermistanceCalib_M')
    0050             test_Thermistance_M=1;
    0051         end
    0052     end
    0053 end
    0054
    0055
    0056
    0057 % substract offset
    0058 if test_Offset
    0059     for ivar=1:length(Field.ListVarName)
    0060         Val_Offset=Field.Offset{ivar};
    0061         if isnumeric(Val_Offset)&~isempty(Val_Offset)
    0062             VarName=Field.ListVarName{ivar};
    0063             eval(['FieldPhys.' VarName '=FieldPhys.' VarName '-Val_Offset;'])
    0064         end
    0065     end
    0066 end
    0067
    0068 %thermistance calibration
    0069 if test_Thermistance_M & test_Thermistance_B
    0070     for ivar=1:length(Field.ListVarName)
    0071         Val_B=Field.ThermistanceCalib_B{ivar};
    0072         Val_M=Field.ThermistanceCalib_M{ivar};
    0073         if isnumeric(Val_B) & ~isempty(Val_B) & isnumeric(Val_M) & ~isempty(Val_M)
    0074             VarName=Field.ListVarName{ivar};
    0075             eval(['FieldPhys.' VarName '=(Val_M ./ (log( FieldPhys.' VarName ')-Val_B)) -273.15;'])
    0076         end
    0077     end
    0078 end
    0079 return
    0080
    0081 %NON USED
    0082 %density profile
    0083 Density=(Conductivity-B)/A;%calibration
    0084 Density=Density(find(Motor>1));%restrict the record to the time motor on
    0085 Density=flipdim(Density,2)';
    0086 %detect free surface
    0087 [dmax,imax]=max(diff(Density));
    0088 nbpoints=length(Density);
    0089 Pos=linspace(0,nbpoints*VelTranslation/ScanRate,nbpoints);
    0090 Pos=Pos-imax*VelTranslation/ScanRate;
    0091
    0092 %[dmax,jmax]=max(diff(Conductivity))
    0093 napoints=length(Conductivity);
    0094 Pos1=linspace(0,napoints*VelTranslation/ScanRate,napoints);
    0095 %Pos1=Pos1-jmax*VelTranslation/ScanRate;
    0096
    0097 figure(2);
    0098 clf
    0099 plot(Pos1,Conductivity)
    0100 grid on
    0101 figure(3);
    0102 size(Pos)
    0103 size(Density)
    0104 plot(Pos,Density)
    0105 hold on
    0106 grid on
    0107 %determination of N
    0108 PosCentr=Pos([floor(nbpoints/4):floor(3*nbpoints/4)]);
    0109 DensityCentr=Density([floor(nbpoints/4):floor(3*nbpoints/4)]);
    0110 p=polyfit(PosCentr,DensityCentr,1);
    0111 LinDens=polyval(p,PosCentr);
    0112 plot(PosCentr,LinDens,'r')
    0113 grad=p(1)
    0114 %find(Motor>1)
    0115
    0116 % data.conductivity=flipdim(Conductivity(find(Motor>5)),1)';
    0117 % data.deplacement=[100/size(data.conductivity,2):100/size(data.conductivity,2):100];
    0118 %
    0119 % figure;plot(data.deplacement,data.conductivity);hold on;
    0120
    0121 %data.density=flipdim(Conductivity(find(Motor>1)),1)'*3.4764+15.1367;
    0122 %data.density=flipdim(Conductivity(find(Motor>1)),2)'*5+14.6090;
    0123 %data.density=flipdim(Conductivity(find(Motor>1)),2)'*4.1525+19.50;
    0124 % data.density=flipdim(Conductivity(find(Motor>1)),2)'
    0125 % data.deplacement=[92/size(data.density,2):92/size(data.density,2):92];
    0126 % figure(101)
    0127 % plot(data.deplacement,data.density);hold on;
    0128
    0129 % t=data.deplacement(find(data.deplacement>20&data.deplacement<80));
    0130 %t=data.deplacement(find(data.deplacement>0&data.deplacement<90));
    0131 % X=[ones(size(t,2),1)';t];
    0132 % Y=data.density(find(data.deplacement>20&data.deplacement<80));
    0133 % %Y=data.density(find(data.deplacement>0&data.deplacement<90));
    0134 % coeff=Y/X;
    0135
    0136 % plot(data.deplacement,data.deplacement*coeff(2)+coeff(1),'r');
    0137
    0138 % grad=abs(coeff(2)*100)
    0139 Tbv=2*pi/sqrt(981*0.001*grad)
    0140 N=2*pi/Tbv
    0141 title(strcat('',name,''))
    0142 xpos=get(gca,'XLim')
    0143 ypos=get(gca,'YLim')
    0144 %xtext=xpos(1)+(xpos(2)-xpos(1))*3/4
    0145 xtext=xpos(1)+(xpos(2)-xpos(1))/2
    0146 ytext=ypos(1)+(ypos(2)-ypos(1))/4
    0147 TabText={strcat('Tbv : ',num2str(Tbv),'s'); strcat('Stratification : ',num2str(grad)); strcat('N : ',num2str(2*pi/Tbv),'rad.s-1')}
    0148 text(xtext,ytext,TabText)
    0149 % text(xtext,13,strcat('Tbv : ',num2str(Tbv),'s'));
    0150 % text(55,10,strcat('Stratification : ',num2str(grad)));
    0151 % text(55,16,strcat('N : ',num2str(2*pi/Tbv),'rad.s-1'));