principles projects CNMI-Guam old projects |
Dtacq2weraOld% dtacq2wera NCHAN=16; % the number of dtacq A/D channel PAIRS IQ=2; % number of channels to make pair OVER=2; % the oversampling rate NANT=8; % the WERA number of antennas, remaining channels set to 0 MT=1984; % the number of WERA samples/chirp NCHIRP=2048; % the number of chirps SKIP=1; % we'll have to SKIP chirps SHIFT=6; % number of bits to loose when converting 32->16 bit % read a binary dtacq file over exact number of chirps % raw dtacq data: NCHIRP+SKIP of MT*OVER of NCHAN A/D channel pairs, % each containing IQ channels of 4 bytes (long) % file acquired with SKIP>>1 f=fopen(filein,'r','ieee-le'); raw=fread(f,Inf,'int32=>int32'); fclose(f); N=length(raw) % the raw number of samples NFRAM=floor(N/(NCHAN*IQ*OVER)) % the number of intact frames N=NFRAM*NCHAN*IQ*OVER % the cleaned number of samples data=reshape(raw(1:N),NCHAN*IQ,NFRAM*OVER); clear raw; % remap data channels to dtacq indices % root@acq164_061 ~ #cat /dev/dtacq/channel_mapping % checked - after mapping channels 17-32 are correctly empty % assume mapping is correct w.r.t I/Q map=reshape([ 1 0 2 4 3 8 4 12 5 1 6 5 7 9 8 13 9 2 10 6 11 10 12 14 13 3 14 7 15 11 16 15 17 19 18 23 19 27 20 31 21 18 22 22 23 26 24 30 25 17 26 21 27 25 28 29 29 16 30 20 31 24 32 28],2,32)'; map(:,2)=map(:,2)+1; mdata(squeeze(map(:,2)),:)=data(squeeze(map(:,1)),:); clear data; % average oversampling and decimate; shift to int16 range (/256) % I find that the /256 is way too much. After /256, max/min is 10000 but % std is only 500. Let/s divide by only 64 (6 bits SNR gained). % ENOB appears to be around 19 bits. Get rid of 6 bits sdata=zeros(NCHAN*IQ,NFRAM); for i=1:NCHAN*IQ sdata(i,1:NFRAM)=(mdata(i,1:OVER:OVER*NFRAM-1)+mdata(i,2:OVER:OVER*NFRAM))/2^(SHIFT+1); end %clear mdata; % clip overrange if any sdata(find(sdata>2^15-1))=2^15-1; sdata(find(sdata<-2^15+1))=-2^15+1; % 37 bad samples before first chirp sdata(:,1:37)=[]; % write binary wera data % .RAW format: NCHIRP of NANT antennas, each containing % MT samples of IQ of 2 bytes (short) % CAUTION! looking at Yves Barbin read function suggest that % the indices order is NANT,MT,IQ,NCHIRP % with the code below, I can read and % rewrite out and see Bragg lines with a Zambales .RAW file % skip first chirp % CAUTION! this is correct only for an 8-antenna 16-channel system wera=int16(zeros(IQ,MT,NANT,NCHIRP)); for ichirp=2:NCHIRP+1 for iant=1:NANT for imt=1:MT for iiq=1:IQ % verified by disconnecting: I 1...8 followed by Q 1...8 % wera(iiq,imt,iant,ichirp-1)=int16(sdata(iant+(iiq-1)*NANT,(ichirp-1)*MT+imt)); % I-Q swapped? try below wera(IQ-iiq+1,imt,iant,ichirp-1)=int16(sdata(iant+(iiq-1)*NANT,(ichirp-1)*MT+imt)); end end end end % output the binary part of a wera .RAW file f=fopen(fileout,'w','ieee-le'); fwrite(f,wera,'int16'); fclose(f); clear wera % save sdata, only for debugging, slow, do not save if not needed clear sdata; % save mdata save |