principles projects CNMI-Guam old projects |
Dtacq2weraNew% dtacq2wera chirp-by-chirp NCHAN=16; % number of dtacq A/D channel pairs IQ=2; % number of channels to make a pair OVER=2; % dtacq oversampling rate NANT=16; % WERA number of antennas MT=1984; % number of WERA samples per chirp NCHIRP=2048; % number of chirps SKIP=1; % number of chirps skipped FIRSKIP=28; % number of samples skipped before first chirp due to FIR transcient SHIFT=7; % number of bits lost when converting 32->16 bits HEADTAG='2048 SAMPLES '; % part of the header necessary fi=fopen(filein,'r','ieee-le'); fseek(fi,0,'eof'); pos=ftell(fi); % check file size is big enough to skip FIR transcient and first chirp, plus % still contain 2048 chirps if pos<((NCHAN*IQ*OVER*MT*(NCHIRP+SKIP))+(FIRSKIP*NCHAN*IQ))*4 error('File size incorrect: Input file too small') else % move to after FIR transcient and first chirp clear pos fseek(fi,((FIRSKIP*NCHAN*IQ)+(SKIP*NCHAN*IQ*OVER*MT))*4,'bof'); % make channel map; first column is dta channel, second is WERA % antenna, third is IQ (1 for I, 2 for Q) % for swapped I and Q cables map=reshape([ 1 1 2 2 5 2 3 1 1 4 5 1 5 2 2 6 6 2 7 2 1 8 6 1 9 3 2 10 ... 7 2 11 3 1 12 7 1 13 4 2 14 8 2 15 4 1 16 8 1 17 13 1 18 9 1 19 13 ... 2 20 9 2 21 14 1 22 10 1 23 14 2 24 10 2 25 15 1 26 11 1 27 15 2 28 ... 11 2 29 16 1 30 12 1 31 16 2 32 12 2],3,32)'; % for normal I and Q cables map=reshape([ 1 1 1 2 5 1 3 1 2 4 5 2 5 2 1 6 6 1 7 2 2 8 6 2 9 3 1 10 ... 7 1 11 3 2 12 7 2 13 4 1 14 8 1 15 4 2 16 8 2 17 13 2 18 9 2 19 13 ... 1 20 9 1 21 14 2 22 10 2 23 14 1 24 10 1 25 15 2 26 11 2 27 15 1 28 ... 11 1 29 16 2 30 12 2 31 16 1 32 12 1],3,32)'; % get time of acquisition for header ft=fopen(filetime,'r','ieee-le'); timed=fread(ft,inf,'*char'); fclose(ft); % get WERA header fh=fopen(filehead,'r','ieee-le'); header=fread(fh,inf,'*char'); fclose(fh); clear ft fh % write header to output file fo=fopen(fileout,'w','ieee-le'); fwrite(fo,[HEADTAG timed' header'],'*char'); clear header timed % loop over all chirps wera=int16(zeros(IQ,MT,NANT,NCHIRP)); for ichirp=1:NCHIRP data=fread(fi,[NCHAN*IQ,OVER*MT],'int32=>int32'); % average oversampling, get rid of SHIFT bits, and move to 16-bit % reorder channels to WERA standard sdata=int16(zeros(NCHAN*IQ,MT)); wera1=int16(zeros(IQ,MT,NANT)); for ichan=1:NANT*IQ sdata(ichan,1:MT)=int16((data(ichan,1:OVER:OVER*MT-1) ... + data(ichan,2:OVER:OVER*MT))/2^(SHIFT+1)); wera1(IQ-map(ichan,3)+1,:,map(ichan,2))=sdata(ichan,:); end clear data ichan %wera(:,:,:,ichirp)=wera1; % write data chirp-by-chirp fwrite(fo,wera1,'int16'); end clear ichirp map fclose(fo); end fclose(fi); clear fi fo save(filemat) |