{"id":13577763,"url":"https://github.com/ha7ilm/csdr","last_synced_at":"2026-03-15T03:31:39.470Z","repository":{"id":22706248,"uuid":"26050322","full_name":"ha7ilm/csdr","owner":"ha7ilm","description":"A simple DSP library and command-line tool for Software Defined Radio.","archived":false,"fork":false,"pushed_at":"2024-02-06T12:13:28.000Z","size":625,"stargazers_count":534,"open_issues_count":41,"forks_count":172,"subscribers_count":62,"default_branch":"master","last_synced_at":"2025-03-28T17:11:25.495Z","etag":null,"topics":["dsp","sdr"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"porn/gitconfig","license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ha7ilm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-11-01T12:43:04.000Z","updated_at":"2025-03-25T07:29:30.000Z","dependencies_parsed_at":"2024-11-05T15:35:10.170Z","dependency_job_id":"35d3820e-3c9e-46ae-b995-fccb2bca9adc","html_url":"https://github.com/ha7ilm/csdr","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ha7ilm%2Fcsdr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ha7ilm%2Fcsdr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ha7ilm%2Fcsdr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ha7ilm%2Fcsdr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ha7ilm","download_url":"https://codeload.github.com/ha7ilm/csdr/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247226215,"owners_count":20904465,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dsp","sdr"],"created_at":"2024-08-01T15:01:24.152Z","updated_at":"2025-12-18T09:21:18.118Z","avatar_url":"https://github.com/ha7ilm.png","language":"C","funding_links":[],"categories":["C","Software"],"sub_categories":["Libraries"],"readme":"CSDR\n====\n\n`csdr` is a command line tool to carry out DSP tasks for Software Defined Radio.\n\nIt can be used to build simple signal processing flow graphs, right from the command line. \n\nThe included `libcsdr` library contains the DSP functions that `csdr` makes use of. It was designed to use auto-vectorization available in `gcc`, and also has some functions optimized with inline assembly for ARM NEON to achieve some speedup by taking advantage of SIMD command sets available in today's CPUs.\n\nFeel free to use it in your projects.  \nMost of the code is available under the permissive BSD license, with some optional parts under GPL. For additional details, see \u003ca href=\"#licensing\"\u003elicensing\u003c/a\u003e.\n\n`csdr` has already been used to build:\n\n- AM, FM, SSB, CW and BPSK31 demodulators and waterfall display in [OpenWebRX](https://github.com/simonyiszk/openwebrx),\n- AM, FM, SSB modulators in [qtcsdr](https://github.com/ha7ilm/qtcsdr) that can also be used standalone with [rpitx](https://github.com/ha7ilm/rpitx-app-note),\n- a demodulator for FSK transmissions sent with the CC1111 wireless MCU, and also a standalone RTTY demodulator. \n\nThis animation shows the Gardner timing recovery algorithm in `csdr` locking on a baseband BPSK signal:\n\n![Gardner](https://raw.githubusercontent.com/wiki/simonyiszk/csdr/gardner.gif)\n\n(The symbol is sampled at the left red dot. The algorithm moves the middle dot as close to the symbol transition center, as possible.)\n\nHow to compile\n--------------\n\n    make\n    sudo make install\n\nThe project was only tested on Linux. It has the following dependencies: `libfftw3-dev`\n\nIf you compile on ARM, please edit the Makefile and tailor `PARAMS_NEON` for your CPU.\n\nTo run the examples, you will also need \u003ca href=\"http://sdr.osmocom.org/trac/wiki/rtl-sdr\"\u003ertl_sdr\u003c/a\u003e from Osmocom, and the following packages (at least on Debian): `mplayer octave gnuplot gnuplot-x11`\n\nIf you compile `fftw3` from sources for use with `libcsdr`, you need to configure it with 32-bit float support enabled: \n\n    ./configure --enable-float\n\n(This is for `fftw3`, not `libcsdr`. You do not need to run the configure script before compiling `libcsdr`.)\n\nCredits\n-------\nThe library was written by Andras Retzler, HA7ILM \u0026lt;\u003crandras@sdr.hu\u003e\u0026gt;.\n\nI would like to say special thanks to Péter Horváth, PhD (HA5CQA) and János Selmeczi, PhD (HA5FT) for their continous help and support.\n\nUsage by example\n----------------\n\n### Demodulate WFM\n\n    rtl_sdr -s 240000 -f 89500000 -g 20 - | csdr convert_u8_f | csdr fmdemod_quadri_cf | csdr fractional_decimator_ff 5 | csdr deemphasis_wfm_ff 48000 50e-6 | csdr convert_f_s16 | mplayer -cache 1024 -quiet -rawaudio samplesize=2:channels=1:rate=48000 -demuxer rawaudio -\n\n- Baseband I/Q signal is coming from an RTL-SDR USB dongle, with a center frequency of `-f 104300000` Hz, a sampling rate of `-s 240000` samples per second.\n- The `rtl_sdr` tool outputs an unsigned 8-bit I/Q signal (one byte of I sample and one byte of Q coming after each other), but `libcsdr` DSP routines internally use floating point data type, so we convert the data stream of `unsigned char` to `float` by `csdr convert_u8_f`.\n- We want to listen one radio station at the frequency `-f 89500000` Hz (89.5 MHz).\n- No other radio station is within the sampled bandwidth, so we send the signal directly to the demodulator. (This is an easy, but not perfect solution as the anti-aliasing filter at RTL-SDR DDC is too short.)\n- After FM demodulation we decimate the signal by a factor of 5 to match the rate of the audio card (240000 / 5 = 48000).\n- A de-emphasis filter is used, because pre-emphasis is applied at the transmitter to compensate noise at higher frequencies. The time constant for de-emphasis for FM broadcasting in Europe is 50 microseconds (hence the `50e-6`).\n- Also, `mplayer` cannot play floating point audio, so we convert our signal to a stream of 16-bit integers.  \n\n### Demodulate WFM: advanced\n\n    rtl_sdr -s 2400000 -f 89300000 -g 20 - | csdr convert_u8_f | csdr shift_addition_cc -0.085 | csdr fir_decimate_cc 10 0.05 HAMMING | csdr fmdemod_quadri_cf | csdr fractional_decimator_ff 5 | csdr deemphasis_wfm_ff 48000 50e-6 | csdr convert_f_s16 | mplayer -cache 1024 -quiet -rawaudio samplesize=2:channels=1:rate=48000 -demuxer rawaudio -\n\n- We want to listen to one radio station, but input signal contains multiple stations, and its bandwidth is too large for sending it directly to the FM demodulator.\n- We shift the signal to the center frequency of the station we want to receive: `-0.085*2400000 = -204000`, so basically we will listen to the radio station centered at 89504000 Hz.\n- We decimate the signal by a factor of 10. The transition bandwidth of the FIR filter used for decimation will be 10% of total bandwidth (as of parameter 0.05 is 10% of 0.5). Hamming window will be used for windowed FIR filter design.\n\nSample rates look like this:\n\n\n                 2.4 Msps                     240 ksps                                  48 ksps\n    I/Q source ------------\u003e FIR decimation ------------\u003e FM demod -\u003e frac. decimation ---------\u003e deemphasis -\u003e sound card\n\n\n*Note:* there is an example shell script that does this for you (without the unnecessary shift operation). If you just want to listen to FM radio, type:\n\n    csdr-fm 89.5 20\n\nThe first parameter is the frequency in MHz, and the second optional parameter is the RTL-SDR tuner gain in dB.\n\n### Demodulate NFM\n\n    rtl_sdr -s 2400000 -f 145000000 -g 20 - | csdr convert_u8_f | csdr shift_addition_cc `python -c \"print float(145000000-145350000)/2400000\"` | csdr fir_decimate_cc 50 0.005 HAMMING | csdr fmdemod_quadri_cf | csdr limit_ff | csdr deemphasis_nfm_ff 48000 | csdr fastagc_ff | csdr convert_f_s16 | mplayer -cache 1024 -quiet -rawaudio samplesize=2:channels=1:rate=48000 -demuxer rawaudio -\n\n- Note that the decimation factor is higher (we want to select a ~25 kHz channel).\n- Also there is a python hack to calculate the relative shift offset. The real receiver frequency is `145350000` Hz.\n- The de-emphasis filter is a fixed FIR filter that has a passband of 400-4000 Hz, also with a roll-off of -20 dB/decade.\n\n### Demodulate AM\n\n    rtl_sdr -s 2400000 -f 145000000 -g 20 - | csdr convert_u8_f | csdr shift_addition_cc `python -c \"print float(145000000-144400000)/2400000\"` | csdr fir_decimate_cc 50 0.005 HAMMING | csdr amdemod_cf | csdr fastdcblock_ff | csdr agc_ff | csdr limit_ff | csdr convert_f_s16 | mplayer -cache 1024 -quiet -rawaudio samplesize=2:channels=1:rate=48000 -demuxer rawaudio -\n\n- `amdemod_cf` is used as demodulator.\n- `agc_ff` should be used for AM and SSB.\n\n### Design FIR band-pass filter (with complex taps)\n\n    csdr firdes_bandpass_c 0 0.5 59 HAMMING --octave | octave -i\n\n- ...and then plot its frequency response with octave. (You can close octave window by issuing Ctrl-C in the terminal window.)\n- It will design a filter that lets only the positive frequencies pass (low cut is 0, high cut is 0.5 - these are relative to the sampling rate).\n- If `--octave` and everything that follows is removed from the command, you get only the taps. E. g. the raw output of `firdes_lowpass_f` can be easily copied to C code.\n\n### Demodulate SSB\n\n    rtl_sdr -s 2400000 -f 145000000 -g 20 - | csdr convert_u8_f | csdr shift_addition_cc `python -c \"print float(145000000-144400000)/2400000\"` | csdr fir_decimate_cc 50 0.005 HAMMING | csdr bandpass_fir_fft_cc 0 0.1 0.05 | csdr realpart_cf | csdr agc_ff | csdr limit_ff | csdr convert_f_s16 | mplayer -cache 1024 -quiet -rawaudio samplesize=2:channels=1:rate=48000 -demuxer rawaudio -\n\n- It is a modified Weaver-demodulator. The complex FIR filter removes the lower sideband and lets only the upper pass (USB). If you want to demodulate LSB, change `bandpass_fir_fft_cc 0 0.1` to `bandpass_fir_fft_cc -0.1 0`.\n\n### Draw FFT\n\n    rtl_sdr -s 2400000 -f 104300000 -g 20 - | csdr convert_u8_f | csdr fft_cc 1024 1200000 HAMMING --octave | octave -i \u003e /dev/null\n\n- We calculate the Fast Fourier Transform by `csdr fft_cc` on the first 1024 samples of every block of 1200000 complex samples coming after each other. (We calculate FFT from 1024 samples and then skip 1200000-1024=1198976 samples. This way we will calculate FFT two times every second.)\n- The window used for FFT is the Hamming window, and the output consists of commands that can be directly interpreted by GNU Octave which plots us the spectrum.\n\nUsage\n-----\nSome basic concepts on using *libcsdr*:\n\n### Data types\nFunction name endings found in *libcsdr* mean the input and output data types of the particular function. (This is similar to GNU Radio naming conventions).\nData types are noted as it follows:\n\n- `f` is `float` (single percision)\n- `c` is `complexf` (two single precision floating point values in a struct)\n- `u8` is `unsigned char` of 1 byte/8 bits (e. g. the output of `rtl_sdr` is of `u8`)\n- `s16` is `signed short` of 2 bytes/16 bits (e. g. sound card input is usually `s16`)\n\nFunctions usually end as:\n\n- `_ff` float input, float output\n- `_cf` complex input, float output\n- `_cc` complex input, complex output\n\nRegarding *csdr*, it can convert a real/complex stream from one data format to another, to interface it with other SDR tools and the sound card.\nThe following commands are available:\n\n- `csdr convert_u8_f`\n- `csdr convert_f_u8`\n- `csdr convert_s8_f`\n- `csdr convert_f_s8`\n- `csdr convert_s16_f`\n- `csdr convert_f_s16`\n- `csdr convert_s24_f [--bigendian]`\n- `csdr convert_f_s24 [--bigendian]`\n\nHow to interpret: `csdr convert_\u003csrc\u003e_\u003cdst\u003e`\nYou can use these commands on complex streams, too, as they are only interleaved values (I,Q,I,Q,I,Q... coming after each other).\n\n\u003e Note: The the functions with `i16` in their names have been renamed, but still work (e.g. `csdr convert_f_i16`).\n\n\n### csdr commands\n\n`csdr` should be considered as a reference implementation on using `libcsdr`. For additional details on how to use the library, check `csdr.c` and `libcsdr.c`.\n\nRegarding `csdr`, the first command-line parameter is the name of a function, others are the parameters for the given function. Compulsory parameters are noted as `\u003cparameter\u003e`, optional parameters are noted as `[parameter]`.\nOptional parameters have safe defaults, for more info look at the code.\n\n----\n\n### [realpart_cf](#realpart_cf)\n\nSyntax:\n\n    csdr realpart_cf\n\nIt takes the real part of the complex signal, and throws away the imaginary part.\n\n----\n\n### [clipdetect_ff](#clipdetect_ff)\n\nSyntax:\n\n    csdr clipdetect_ff\n\nIt clones the signal (the input and the output is the same), but it prints a warning on `stderr` if any sample value is out of the -1.0 ... 1.0 range.\n\n----\n\n### [limit_ff](#limit_ff)\n\nSyntax:\n\n    csdr limit_ff [max_amplitude]\n\nThe input signal amplitude will not be let out of the `-max_amplitude ... max_amplitude` range.\n\n----\n\n### [gain_ff](#gain_ff)\n\nSyntax:\n\n    csdr gain_ff \u003cgain\u003e\n\nIt multiplies all samples by `gain`.\n\n----\n\n### [clone](#clone)\n\nSyntax:\n\n    csdr clone\n\nIt copies the input to the output.\n\n----\n\n### [through](#through)\n\nSyntax:\n\n    csdr through\n\nIt copies the input to the output, while also displaying the data rate going through it.\n\n----\n\n### [none](#none)\n\nSyntax:\n\n    csdr none\n\nThe `csdr` process just exits with 0.\n\n----\n\n### [yes_f](#yes_f)\n\nSyntax:\n\n    csdr yes_f \u003cto_repeat\u003e [buf_times]\n\nIt outputs continously the `to_repeat` float number.\n\nIf `buf_times` is not given, it never stops.\n\nElse, after outputing `buf_times` number of buffers (the size of which is stated in the `BUFSIZE` macro), it exits.\n\n----\n\n### [detect_nan_ff](#detect_nan_ff)\n\nSyntax:\n\n    csdr detect_nan_ff\n\nAlong with copying its input samples to the output, it prints a warning message to *stderr* if it finds any IEEE floating point NaN values among the samples.\n\n----\n\n### [dump_f](#dump_f)\n\nSyntax:\n\n    csdr dump_f\n\nIt prints all floating point input samples as text.\n\nThe C format string used is `\"%g \"`.\n\nYou can also use it to print complex float values, then you will see the I and Q samples interleaved, like: `I Q I Q I Q ...`\n\nAlternatively, you can use the `od` command (built into most Linux distributions). To display a list of floating point values with their addresses as well, you can use: `od -vf`\n\nAliases for this function: `floatdump_f`\n\n----\n\n### [dump_u8](#dump_u8)\n\nSyntax:\n\n    csdr dump_u8\n\nIt prints all input bytes as text, in hexadecimal form. \n\nAlternatively, you can use the `xxd` command (built into most Linux distributions). To display a hexadecimal dump of the standard input (with addresses at the beginning of rows), you can use: `xxd -g1`\n\n----\n\n### [flowcontrol](#flowcontrol)\n\nSyntax:\n\n    csdr flowcontrol \u003cdata_rate\u003e \u003creads_per_second\u003e\n\nIt limits the data rate of a stream to a given `data_rate` number of bytes per second.\n\nIt copies `data_rate / reads_per_second` bytes from the input to the output, doing it `reads_per_second` times every second.\n\n----\n\n### [shift_math_cc](#shift_math_cc)\n\nSyntax:\n\n    csdr shift_math_cc \u003crate\u003e\n\nIt shifts the signal in the frequency domain by `rate`.\n\n`rate` is a floating point number between -0.5 and 0.5.\n\n`rate` is relative to the sampling rate.\n\nInternally, a sine and cosine wave is generated, and this function uses `math.h` for this purpose, which is quite accurate, but not always very fast.\n\n----\n\n### [shift_addition_cc](#shift_addition_cc)\n\nSyntax:\n\n    csdr shift_addition_cc \u003crate\u003e\n\nOperation is the same as for `shift_math_cc`.\n\nInternally, this function uses trigonometric addition formulas to generate sine and cosine, which is a bit faster. (About 4 times on the machine I have tested it on.)\n\n----\n\n### [shift_addition_cc_test](#shift_addition_cc_test)\n\nSyntax: \n\n    csdr shift_addition_cc_test\n\nThis function was used to test the accuracy of the method above.\n\n----\n\n### [shift_table_cc](#shift_table_cc)\n\nSyntax: \n\n    csdr shift_table_cc \u003crate\u003e [table_size]\n\nOperation is the same as with `shift_math_cc`.\n\nInternally, this function uses a look-up table (LUT) to recall the values of the sine function (for the first quadrant).\n\nThe higher the table size is, the smaller the phase error is.\n\n----\n\n### [shift_addfast_cc](#shift_addfast_cc)\n\nSyntax: \n\n    csdr shift_addfast_cc \u003crate\u003e\n\nOperation is the same as for `shift_math_cc`.\n\nInternally, this function uses a NEON-accelerated algorithm on capable systems, so it is advised to use this one on ARM boards.\n\n----\n\n### [shift_unroll_cc](#shift_unroll_cc)\n\nSyntax: \n\n    csdr shift_unroll_cc \u003crate\u003e\n\nOperation is the same as for `shift_math_cc`.\n\nThis uses a modified algoritm that first stores a vector of sine and cosine values for given phase differences.\n\nThe loop in this function unrolls quite well if compiled on a PC. It was the fastest one on an i7 CPU during the tests.\n\n----\n\n### [decimating_shift_addition_cc](#decimating_shift_addition_cc)\n\nSyntax: \n\n    csdr decimating_shift_addition_cc \u003crate\u003e [decimation]\n\nIt shifts the input signal in the frequency domain, and also decimates it, without filtering. It will be useful as a part of the FFT channelizer implementation (to be done).\n\nIt cannot be used as a channelizer by itself, use `fir_decimate_cc` instead.\n\n----\n\n### [shift_addition_fc](#shift_addition_fc)\n\nSyntax:\n\n    csdr shift_addition_fc \u003crate\u003e\n\nIt converts the real input signal to complex, and then shifts it in the frequency domain by `rate`.\n\n----\n\n### [dcblock_ff](#dcblock_ff)\n\nSyntax: \n\n    csdr dcblock_ff\n\nThis is a DC blocking IIR filter.\n\n----\n\n### [fastdcblock_ff](#fastdcblock_ff)\n\nSyntax: \n\n    csdr fastdcblock_ff\n\nThis is a DC blocker that works based on the average of the buffer.\n\n----\n\n### [fmdemod_atan_cf](#fmdemod_atan_cf)\n\nSyntax: \n\n    csdr fmdemod_atan_cf\n\nIt is an FM demodulator that internally uses the `atan` function in `math.h`, so it is not so fast.\n\n----\n\n### [fmdemod_quadri_cf](#fmdemod_quadri_cf)\n\nSyntax: \n\n    csdr fmdemod_quadri_cf\n\nIt is an FM demodulator that is based on the quadri-correlator method, and it can be effectively auto-vectorized, so it should be faster.\n\n----\n\n### [fmdemod_quadri_novect_cf](#fmdemod_quadri_novect_cf)\n\nSyntax: \n\n    csdr fmdemod_quadri_novect_cf\n\nIt has more easily understandable code than the previous one, but can't be auto-vectorized.\n\n----\n\n### [deemphasis_wfm_ff](#deemphasis_wfm_ff)\n\nSyntax: \n\n    csdr deemphasis_wfm_ff \u003csample_rate\u003e \u003ctau\u003e\n\nIt does de-emphasis with the given RC time constant `tau`.\n\nDifferent parts of the world use different pre-emphasis filters for FM broadcasting.\n\nIn Europe, `tau` should be chosen as `50e-6`, and in the USA, `tau` should be `75e-6`.\n\n----\n\n### [deemphasis_nfm_ff](#deemphasis_nfm_ff)\n\nSyntax: \n\n    csdr deemphasis_nfm_ff \u003cone_of_the_predefined_sample_rates\u003e\n\nIt does de-emphasis on narrow-band FM for communication equipment (e.g. two-way radios).\n\nIt uses fixed filters so it works only on predefined sample rates, for the actual list of them run: \n\n    cat libcsdr.c | grep DNFMFF_ADD_ARRAY\n\n----\n\n### [amdemod_cf](#amdemod_cf)\n\nSyntax: \n\n    csdr amdemod_cf\n\nIt is an AM demodulator that uses `sqrt`. On some architectures `sqrt` can be directly calculated by dedicated CPU instructions, but on others it may be slower.\n\n----\n\n### [amdemod_estimator_cf](#amdemod_estimator_cf)\n\nSyntax: \n\n    csdr amdemod_estimator_cf\n\nIt is an AM demodulator that uses an estimation method that is faster but less accurate than `amdemod_cf`.\n\n----\n\n### [firdes_lowpass_f](#firdes_lowpass_f)\n\nSyntax: \n\n    csdr firdes_lowpass_f \u003ccutoff_rate\u003e \u003clength\u003e [window [--octave]]\n\nLow-pass FIR filter design function to output real taps, with a `cutoff_rate` proportional to the sampling frequency, using the windowed sinc filter design method.\n\n`cutoff_rate` can be between 0 and 0.5.\n\n`length` is the number of filter taps to output, and should be odd.\n\nThe longer the filter kernel is, the shorter the transition bandwidth is, but the more CPU time it takes to process the filter.\n\nThe transition bandwidth (proportional to the sampling rate) can be calculated as: `transition_bw = 4 / length`.\n\nSome functions (below) require the `transition_bw` to be given instead of filter `length`. Try to find the best compromise between speed and accuracy by changing this parameter.\n\n`window` is the window function used to compensate finite filter length. Its typical values are: `HAMMING`, `BLACKMAN`, `BOXCAR`. For the actual list of values, run: `cpp libcsdr.c | grep window\\ ==`\n\nThe `--octave` parameter lets you directly view the filter response in `octave`. For more information, look at the [Usage by example] section.\n\n----\n\n### [firdes_bandpass_c](#firdes_bandpass_c)\n\nSyntax: \n\n    csdr firdes_bandpass_c \u003clow_cut\u003e \u003chigh_cut\u003e \u003clength\u003e [window [--octave]]\n\nBand-pass FIR filter design function to output complex taps.\n\n`low_cut` and ` high_cut` both may be between -0.5 and 0.5, and are also proportional to the sampling frequency.\n\nOther parameters were explained above at `firdes_lowpass_f`.\n\n----\n\n### [fir_decimate_cc](#fir_decimate_cc)\n\nSyntax: \n\n    csdr fir_decimate_cc \u003cdecimation_factor\u003e [transition_bw [window]]\n\nIt is a decimator that keeps one sample out of `decimation_factor` samples.\n\nTo avoid aliasing, it runs a filter on the signal and removes spectral components above `0.5 × nyquist_frequency × decimation_factor` from the input signal.\n\n----\n\n### [fir_interpolate_cc](#fir_interpolate_cc)\n\nSyntax: \n\n    csdr fir_interpolate_cc \u003cinterpolation_factor\u003e [transition_bw [window]]\n\nIt is an interpolator that generates `interpolation_factor` number of output samples from one input sample.\n\nTo avoid aliasing, it runs a filter on the signal and removes spectral components above `0.5 × nyquist_frequency / interpolation_factor` from the output signal.\n\n`transition_bw` and `window` are the parameters of the filter.\n\n----\n\n### [rational_resampler_ff](#rational_resampler_ff)\n\nSyntax: \n\n    csdr rational_resampler_ff \u003cinterpolation\u003e \u003cdecimation\u003e [transition_bw [window]]\n\nIt is a resampler that takes integer values of `interpolation` and `decimation`.\nThe output sample rate will be `interpolation / decimation × input_sample_rate`.\n\n`transition_bw` and `window` are the parameters of the filter.\n\n----\n\n### [fractional_decimator_ff](#fractional_decimator_ff)\n\nSyntax: \n\n    csdr fractional_decimator_ff \u003cdecimation_rate\u003e [num_poly_points ( [transition_bw [window]] | --prefilter )]\n\nIt can decimate by a floating point ratio.\n\nIt uses Lagrance interpolation, where `num_poly_points` (12 by default) input samples are taken into consideration while calculating one output sample. \n\nIt can filter the signal with an anti-aliasing FIR filter before applying the Lagrange interpolation. This filter is inactive by default, but can be activated by:\n\n* passing only the `transition_bw`, or both the `transition_bw` and the `window` parameters of the filter,\n* using the `--prefilter` switch after `num_poly_points` to switch this filter on with the default parameters.\n\n----\n\n### [old_fractional_decimator_ff](#old_fractional_decimator_ff)\n\nSyntax: \n\n    csdr old_fractional_decimator_ff \u003cdecimation_rate\u003e [transition_bw [window]]\n\nThis is the deprecated, old algorithm to decimate by a floating point ratio, superseded by `fractional_decimator_ff`. \n\n(It uses linear interpolation, and its filter cuts at 59% of the passband.)\n\n----\n\n### [bandpass_fir_fft_cc](#bandpass_fir_fft_cc)\n\nSyntax: \n\n    csdr bandpass_fir_fft_cc \u003clow_cut\u003e \u003chigh_cut\u003e \u003ctransition_bw\u003e [window]\n\nIt performs a bandpass FIR filter on complex samples, using FFT and the overlap-add method.\n\nParameters are described under `firdes_bandpass_c` and `firdes_lowpass_f`.\n\n----\n\n### [agc_ff](#agc_ff)\n\nSyntax: \n\n    csdr agc_ff [hang_time [reference [attack_rate [decay_rate [max_gain [attack_wait [filter_alpha]]]]]]]\n\nIt is an automatic gain control function.\n\n- `hang_time` is the number of samples to wait before starting to increase the gain after a peak.\n- `reference` is the reference level for the AGC. It tries to keep the amplitude of the output signal close to that.\n- `attack_rate` is the rate of decreasing the signal level if it gets higher than it used to be before.\n- `decay_rate` is the rate of increasing the signal level if it gets lower than it used to be before.\n- AGC won't increase the gain over `max_gain`.\n- `attack_wait` is the number of sampels to wait before starting to decrease the gain, because sometimes very short peaks happen, and we don't want them to spoil the reception by substantially decreasing the gain of the AGC.\n- `filter_alpha` is the parameter of the loop filter.\n\nIts default parameters work best for an audio signal sampled at 48000 Hz.\n\n----\n\n### [fastagc_ff](#fastagc_ff)\n\nSyntax: \n\n    csdr fastagc_ff [block_size [reference]]\n\nIt is a faster AGC that linearly changes the gain, taking the highest amplitude peak in the buffer into consideration. Its output will never exceed `-reference ... reference`.\n\n----\n\n### [fft_cc](#fft_cc)\n\nSyntax: \n\n    csdr fft_cc \u003cfft_size\u003e \u003cout_of_every_n_samples\u003e [window [--octave] [--benchmark]]\n\nIt performs an FFT on the first `fft_size` samples out of `out_of_every_n_samples`, thus skipping `out_of_every_n_samples - fft_size` samples in the input.\n\nIt can draw the spectrum by using `--octave`, for more information, look at the [Usage by example] section.\n\nFFTW can be faster if we let it optimalize a while before starting the first transform, hence the `--benchmark` switch.\n\n----\n\n### [fft_fc](#fft_fc)\n\nSyntax:\n\n    csdr fft_fc \u003cfft_out_size\u003e \u003cout_of_every_n_samples\u003e [--benchmark]\n\nIt works similarly to \u003ca href=\"#fft_cc\"\u003efft_cc\u003c/a\u003e, but on real input samples. \n\nFor real FFT, the `fft_out_size` parameter is the number of output complex bins instead of the actual FFT size.\n\nNumber of input samples used for each FFT is `2 × fft_out_size`. This makes it easier to replace `fft_cc` by `fft_fc` in some applications.\n\n----\n\n### [fft_benchmark](#fft_benchmark)\n\nSyntax: \n\n    csdr fft_benchmark \u003cfft_size\u003e \u003cfft_cycles\u003e [--benchmark]\n\nIt measures the time taken to process `fft_cycles` transforms of `fft_size`.\nIt lets FFTW optimalize if used with the `--benchmark` switch.\n\n----\n\n### [logpower_cf](#logpower_cf)\n\nSyntax: \n\n    csdr logpower_cf [add_db]\n\nCalculates `10*log10(i^2+q^2)+add_db` for the input complex samples. It is useful for drawing power spectrum graphs.\n\n----\n\n### [encode_ima_adpcm_i16_u8](#encode_ima_adpcm_i16_u8)\n\nSyntax: \n\n    csdr csdr encode_ima_adpcm_i16_u8\n\nEncodes the audio stream to IMA ADPCM, which decreases the size to 25% of the original.\n\n----\n\n### [decode_ima_adpcm_u8_i16](#decode_ima_adpcm_u8_i16)\n\nSyntax: \n\n    csdr decode_ima_adpcm_u8_i16\n\nDecodes the audio stream from IMA ADPCM.\n\n----\n\n### [compress_fft_adpcm_f_u8](#compress_fft_adpcm_f_u8)\n\nSyntax: \n\n    csdr compress_fft_adpcm_f_u8 \u003cfft_size\u003e\n\nEncodes the FFT output vectors of `fft_size`. It should be used on the data output from `logpower_cf`.\n\nIt resets the ADPCM encoder at the beginning of every vector, and to compensate it, `COMPRESS_FFT_PAD_N` samples are added at beginning (these equal to the first relevant sample).\n\nThe actual number of padding samples can be determined by running:\n\n    cat csdr.c | grep \"define COMPRESS_FFT_PAD_N\"\n\n----\n\n### [fft_exchange_sides_ff](#fft_exchange_sides_ff)\n\nSyntax: \n\n    csdr fft_exchange_sides_ff \u003cfft_size\u003e\n\nIt exchanges the first and second part of the FFT vector, to prepare it for the waterfall/spectrum display. It should operate on the data output from `logpower_cf`.\n\n----\n\n### [dsb_fc](#dsb_fc)\n\nSyntax: \n\n    csdr dsb_fc [q_value]\n\nIt converts a real signal to a double sideband complex signal centered around DC.\n\nIt does so by generating a complex signal:\n* the real part of which is the input real signal,\n* the imaginary part of which is `q_value` (0 by default).\n\nWith `q_value = 0` it is an AM-DSB/SC modulator. If you want to get an AM-DSB signal, you will have to add a carrier to it.\n\n----\n\n### [add_dcoffset_cc](#add_dcoffset_cc)\n\nSyntax: \n\n    csdr add_dcoffset_cc\n\nIt adds a DC offset to the complex signal: `i_output = 0.5 + i_input / 2, q_output = q_input / 2`\n\n----\n\n### [convert_f_samplerf](#convert_f_samplerf)\n\nSyntax: \n\n    csdr convert_f_samplerf \u003cwait_for_this_sample\u003e\n\nIt converts a real signal to the `-mRF` input format of [https://github.com/F5OEO/rpitx](rpitx), so it allows you to generate frequency modulation. The input signal will be the modulating signal. The `\u003cwait_for_this_sample\u003e` parameter is the value for `rpitx` indicating the time to wait between samples. For a sampling rate of 48 ksps, this is 20833.\n\n----\n\n### [fmmod_fc](#fmmod_fc)\n\nSyntax: \n\n    csdr fmmod_fc\n\nIt generates a complex FM modulated output from a real input signal.\n\n----\n\n### [fixed_amplitude_cc](#fixed_amplitude_cc)\n\nSyntax: \n\n    csdr fixed_amplitude_cc \u003cnew_amplitude\u003e\n\nIt changes the amplitude of every complex input sample to a fixed value. It does not change the phase information of the samples.\n\n----\n\n### [mono2stereo_s16](#mono2stereo_s16)\n\nSyntax: \n\n    csdr mono2stereo_s16\n\nIt doubles every input sample. \n\nExample: if the input samples are 16 bit signed integers: \n\n    23 -452 3112\n\nThe output will be:\n\n    23 23 -452 -452 3112 3112\n\n----\n\n### [setbuf](#setbuf)\n\nSyntax: \n\n    csdr setbuf \u003cbuffer_size\u003e\n\nSee the [buffer sizes](#buffer_sizes) section.\n\n    squelch_and_smeter_cc --fifo \u003csquelch_fifo\u003e --outfifo \u003csmeter_fifo\u003e \u003cuse_every_nth\u003e \u003creport_every_nth\u003e\n\nThis is a controllable squelch, which reads the squelch level input from `\u003csquelch_fifo\u003e` and writes the power level output to `\u003csmeter_fifo\u003e`. Both input and output are in the format of `%g\\n`. While calculating the power level, it takes only every `\u003cuse_every_nth\u003e` sample into consideration. It writes the S-meter value for every `\u003creport_every_nth\u003e` buffer to `\u003csmeter_fifo\u003e`. If the squelch level is set to 0, it it forces the squelch to be open. If the squelch is closed, it fills the output with zero.\n\n----\n\n### [fifo](#fifo)\n\nSyntax: \n\n    csdr fifo \u003cbuffer_size\u003e \u003cnumber_of_buffers\u003e\n\nIt is similar to `clone`, but internally it uses a circular buffer. It reads as much as possible from the input. It discards input samples if the input buffer is full.\n\n----\n\n### [psk31_varicode_encoder_u8_u8](#psk31_varicode_encoder_u8_u8)\n\nSyntax: \n\n    csdr psk31_varicode_encoder_u8_u8\n\nIt encodes ASCII characters into varicode for PSK31 transmission. It puts a `00` sequence between the varicode characters (which acts as a separator). \n\nFor the Varicode character set, see: http://www.arrl.org/psk31-spec\n\nFor example, `aaa` means the bit sequence `101100101100101100`. \n\nFor this input, the output of `psk31_varicode_encoder_u8_u8` will be the following bytes (in hexadecimal):\n\n```\n01 00 01 01 00 00 01 00 \n01 01 00 00 01 00 01 01\n00 00\n```\n\n----\n\n### [repeat_u8](#repeat_u8)\n\nSyntax:\n\n    csdr repeat_u8 \u003cdata_bytes × N\u003e\n\nIt repeatedly outputs a set of data bytes (given with decimal numbers).\n\nFor example, `csdr repeat_u8 1 1 0 0` will output:\n\n```\n01 01 00 00 01 01 00 00 \n01 01 00 00 01 01 00 00\n```\n\n----\n\n### [uniform_noise_f](#uniform_noise_f)\n\nSyntax:\n\n    csdr uniform_noise_f\n\nIt outputs uniform white noise. All samples are within the range [-1.0, 1.0].\n\n----\n\n### [gaussian_noise_c](#gaussian_noise_c)\n\nSyntax:\n\n    csdr gaussian_noise_c\n\nIt outputs Gaussian white noise. All samples are within the unit circle.\n\n----\n\n### [pack_bits_8to1_u8_u8](#pack_bits_8to1_u8_u8)\n\nSyntax:\n\n    csdr pack_bits_8to1_u8_u8 \n\nTODO \n\n----\n\n### [pack_bits_1to8_u8_u8](#pack_bits_1to8_u8_u8)\n\nSyntax:\n\n    csdr pack_bits_1to8_u8_u8 \n\nIt serializes the bytes on the input: it outputs each bit of the input byte as a single byte valued 0x00 or 0x01, starting from the lowest bit and going to the highest bit.\n\nThe output is 8 times as large in size as the input. \n\nFor example, the input byte 0x43 will result in eight bytes at the output:\n\n```\n01 01 00 00 00 00 01 00 \n```\n\nFor consequtive 0x02, 0x03, 0xff bytes on the input, the output will be:\n\n```\n00 01 00 00 00 00 00 00 \n01 01 00 00 00 00 00 00 \n01 01 01 01 01 01 01 01 \n```\n\n----\n\n### [awgn_cc](#awgn_cc)\n\nSyntax:\n\n    csdr awgn_cc \u003csnr_db\u003e [--snrshow]\n\nIt adds white noise with the given SNR to a signal assumed to be of 0 dB power.\n\nIf the `--snrshow` switch is given, it also shows the actual SNR based on the calculated power of signal and noise components.\n\n----\n\n### [add_n_zero_samples_at_beginning_f](#add_n_zero_samples_at_beginning_f)\n\nSyntax:\n\n    csdr add_n_zero_samples_at_beginning_f \u003cn_zero_samples\u003e \n\nWhen the function is executed, it furst writes `\u003cn_zero_samples\u003e` 32-bit floating point zeros at the output, after that it just clones the input at the output. \n\n----\n\n### [fft_one_side_ff](#fft_one_side_ff)\n\nSyntax:\n\n    csdr fft_one_side_ff \u003cfft_size\u003e\n\nIf the frequency domain signal spans between frequencies -fs/2 to fs/2, this function removes the part from -fs/2 to DC. This can be useful if the FFT of a real signal has been taken (so that the spectrum is mirrored to DC).  \n\n----\n\n### [logaveragepower_cf](#logaveragepower_cf)\n\nSyntax:\n\n    csdr logaveragepower_cf \u003cadd_db\u003e \u003cfft_size\u003e \u003cavgnumber\u003e\n\nIt works like \u003ca href=\"#logpower_cf\"\u003elogpower_cf \u003c/a\u003e, but it calculates the average of every `avgnumber` FFTs. \n\n----\n\n### [mono2stereo_s16](#mono2stereo_s16)\n\nSyntax:\n\n    csdr mono2stereo_s16\n\nIt duplicates each 16-bit integer input sample.\n\n----\n\n### [psk31_varicode_decoder_u8_u8](#psk31_varicode_decoder_u8_u8)\n\nSyntax:\n\n    csdr psk31_varicode_decoder_u8_u8\n\nIt expects symbols encoded as 0x00 and 0x01 bytes on the input, and extracts Varicode characters from them.  \n\n----\n\n### [_fft2octave](#_fft2octave)\n\nSyntax:\n\n    csdr _fft2octave \u003cfft_size\u003e\n\nIt is used for plotting FFT data with a GNU Octave session, piping its output to `octave -i`.\n\n----\n\n### [invert_u8_u8](#invert_u8_u8)\n\nSyntax:\n\n    csdr invert_u8_u8\n\nIt maps\n\n* each 0x00 to 0x01,\n* each 0x01 to 0x00.\n\n----\n\n### [rtty_baudot2ascii_u8_u8](#rtty_baudot2ascii_u8_u8)\n\nSyntax:\n\n    csdr rtty_baudot2ascii_u8_u8\n\nThis function awaits baudot code characters on its input (ranging from 0b00000000 to 0b00011111), and converts them into ASCII characters. It has an internal state to switch between letters and figures. \n\n----\n\n### [binary_slicer_f_u8](#binary_slicer_f_u8)\n\nSyntax:\n\n    csdr binary_slicer_f_u8\n\n* If the input sample is below or equals to 0.0, it outputs a 0x00.\n* If the input sample is above 0.0, it outputs a 0x01.\n\n----\n\n### [serial_line_decoder_f_u8](#serial_line_decoder_f_u8)\n\nSyntax:\n\n    csdr serial_line_decoder_f_u8 \u003csamples_per_bits\u003e [databits [stopbits]]\n\nIt decodes bits from a sampled serial line. It does so by finding the appropriate start and stop bits, and extracts the data bits in between.\n\n----\n\n### [pll_cc](#pll_cc)\n\nSyntax:\n\n    csdr pll_cc (1 [alpha] |2 [bandwidth [damping_factor [ko [kd]]]])\n\nIt implements a PLL that can lock onto a sinusoidal input signal. \n\nThe first parameter corresponds to the order of the PLL loop filter (first or second order), others are parameters of the loop filter.\n\n----\n\n### [timing_recovery_cc](#timing_recovery_cc)\n\nSyntax:\n\n    csdr timing_recovery_cc  \u003calgorithm\u003e \u003cdecimation\u003e [mu [max_error [--add_q [--output_error | --output_indexes |  --octave \u003cshow_every_nth\u003e |  --octave_save \u003cshow_every_nth\u003e \u003cdirectory\u003e ]]]] \n\nIt implements non-data aided timing recovery (Gardner and early-late gate algorithms). \n\n[More information](http://openwebrx.org/msc-thesis.pdf#page=34) (section 4.4 from page 34)\n\n----\n\n### [octave_complex_c](#octave_complex_c)\n\nSyntax:\n\n    csdr octave_complex_c \u003csamples_to_plot\u003e \u003cout_of_n_samples\u003e [--2d]\n\nIt generates octave commands to plot a complex time domain signal. Its output can be piped into `octave -i`. It plots every `samples_to_plot` samples `out_of_n_samples`.\n\n----\n\n### [psk_modulator_u8_c](#psk_modulator_u8_c)\n\nSyntax:\n\n    csdr psk_modulator_u8_c \u003cn_psk\u003e\n\nIt generates an N-PSK modulated signal from the input symbols. \n\nAs an example, for `n_psk`=4, it will translate:\n\n* any 0x00 byte on the input into 1+0j on the output,\n* any 0x01 byte on the input into 0+1j on the output,\n* any 0x02 byte on the input into -1+0j on the output,\n* any 0x03 byte on the input into 0-1j on the output.\n\n----\n\n### [duplicate_samples_ntimes_u8_u8](#duplicate_samples_ntimes_u8_u8)\n\nSyntax:\n\n    csdr duplicate_samples_ntimes_u8_u8 \u003csample_size_bytes\u003e \u003cntimes\u003e\n\nIt duplicates each sample of `sample_size_bytes` the given `ntimes` times.\n\n----\n\n### [psk31_interpolate_sine_cc](#psk31_interpolate_sine_cc)\n\nSyntax:\n\n    csdr psk31_interpolate_sine_cc \u003cinterpolation\u003e\n\nThe input to this function is one complex sample per symbol, the output is `interpolation` samples per symbol, interpolated using a cosine envelope (which is used for PSK31). \n\n----\n\n### [differential_encoder_u8_u8](#differential_encoder_u8_u8)\n\nSyntax:\n\n    csdr differential_encoder_u8_u8\n\nIt can be used while generating e.g. differential BPSK modulation. \n\n* If the input is 0x01, the output remains the same as the last output.\n* If the input is 0x00, the output changes from 0x00 to 0x01, or 0x01 to 0x00.\n\n----\n\n### [differential_decoder_u8_u8](#differential_decoder_u8_u8)\n\nSyntax:\n\n    csdr differential_decoder_u8_u8\n\nIt can be used while demodulating e.g. differential BPSK modulation. The following table show the logic function it performs:\n\n| Last input | Current input | Output | \n| ---------- | ------------- | ------ |\n| 0x00       | 0x00          | 0x01   |\n| 0x00       | 0x01          | 0x00   |\n| 0x01       | 0x00          | 0x00   |\n| 0x01       | 0x01          | 0x01   |\n\n----\n\n### [bpsk_costas_loop_cc](#bpsk_costas_loop_cc)\n\nSyntax:\n\n    csdr bpsk_costas_loop_cc \u003cloop_bandwidth\u003e \u003cdamping_factor\u003e [--dd | --decision_directed] [--output_error | --output_dphase | --output_nco | --output_combined \u003cerror_file\u003e \u003cdphase_file\u003e \u003cnco_file\u003e]\n\nIt implements a Costas loop for BPSK signals. \n\n[More information](http://openwebrx.org/msc-thesis.pdf#page=55) (section 5.4 from page 55)\n\n----\n\n### [simple_agc_cc](#simple_agc_cc)\n\nSyntax:\n\n    csdr simple_agc_cc \u003crate\u003e [reference [max_gain]] \n\nIt is an automatic gain control function with a single pole IIR loop filter.\n\n- `reference` is the reference level for the AGC. It tries to keep the amplitude of the output signal close to that.\n- AGC won't increase the gain over `max_gain`.\n- `rate` is the parameter of the loop filter.\n\nThe block diagram of this function follows:\n\n![simple_agc_cc block diagram](https://raw.githubusercontent.com/wiki/simonyiszk/csdr/simple-agc-dataflow.png)\n\n----\n\n### [peaks_fir_cc](#peaks_fir_cc)\n\nSyntax:\n\n    csdr peaks_fir_cc \u003ctaps_length\u003e \u003cpeak_rate × N\u003e\n\nIt applies a peak filter to the input signal. The peak filter is a very narrow bandpass filter, the opposite of a notch filter. The higher the `taps_length` is, the sharper the filter frequency transfer function is. \n\n`peak_rate` is the center of the passband, in proportion to the sampling rate. \n\n----\n\n### [firdes_peak_c](#firdes_peak_c)\n\nSyntax:\n\n    csdr firdes_peak_c \u003crate\u003e \u003clength\u003e [window [--octave]]\n\nIt designs a FIR peak filter, and writes the taps to the output. More about this filter at \u003ca href=\"#peaks_fir_cc\"\u003epeaks_fir_cc\u003c/a\u003e. \n\nThis command also supports GNU Octave-friendly output that can be piped into the Octave interpreter `octave -i`.\n\n----\n\n### [normalized_timing_variance_u32_f](#normalized_timing_variance_u32_f)\n\nSyntax:\n\n    csdr normalized_timing_variance_u32_f \u003csamples_per_symbol\u003e \u003cinitial_sample_offset\u003e [--debug]\n\nIt calculates the normalized timing variance. It works on the sample indexes output from the `timing_recovery_cc` function. \n\n----\n\n### [pulse_shaping_filter_cc](#pulse_shaping_filter_cc)\n\nSyntax:\n\n    csdr pulse_shaping_filter_cc (RRC \u003csamples_per_symbol\u003e \u003cnum_taps\u003e \u003cbeta\u003e | COSINE \u003csamples_per_symbol\u003e)\n\nIt runs a pulse shaping FIR filter on the signal.\n\n* `RRC` stands for Root-Raised-Cosine filter, a design parameter of which is `beta`.\n* The `COSINE` filter is the one used for BPSK31. \n* `samples_per_symbol` is the number of input samples per symbol.\n* `num_taps` is the filter length.\n\n----\n\n### [firdes_pulse_shaping_filter_f](#firdes_pulse_shaping_filter_f)\n\nSyntax:\n\n    csdr firdes_pulse_shaping_filter_f (RRC \u003csamples_per_symbol\u003e \u003cnum_taps\u003e \u003cbeta\u003e | COSINE \u003csamples_per_symbol\u003e)\n\nIt designs a pulse shaping filter, and outputs the taps. It has the same parameters as `pulse_shaping_filter_cc`. \n\n----\n\n### [generic_slicer_f_u8](#generic_slicer_f_u8)\n\nSyntax:\n\n    csdr generic_slicer_f_u8 \u003cn_symbols\u003e\n\nIt decides which symbol the sample corresponds to, where the highest symbol corresponds to 1.0, and the lowest symbol corresponds to -1.0.\n\nAs an example, if N=3, the 3 symbols to choose from are: -1, 0, 1. The algorithm will output:\n\n* 0x00 for any input sample between -infinity and -0.5.\n* 0x01 for any input sample between -0.5 and 0.5.\n* 0x02 for any input sample between 0.5 and infinity. \n\n----\n\n### [plain_interpolate_cc](#plain_interpolate_cc)\n\nSyntax:\n\n    csdr plain_interpolate_cc \u003cinterpolation\u003e\n\nIt interpolates the signal by writing `interpolation - 1` zero samples between each input sample. You need to run an anti-aliasing filter on its output.\n\n----\n\n### [dbpsk_decoder_c_u8](#dbpsk_decoder_c_u8)\n\nSyntax:\n\n    csdr dbpsk_decoder_c_u8\n\nIt implements a differential BPSK demodulator, with the following data flow:\n\n![DBPSK dataflow](https://raw.githubusercontent.com/wiki/simonyiszk/csdr/dbpsk-dataflow.png)\n\nThe output is 0x00 or 0x01.\n\n----\n\n### [bfsk_demod_cf](#bfsk_demod_cf)\n\nSyntax:\n\n    csdr bfsk_demod_cf \u003cspacing\u003e \u003cfilter_length\u003e\n\nIt implements a 2-FSK demodulator, with the following data flow:\n\n![BFSK dataflow](https://raw.githubusercontent.com/wiki/simonyiszk/csdr/bfsk-dataflow.png)\n\nYou can calculate the expected frequencies of the two tones on the input by the following formulas: `+(spacing/sampling_rate)` and `-(spacing/sampling_rate)`.\n\nFilter length is the length of the peak filters (FIR) applied to the input för each tone.\n\n----\n\n### [add_const_cc](#add_const_cc)\n\nSyntax:\n\n    csdr add_const_cc \u003ci\u003e \u003cq\u003e\n\nIt adds a constant value of `i+q*j` to each input sample.\n\n----\n\n### [pattern_search_u8_u8](#pattern_search_u8_u8)\n\nSyntax: \n\n    csdr pattern_search_u8_u8 \u003cvalues_after\u003e \u003cpattern_values × N\u003e\n\nIt can be used for preamble search. It looks for a given sequence of N bytes (`\u003cpattern_values × N\u003e`) in the input data, and if the sequence is found, it reads the following `\u003cvalues_after\u003e` bytes and outputs them. The `\u003cpattern_values × N\u003e` parameter is read as unsigned integers.\n\n----\n\n### [tee](#tee)\n\nSyntax:\n\n    csdr tee \u003cpath\u003e [buffers]\n\nSimilarly to the `tee` command, it reads data from the standard input, and writes it to both a file and the standard output. \n\nUnlike `tee`, if it fails to flush the data to the file, it still flushes it to the standard output. This allows us to have less glitches / better response time if we use this as a way to put branches in the data flow. Example:\n\n    mkfifo /tmp/csdr_fifo\n    rtl_sdr - | csdr tee /tmp/csdr_fifo | csdr dump_u8\n    cat /tmp/csdr_fifo | csdr convert_u8_f | csdr dump_f\n\nHow the data flow looks like:\n\n    rtl_sdr --\u003e tee --\u003e dump_u8\n                 |\n                \\/\n             convert_u8_f --\u003e dump_f\n\n\n### [?](#search_the_function_list)\n\nSyntax: \n\n    csdr ?\u003csearch_the_function_list\u003e\n\nYou can search the functions available in `csdr` just as if you typed: `csdr 2\u003e\u00261 | grep \u003csearch_what\u003e`\n\n### [=](#evaluate-python-expression)\n\nSyntax:\n\n    csdr =\u003cevaluate_python_expression\u003e\n\nWhen running complicated `csdr` commands, we usually run into using `python` to calculate certain parameters. \n\nThis function can eliminate some typing and make our command clearer.\n\nInstead of having to write: \n\n    csdr shift_addition_cc $(python -c \"print 1200/2400000.\") \n\n...we can type: \n\n    csdr shift_addition_cc $(csdr =1200/2400000.)\n\nIf using parenthesis inside the expression, it needs to be escaped (as `bash` would want to parse it): \n\n    csdr shift_addition_cc $(csdr =\\(1200+300\\)/2400000)\n\nAnother solution is using single quotes to wrap the expression: \n\n    csdr shift_addition_cc $(csdr '=(1200+300)/2400000.')\n\nCurrent version of `csdr` executes the following python script for this function:\n\n```python\nimport os, sys\nfrom math import *\nprint \u003cevaluate_python_expression\u003e\n```\n\nThis means that one can also call math functions like `sqrt()`.\n\n#### Control via pipes\n\nSome parameters can be changed while the `csdr` process is running. To achieve this, some `csdr` functions have special parameters. You have to supply a fifo previously created by the `mkfifo` command. Processing will only start after the first control command has been received by `csdr` over the FIFO.\n\n    shift_addition_cc --fifo \u003cfifo_path\u003e\n\nBy writing to the given FIFO file with the syntax below, you can control the shift rate:\n\n    \u003cshift_rate\u003e\\n\n\nE.g. you can send `-0.3\\n`\n\nProcessing will only start after the first control command has been received by `csdr` over the FIFO.\n\n    bandpass_fir_fft_cc --fifo \u003cfifo_path\u003e \u003ctransition_bw\u003e [window]\n\nBy writing to the given FIFO file with the syntax below, you can control the shift rate:\n\n    \u003clow_cut\u003e \u003chigh_cut\u003e\\n\n\nE.g. you can send `-0.05 0.02\\n`\n\n#### Buffer sizes\n\n*csdr* has three modes of determining the buffer sizes, which can be chosen by the appropriate environment variables:\n* *default:* 16k or 1k buffer is chosen based on function,\n* *dynamic buffer size determination:* input buffer size is recommended by the previous process, output buffer size is determined by the process,\n* *fixed buffer sizes*.\n\n*csdr* can choose from two different buffer sizes by **default**.\n* For operations handling the full-bandwidth I/Q data from the receiver, a buffer size of 16384 samples is used (see `env_csdr_fixed_big_bufsize` in the code).\n* For operations handling only a selected channel, a buffer size of 1024 samples is used (see `env_csdr_fixed_bufsize` in the code).\n\n*csdr* now has an experimental feature called **dynamic buffer size determination**, which is switched on by issuing `export CSDR_DYNAMIC_BUFSIZE_ON=1` in the shell before running `csdr`. If it is enabled:\n* All `csdr` processes in a DSP chain acquire their recommended input buffer size from the previous `csdr` process. This information is in the first 8 bytes of the input stream.\n* Each process can decide whether to use this or choose another input buffer size (if that's more practical).\n* Every process sends out its output buffer size to the next process. Then it startss processing data.\n* The DSP chain should start with a `csdr setbuf \u003cbuffer_size\u003e` process, which only copies data from the input to the output, but also sends out the given buffer size information to the next process.\n* The 8 bytes of information included in the beginning of the stream is:\n  * a preamble of the bytes 'c','s','d','r' (4 bytes),\n  * the buffer size stored as `int` (4 bytes).\n* This size always counts as samples, as we expect that the user takes care of connecting the functions with right data types to each other.\n\n\u003e I added this feature while researching how to decrease the latency of a DSP chain consisting of several multirate algorithms.\u003cbr /\u003e\n\u003e For example, a `csdr fir_decimate_cc 10` would use an input buffer of 10240, and an output buffer of 1024. The next process in the chain, `csdr bandpass_fir_fft_cc` would automatically adjust to it, using a buffer of 1024 for both input and output.\u003cbr /\u003e\n\u003e In contrast to original expectations, using dynamic buffer sizes didn't decrease the latency much.\n\nIf dynamic buffer size determination is disabled, you can still set a **fixed buffer size** with `export CSDR_FIXED_BUFSIZE=\u003cbuffer_size\u003e`.\n\nFor debug purposes, buffer sizes of all processes can be printed using `export CSDR_PRINT_BUFSIZES=1`.\n\nIf you add your own functions to `csdr`, you have to initialize the buffers before doing the processing. Buffer size will be stored in the global variable `the_bufsize`.\n\nExample of initialization if the process generates N output samples for N input samples:\n\n    if(!sendbufsize(initialize_buffers())) return -2;\n\nExample of initalization if the process generates N/D output samples for N input samples:\n\n    if(!initialize_buffers()) return -2;\n    sendbufsize(the_bufsize/D);\n\nExample of initialization if the process allocates memory for itself, and it doesn't want to use the global buffers:\n\n    getbufsize(); //dummy\n    sendbufsize(my_own_bufsize);\n\nExample of initialization if the process always works with a fixed output size, regardless of the input:\n\n    if(!initialize_buffers()) return -2;\n    sendbufsize(fft_size);\n\n#### Testbench\n\n`csdr` was tested with GNU Radio Companion flowgraphs. These flowgraphs are available under the directory `grc_tests`, and they require the \u003ca href=\"https://github.com/simonyiszk/gr-ha5kfu\"\u003egr-ha5kfu\u003c/a\u003e set of blocks for GNU Radio.  \n\n## [sdr.js](#sdrjs)\n\n*sdr.js* is *libcsdr* compiled to JavaScript code with *Emscripten*. Nowadays JavaScript runs quite fast in browsers, as all major browser vendors included JavaScript JIT machines into their product. You can find a \u003ca href=\"https://kripken.github.io/mloc_emscripten_talk/cppcon.html\"\u003egreat introductory slideshow here\u003c/a\u003e on the concept behind *Emscripten* and *asm.js*.\n\nThe purpose of *sdr.js* is to make SDR DSP processing available in the web browser. However, it is not easy to use in production yet. By now, only those functions have wrappers that the front-end of OpenWebRX uses.\n\nTo compile *sdr.js*, first get \u003ca href=\"http://emscripten.org/\"\u003eEmscripten\u003c/a\u003e. (It turns out that there is an *emscripten* package in Ubuntu repositories.)\n\nTo install and build dependencies (for now, only FFTW3):\n\n    make emcc-get-deps\n\nTo compile *sdr.js* (which will be created in the `sdr.js` subdirectory):\n\n    make emcc\n\nYou can test *sdr.js* by opening *sdr.html*. It contains a test for *firdes_lowpass_f* for this time.\n\nTo remove *sdr.js* and the compiled dependencies:\n\n    make emcc-clean\n\n## [nmux](#nmux)\n\nThe repo also contains a command line tool called `nmux`, which is a TCP stream multiplexer. It reads data from the standard input, and sends it to each client connected through TCP sockets. Available command line options are:\n* `--port (-p), --address (-a):` TCP port and address to listen.\n* `--bufsize (-b), --bufcnt (-n)`: Internal buffer size and count.\n* `--help (-h)`: Show help message.\n\n`nmux` was originally written for use in OpenWebRX.\n\n## [Licensing](#licensing)\n\nMost of the code of `libcsdr` is under BSD license.  \nHowever, before the implementation of some algoritms, GPL-licensed code from other applications have been reviewed.\nIn order to eliminate any licesing issues, these parts are placed under a different file.\nHowever, the library is still fully functional with BSD-only code, altough having only less-optimized versions of some algorithms.  \nIt should also be noted that if you compile with `-DUSE_FFTW` and `-DLIBCSDR_GPL` (as default), the GPL license would apply on the whole result.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fha7ilm%2Fcsdr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fha7ilm%2Fcsdr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fha7ilm%2Fcsdr/lists"}