rtl433
UNKNOWN
RTL-433 utility
|
Pulse detection functions. More...
Data Structures | |
struct | pulse_FSK_state_t |
Internal state data for pulse_FSK_detect() More... | |
struct | pulse_detect |
Internal state data for pulse_pulse_package() More... | |
struct | hist_bin_t |
Histogram data for single bin. More... | |
struct | histogram_t |
Histogram data for all bins. More... | |
Functions | |
void | pulse_data_clear (pulse_data_t *data) |
Clear the content of a pulse_data_t structure. More... | |
void | pulse_data_print (pulse_data_t const *data) |
Print the content of a pulse_data_t structure (for debug). More... | |
static void * | bounded_memset (void *b, int c, int64_t size, int64_t offset, int64_t len) |
void | pulse_data_dump_raw (uint8_t *buf, unsigned len, uint64_t buf_offset, pulse_data_t const *data, uint8_t bits) |
Dump the content of a pulse_data_t structure as raw binary. More... | |
void | pulse_data_print_vcd_header (FILE *file, uint32_t sample_rate) |
Print a header for the VCD format. More... | |
void | pulse_data_print_vcd (FILE *file, pulse_data_t const *data, int ch_id) |
Print the content of a pulse_data_t structure in VCD format. More... | |
void | pulse_data_load (FILE *file, pulse_data_t *data) |
Read the next pulse_data_t structure from OOK text. More... | |
void | pulse_data_print_pulse_header (FILE *file) |
Print a header for the OOK text format. More... | |
void | pulse_data_dump (FILE *file, pulse_data_t *data) |
Print the content of a pulse_data_t structure as OOK text. More... | |
void | pulse_FSK_detect (int16_t fm_n, pulse_data_t *fsk_pulses, pulse_FSK_state_t *s) |
Demodulate Frequency Shift Keying (FSK) sample by sample. More... | |
void | pulse_FSK_wrap_up (pulse_data_t *fsk_pulses, pulse_FSK_state_t *s) |
Wrap up FSK modulation and store last data at End Of Package. More... | |
pulse_detect_t * | pulse_detect_create () |
void | pulse_detect_free (pulse_detect_t *pulse_detect) |
int | pulse_detect_package (pulse_detect_t *pulse_detect, int16_t const *envelope_data, int16_t const *fm_data, int len, int16_t level_limit, uint32_t samp_rate, uint64_t sample_offset, pulse_data_t *pulses, pulse_data_t *fsk_pulses) |
Demodulate On/Off Keying (OOK) and Frequency Shift Keying (FSK) from an envelope signal. More... | |
void | histogram_sum (histogram_t *hist, int const *data, unsigned len, float tolerance) |
Generate a histogram (unsorted) More... | |
void | histogram_delete_bin (histogram_t *hist, unsigned index) |
Delete bin from histogram. More... | |
void | histogram_swap_bins (histogram_t *hist, unsigned index1, unsigned index2) |
Swap two bins in histogram. More... | |
void | histogram_sort_mean (histogram_t *hist) |
Sort histogram with mean value (order lowest to highest) More... | |
void | histogram_sort_count (histogram_t *hist) |
Sort histogram with count value (order lowest to highest) More... | |
void | histogram_fuse_bins (histogram_t *hist, float tolerance) |
Fuse histogram bins with means within tolerance. More... | |
void | histogram_print (histogram_t const *hist, uint32_t samp_rate) |
Print a histogram. More... | |
void | pulse_analyzer (pulse_data_t *data, int package_type) |
Analyze the statistics of a pulse data structure and print result. More... | |
Pulse detection functions.
Copyright (C) 2015 Tommy Vestermark
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
Referenced by pulse_data_dump_raw().
void histogram_delete_bin | ( | histogram_t * | hist, |
unsigned | index | ||
) |
Delete bin from histogram.
References histogram_t::bins, and histogram_t::bins_count.
Referenced by histogram_fuse_bins(), and pulse_analyzer().
void histogram_fuse_bins | ( | histogram_t * | hist, |
float | tolerance | ||
) |
Fuse histogram bins with means within tolerance.
References histogram_t::bins, histogram_t::bins_count, hist_bin_t::count, histogram_delete_bin(), hist_bin_t::max, hist_bin_t::mean, hist_bin_t::min, and hist_bin_t::sum.
Referenced by pulse_analyzer().
void histogram_print | ( | histogram_t const * | hist, |
uint32_t | samp_rate | ||
) |
Print a histogram.
References histogram_t::bins, histogram_t::bins_count, hist_bin_t::count, hist_bin_t::max, hist_bin_t::mean, and hist_bin_t::min.
Referenced by pulse_analyzer().
void histogram_sort_count | ( | histogram_t * | hist | ) |
Sort histogram with count value (order lowest to highest)
References histogram_t::bins, histogram_t::bins_count, hist_bin_t::count, and histogram_swap_bins().
Referenced by pulse_analyzer().
void histogram_sort_mean | ( | histogram_t * | hist | ) |
Sort histogram with mean value (order lowest to highest)
References histogram_t::bins, histogram_t::bins_count, histogram_swap_bins(), and hist_bin_t::mean.
Referenced by pulse_analyzer().
void histogram_sum | ( | histogram_t * | hist, |
int const * | data, | ||
unsigned | len, | ||
float | tolerance | ||
) |
Generate a histogram (unsorted)
References histogram_t::bins, histogram_t::bins_count, hist_bin_t::count, hist_bin_t::max, hist_bin_t::mean, hist_bin_t::min, and hist_bin_t::sum.
Referenced by pulse_analyzer().
void histogram_swap_bins | ( | histogram_t * | hist, |
unsigned | index1, | ||
unsigned | index2 | ||
) |
Swap two bins in histogram.
References histogram_t::bins.
Referenced by histogram_sort_count(), and histogram_sort_mean().
void pulse_analyzer | ( | pulse_data_t * | data, |
int | package_type | ||
) |
Analyze the statistics of a pulse data structure and print result.
Analyze and print result.
References histogram_t::bins, histogram_t::bins_count, pulse_data::fsk_f1_est, pulse_data::fsk_f2_est, FSK_PULSE_PCM, FSK_PULSE_PWM, pulse_data::gap, histogram_delete_bin(), histogram_fuse_bins(), histogram_print(), histogram_sort_count(), histogram_sort_mean(), histogram_sum(), hist_bin_t::max, hist_bin_t::mean, r_device::modulation, r_device::name, pulse_data::noise_db, pulse_data::num_pulses, pulse_data::ook_high_estimate, pulse_data::ook_low_estimate, OOK_PULSE_MANCHESTER_ZEROBIT, OOK_PULSE_PPM, OOK_PULSE_PWM, pulse_data::pulse, PULSE_DATA_FSK, pulse_demod_manchester_zerobit(), pulse_demod_pcm(), pulse_demod_ppm(), pulse_demod_pwm(), pulse_data::rssi_db, r_device::s_gap_limit, r_device::s_long_width, r_device::s_reset_limit, r_device::s_short_width, r_device::s_sync_width, r_device::s_tolerance, pulse_data::sample_rate, and pulse_data::snr_db.
Referenced by sdr_callback().
void pulse_data_clear | ( | pulse_data_t * | data | ) |
Clear the content of a pulse_data_t structure.
Referenced by pulse_data_load(), and pulse_detect_package().
void pulse_data_dump | ( | FILE * | file, |
pulse_data_t * | data | ||
) |
Print the content of a pulse_data_t structure as OOK text.
References pulse_data::freq1_hz, pulse_data::freq2_hz, pulse_data::fsk_f2_est, pulse_data::gap, pulse_data::num_pulses, pulse_data::pulse, and pulse_data::sample_rate.
Referenced by sdr_callback().
void pulse_data_dump_raw | ( | uint8_t * | buf, |
unsigned | len, | ||
uint64_t | buf_offset, | ||
pulse_data_t const * | data, | ||
uint8_t | bits | ||
) |
Dump the content of a pulse_data_t structure as raw binary.
References bounded_memset(), pulse_data::gap, pulse_data::num_pulses, pulse_data::offset, and pulse_data::pulse.
Referenced by sdr_callback().
void pulse_data_load | ( | FILE * | file, |
pulse_data_t * | data | ||
) |
Read the next pulse_data_t structure from OOK text.
References pulse_data::freq1_hz, pulse_data::freq2_hz, pulse_data::gap, pulse_data::num_pulses, pulse_data::pulse, pulse_data_clear(), and pulse_data::sample_rate.
Referenced by main().
void pulse_data_print | ( | pulse_data_t const * | data | ) |
Print the content of a pulse_data_t structure (for debug).
References pulse_data::gap, pulse_data::num_pulses, and pulse_data::pulse.
Referenced by sdr_callback().
void pulse_data_print_pulse_header | ( | FILE * | file | ) |
void pulse_data_print_vcd | ( | FILE * | file, |
pulse_data_t const * | data, | ||
int | ch_id | ||
) |
Print the content of a pulse_data_t structure in VCD format.
References pulse_data::gap, pulse_data::num_pulses, pulse_data::offset, pulse_data::pulse, and pulse_data::sample_rate.
Referenced by sdr_callback().
void pulse_data_print_vcd_header | ( | FILE * | file, |
uint32_t | sample_rate | ||
) |
Print a header for the VCD format.
References format_time_str(), and nice_freq().
Referenced by add_dumper().
pulse_detect_t* pulse_detect_create | ( | void | ) |
Referenced by main().
void pulse_detect_free | ( | pulse_detect_t * | pulse_detect | ) |
Referenced by r_free_cfg().
int pulse_detect_package | ( | pulse_detect_t * | pulse_detect, |
int16_t const * | envelope_data, | ||
int16_t const * | fm_data, | ||
int | len, | ||
int16_t | level_limit, | ||
uint32_t | samp_rate, | ||
uint64_t | sample_offset, | ||
pulse_data_t * | pulses, | ||
pulse_data_t * | fsk_pulses | ||
) |
Demodulate On/Off Keying (OOK) and Frequency Shift Keying (FSK) from an envelope signal.
Function is stateful and can be called with chunks of input data.
envelope_data | Samples with amplitude envelope of carrier | |
fm_data | Samples with frequency offset from center frequency | |
len | Number of samples in input buffers | |
samp_rate | Sample rate in samples per second | |
[in,out] | pulses | Will return a pulse_data_t structure |
[in,out] | fsk_pulses | Will return a pulse_data_t structure for FSK demodulated data |
References pulse_detect::data_counter, pulse_data::end_ago, pulse_FSK_state_t::fm_f1_est, pulse_FSK_state_t::fm_f2_est, pulse_data::fsk_f1_est, pulse_data::fsk_f2_est, pulse_detect::FSK_state, pulse_data::gap, pulse_detect::lead_in_counter, pulse_detect::max_pulse, pulse_data::num_pulses, pulse_data::offset, pulse_data::ook_high_estimate, pulse_detect::ook_high_estimate, pulse_data::ook_low_estimate, pulse_detect::ook_low_estimate, pulse_detect::ook_state, pulse_data::pulse, pulse_data_clear(), PULSE_DATA_FSK, PULSE_DATA_OOK, pulse_FSK_detect(), pulse_FSK_wrap_up(), pulse_detect::pulse_length, pulse_data::sample_rate, and pulse_data::start_ago.
Referenced by sdr_callback().
void pulse_FSK_detect | ( | int16_t | fm_n, |
pulse_data_t * | fsk_pulses, | ||
pulse_FSK_state_t * | s | ||
) |
Demodulate Frequency Shift Keying (FSK) sample by sample.
Function is stateful between calls Builds estimate for initial frequency. When frequency deviates more than a threshold value it will determine whether the deviation is positive or negative to classify it as a pulse or gap. It will then transition to other state (F1 or F2) and build an estimate of the other frequency. It will then transition back and forth when current frequency is closer to other frequency estimate. Includes spurious suppression by coalescing pulses when pulse/gap widths are too short. Pulses equal higher frequency (F1) and Gaps equal lower frequency (F2)
fm_n | One single sample of FM data |
*fsk_pulses | Will return a pulse_data_t structure for FSK demodulated data |
*s | Internal state |
References pulse_FSK_state_t::fm_f1_est, pulse_FSK_state_t::fm_f2_est, pulse_FSK_state_t::fsk_pulse_length, pulse_FSK_state_t::fsk_state, pulse_data::gap, pulse_data::num_pulses, and pulse_data::pulse.
Referenced by pulse_detect_package().
void pulse_FSK_wrap_up | ( | pulse_data_t * | fsk_pulses, |
pulse_FSK_state_t * | s | ||
) |
Wrap up FSK modulation and store last data at End Of Package.
fm_n | One single sample of FM data |
*fsk_pulses | Pulse_data_t structure for FSK demodulated data |
*s | Internal state |
References pulse_FSK_state_t::fsk_pulse_length, pulse_FSK_state_t::fsk_state, pulse_data::gap, pulse_data::num_pulses, and pulse_data::pulse.
Referenced by pulse_detect_package().