Home > atmlab > sensors > atovs > unpack_bip.m

unpack_bip

PURPOSE ^

unpack_bip Unpacks Band-Interleaved by Pixel (BIP) data in uint16

SYNOPSIS ^

function out = unpack_bip(in)

DESCRIPTION ^

 unpack_bip Unpacks Band-Interleaved by Pixel (BIP) data in uint16

 AVHRR GAC data Earth views are stored in Band-Interleaved by Pixel (BIP)
 10-bit format. This function takes 32-bit words encoded with BIP and
 extracts the counts for all channels.

 FORMAT

   counts = unpack_bip(bip_data)

 IN

   bip_data      682-element uint32 (as returned by <a href="atmlab:help avhrr_gac_read_raw">avhrr_gac_read_raw</a>

 OUT

   counts        409*5 uint16, counts for channels 1--5

 $Id: unpack_bip.m 8340 2013-04-16 17:02:42Z gerrit $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

unpack_bip.m

SOURCE CODE ^

0001 function out = unpack_bip(in)
0002 
0003 % unpack_bip Unpacks Band-Interleaved by Pixel (BIP) data in uint16
0004 %
0005 % AVHRR GAC data Earth views are stored in Band-Interleaved by Pixel (BIP)
0006 % 10-bit format. This function takes 32-bit words encoded with BIP and
0007 % extracts the counts for all channels.
0008 %
0009 % FORMAT
0010 %
0011 %   counts = unpack_bip(bip_data)
0012 %
0013 % IN
0014 %
0015 %   bip_data      682-element uint32 (as returned by <a href="atmlab:help avhrr_gac_read_raw">avhrr_gac_read_raw</a>
0016 %
0017 % OUT
0018 %
0019 %   counts        409*5 uint16, counts for channels 1--5
0020 %
0021 % $Id: unpack_bip.m 8340 2013-04-16 17:02:42Z gerrit $
0022 
0023 % FIXME: make this function vectorised
0024 
0025 % words = uint32([...
0026 %                 bin2dec('00000000000000000000001111111111'), ...
0027 %                 bin2dec('00000000000011111111110000000000'), ...
0028 %                 bin2dec('00111111111100000000000000000000'), ...
0029 %                 ]);
0030 words = uint32([1023, 1047552, 1072693248]);
0031 
0032 bit_0_9 = bitand(words(1), in);
0033 bit_10_19 = bitshift(bitand(words(2), in), -10);
0034 bit_20_29 = bitshift(bitand(words(3), in), -20);
0035 
0036 % sort it as bit_20_29 bit_10_19 bit_0_9 because the data are big-endian
0037 % and like this, channel order will be contiguous (1 2 3 4 5 1 2 ... 4 5 -)
0038 % see also NOAA KLM User's Guide Table 8.3.1.4.3.2-1.
0039 
0040 backsorted = [bit_20_29 bit_10_19 bit_0_9]';
0041 backsorted = backsorted(:);
0042 ch1 = backsorted(1:5:end-5);
0043 ch2 = backsorted(2:5:end);
0044 ch3 = backsorted(3:5:end);
0045 ch4 = backsorted(4:5:end);
0046 ch5 = backsorted(5:5:end);
0047 out = [ch1 ch2 ch3 ch4 ch5];
0048 end

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005