CalMresfdaV.m 2.7 KB
Newer Older
1
function [normI,phi,firstZ,MresHV,MresV] = CalMresfdaV(n_and_dateZ,Zamp,qemres)
2

3
%uses calculated sine and cosine instead of fda CorNSTEXZstuf signals with a shift by 22 samples for the Q Cor signal
4
% to get the Iand Q data
5
6
7

% set_path % TO BE COMMENTED OUT WHEN MERGING WITH QEMPANEL
tic
8
9
10
11
%load lastMresV
set_path
[Xsnif, Zsnif] =getFDAreaderXZ(n_and_dateZ);
[XCor, ZCor] =getFDAreaderXZCor(n_and_dateZ);
12
13
14
15
16
17
18
siz=size(Xsnif);
NBPM=siz(1); NSTE=size(XCor,1);
MresH=zeros(NBPM,NSTE);
MresV=zeros(NBPM,NSTE);
MresHV=zeros(NBPM,NSTE);
MresHI=zeros(NBPM,NSTE);
MresVI=zeros(NBPM,NSTE);
19

20
21
22
MresHQ=zeros(NBPM,NSTE);
MresVQ=zeros(NBPM,NSTE);
MresHVQ=zeros(NBPM,NSTE);
23
    
24
25
26
27
% for i=1:NSTE
%    CorNSTEZstuf(i,1:siz(2))=ZCor(i,1:siz(2))-mean(ZCor(i,:));
% end 
CorNSTEZstuf=ZCor-repmat(mean(ZCor,2)',siz(2),1)';
28
    
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
disp(['Zamp=' num2str(Zamp) ...
      '   # steerers=', num2str(size(CorNSTEZstuf,1)) ...
      '   buffer size=',num2str(size(CorNSTEZstuf,2)) ])
  
[ CZI,CZQ,firstZ,lastZ,lengthZ]  = Corfast_fda2(CorNSTEZstuf,Zamp,Zamp/10);

Xres=zeros(1,siz(2));
Zres=zeros(1,siz(2));
CX=zeros(1,siz(2));
CZ=zeros(1,siz(2));
 
C=CZI./repmat(sum(abs(CZI),2),1,siz(2));
A=max(abs(CZI),[],2);
MresHI=Xsnif*C'./repmat(A',NBPM,1);
MresVI=Zsnif*C'./repmat(A',NBPM,1);
CQ=CZQ./repmat(sum(abs(CZQ),2),1,siz(2));
AQ=max(abs(CZQ),[],2);
MresHQ=Xsnif*CQ'./repmat(AQ',NBPM,1);
MresVQ=Zsnif*CQ'./repmat(AQ',NBPM,1); 
48

49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
%     for j=1:NSTE
%      j
%         
%         for k=1:NBPM
%              
%            Xres(1:siz(2))=Xsnif(k,1:siz(2));
%             Zres(1:siz(2))=Zsnif(k,1:siz(2));
%             %CX(1:siz(2))=CXI(j,1:siz(2));
%             CZ(1:siz(2))=CZI(j,1:siz(2));
%             
%             C=CZ/sum(abs(CZ));
%             A=max(abs(CZ));
%            
%          
%        
%         MresHI(k,j)=MresH(k,j)+Xres*C'/A;
%         MresVI(k,j)=MresV(k,j)+Zres*C'/A;
%        
%             
%             [ CZ ] = CZQ(j,1:siz(2));
%             
%           
%             C=CZ/sum(abs(CZ));
%             A=max(abs(CZ));
%            
%             
%         MresHQ(k,j)=MresH(k,j)+Xres*C'/A;
%         MresVQ(k,j)=MresV(k,j)+Zres*C'/A;
% 
%         
%           end
%        
%     end
82
83
84
85
86
87
88
89
90
91
92
93
94
95

stdHI=std(MresHI);
stdHQ=std(MresHQ);
stdVI=std(MresVI);
stdVQ=std(MresVQ);
%calibration factor OK for.1A=32768
G=1e9*.2/pi*2*.5/32768;

normI=sqrt(stdVI.^2+stdVQ.^2)./stdVI;
normQ=sqrt(stdVI.^2+stdVQ.^2)./stdVQ;
phi=stdVQ./sqrt(stdVI.^2+stdVQ.^2);



96
for i=1:NSTE
97
98
99
100
101
102
103
104
105
106
107
    if phi(i)< .8
MresV(:,i)=MresVI(:,i)*normI(i)/G;
MresHV(:,i)=MresHI(:,i)*normI(i)/G;
    else
MresV(:,i)=MresVQ(:,i)*normQ(i)/G;
MresHV(:,i)=MresHQ(:,i)*normQ(i)/G;        
    end       
end

time=time_label;
file=['TimeLabelMresZ',time];
108

109
save(fullfile(qemres.datadir,file),'n_and_dateZ' , 'MresV','MresHV');
110

111
toc