-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from hcab14/master
GPS timestamps for IQ mode
- Loading branch information
Showing
4 changed files
with
190 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
## -*- octave -*- | ||
|
||
function [x,xx]=proc(fn) ##20171119T171520Z_30000_iq.wav | ||
tic | ||
[x,fs]=read_kiwi_iq_wav(fn); | ||
toc; | ||
|
||
idx = find(cat(1,x.gpslast)<6); | ||
xx = {}; | ||
for i=1:length(idx) | ||
j=idx(i); | ||
xx(i).t = x(j).gpssec + 1e-9*x(j).gpsnsec + [0:length(x(j).z)-1]'/fs; | ||
xx(i).z = x(j).z; | ||
end | ||
|
||
if length(xx) != 0 | ||
subplot(2,2,1:2); plot(mod(cat(1,xx.t), 1), abs(cat(1,xx.z))); xlabel("GPS seconds mod 1 (sec)"); | ||
subplot(2,2,3); plot(mod(cat(1,xx.t), 1), abs(cat(1,xx.z)), '.'); xlim([0.0285 0.0294]) ; xlabel("GPS seconds mod 1 (sec)"); | ||
subplot(2,2,4); plot(mod(cat(1,xx.t), 1), abs(cat(1,xx.z)), '.'); xlim(0.1+[0.0285 0.0294]) ; xlabel("GPS seconds mod 1 (sec)"); | ||
end | ||
endfunction |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
// -*- C++ -*- | ||
|
||
#include <fstream> | ||
#include <octave/oct.h> | ||
|
||
class chunk_base { | ||
public: | ||
std::string id() const { return std::string((char*)(_id), 4); } | ||
std::streampos size() const { return _size; } | ||
private: | ||
int8_t _id[4]; | ||
uint32_t _size; | ||
} __attribute__((packed)); | ||
|
||
class chunk_riff : public chunk_base { | ||
public: | ||
std::string format() const { return std::string((char*)(_format), 4); } | ||
|
||
private: | ||
int8_t _format[4]; | ||
} __attribute__((packed)); | ||
|
||
class chunk_fmt : public chunk_base { | ||
public: | ||
uint16_t format() const { return _format; } | ||
uint16_t num_channels() const { return _num_channels; } | ||
uint32_t sample_rate() const { return _sample_rate; } | ||
uint32_t byte_rate() const { return _byte_rate; } | ||
uint16_t block_align() const { return _block_align; } | ||
|
||
protected: | ||
uint16_t _format; | ||
uint16_t _num_channels; | ||
uint32_t _sample_rate; | ||
uint32_t _byte_rate; | ||
uint16_t _block_align; | ||
uint16_t _dummy; | ||
} __attribute__((packed)); | ||
|
||
class chunk_kiwi : public chunk_base { | ||
public: | ||
uint8_t last() const { return _last; } | ||
uint32_t gpssec() const { return _gpssec; } | ||
uint32_t gpsnsec() const { return _gpsnsec; } | ||
private: | ||
uint8_t _last, _dummy; | ||
uint32_t _gpssec, _gpsnsec; | ||
} __attribute__((packed)); | ||
|
||
DEFUN_DLD (read_kiwi_iq_wav, args, nargout, "[d,sample_rate]=read_kiwi_wav(\"<wav file name\");") | ||
{ | ||
octave_value_list retval; | ||
|
||
const std::string filename = args(0).string_value(); | ||
if (error_state) | ||
return retval; | ||
|
||
std::ifstream file(filename, std::ios::binary); | ||
|
||
octave_value_list cell_z, cell_last, cell_gpssec, cell_gpsnsec; | ||
|
||
chunk_base c; | ||
chunk_fmt fmt; | ||
|
||
int data_counter=0; | ||
while (file) { | ||
std::streampos pos = file.tellg(); | ||
file.read((char*)(&c), sizeof(c)); | ||
if (!file) | ||
break; | ||
|
||
if (c.id() == "RIFF") { | ||
chunk_riff cr; | ||
file.seekg(pos); | ||
file.read((char*)(&cr), sizeof(cr)); | ||
if (cr.format() != "WAVE") { | ||
// complain | ||
break; | ||
} | ||
} else if (c.id() == "fmt ") { | ||
file.seekg(pos); | ||
file.read((char*)(&fmt), sizeof(fmt)); | ||
if (fmt.format() != 1 || | ||
fmt.num_channels() != 2) { | ||
// complain | ||
break; | ||
} | ||
retval(1) = octave_value(fmt.sample_rate()); | ||
} else if (c.id() == "data") { | ||
ComplexNDArray a(dim_vector(c.size()/4, 1)); | ||
int16_t i=0, q=0; | ||
for (int j=0; j<c.size()/4 && file; ++j) { | ||
file.read((char*)(&i), sizeof(i)); | ||
file.read((char*)(&q), sizeof(q)); | ||
a(j) = std::complex<double>(i/32768., q/32768.); | ||
} | ||
cell_z(data_counter++) = octave_value(a); | ||
} else if (c.id() == "kiwi") { | ||
file.seekg(pos); | ||
chunk_kiwi kiwi; | ||
file.read((char*)(&kiwi), sizeof(kiwi)); | ||
cell_last(data_counter) = octave_value(kiwi.last()); | ||
cell_gpssec(data_counter) = octave_value(kiwi.gpssec()); | ||
cell_gpsnsec(data_counter) = octave_value(kiwi.gpsnsec()); | ||
} else { | ||
std::cout << "skipping unknown chunk " << c.id() << std::endl; | ||
pos = file.tellg(); | ||
file.seekg(pos + c.size()); | ||
} | ||
} | ||
|
||
octave_map map; | ||
map.setfield("z", cell_z); | ||
if (cell_last.length() == cell_z.length()) { | ||
map.setfield("gpslast", cell_last); | ||
map.setfield("gpssec", cell_gpssec); | ||
map.setfield("gpsnsec", cell_gpsnsec); | ||
} | ||
retval(0) = map; | ||
|
||
return retval; | ||
} |