File ofdm_core.h¶
FileList > doppler > ofdm > ofdm_core.h
Go to the source code of this file
A general OFDM modulator: constellation points and a layout in, baseband samples out. More...
#include "doppler/clib_common.h"#include "doppler/dp_state.h"#include "doppler/fft/fft_core.h"#include "doppler/jm_perf.h"
Classes¶
| Type | Name |
|---|---|
| struct | dp_ofdm_state_t Ofdm state: the layout (configuration) and the position in it (state). |
| struct | ofdm_class_t One kind of OFDM symbol. The arrays are owned by the modulator, copied in by dp_ofdm_add_class() anddp_ofdm_add_fixed() . |
| struct | ofdm_fixed_t One entry of a class's fixed pattern. |
| struct | ofdm_run_t A run of OFDM symbols of one class. |
Public Functions¶
| Type | Name |
|---|---|
| int | dp_ofdm_add_class (dp_ofdm_state_t * state, uint32_t n_fft, const uint8_t * subcarrier_map, size_t subcarrier_map_len, uint32_t useful, uint32_t cyclic_prefix, uint32_t window, double scale, uint32_t n_phase) Append one kind of OFDM symbol and return its index. |
| int | dp_ofdm_add_fixed (dp_ofdm_state_t * state, uint32_t class_index, uint32_t phase, int32_t k, double _Complex value) Append one fixed entry to a class: a pilot or a training value. |
| int | dp_ofdm_add_polarity (dp_ofdm_state_t * state, uint32_t class_index, const float _Complex * polarity, size_t polarity_len) Give a class a polarity sequence. |
| int | dp_ofdm_add_run (dp_ofdm_state_t * state, uint32_t class_index, uint32_t count, uint32_t cyclic_prefix, uint32_t polarity_offset, uint32_t first_phase) Append a run of OFDM symbols of one class and return its index. |
| int | dp_ofdm_add_subcarrier_gain (dp_ofdm_state_t * state, uint32_t class_index, const float _Complex * gain, size_t gain_len) Give a class a complex multiplier per subcarrier. |
| int | dp_ofdm_check (dp_ofdm_state_t * state) The plain form of dp_ofdm_check_why() : 0 if the layout is usable, a negative value if not, with no sentence. What a C caller that does not print the reason calls. |
| int | dp_ofdm_check_why (dp_ofdm_state_t * state, const char ** why) Check the whole layout and derive what the render uses; say why when it is not usable. This is the binding's check . |
| dp_ofdm_state_t * | dp_ofdm_create (void) Create an empty modulator (no classes, no runs). |
| void | dp_ofdm_destroy (dp_ofdm_state_t * state) Destroy a modulator and release all memory. |
| size_t | dp_ofdm_finish (dp_ofdm_state_t * state, size_t n, float _Complex * out, size_t max_out) Return the window tail still held and clear it. |
| size_t | dp_ofdm_finish_max_out (dp_ofdm_state_t * state, size_t n) Capacity dp_ofdm_finish() needs for n samples. |
| void | dp_ofdm_get_state (const dp_ofdm_state_t * state, void * blob) Write the state into blob . |
| size_t | dp_ofdm_modulate (dp_ofdm_state_t * state, const float _Complex * in, size_t n_in, float _Complex * out, size_t max_out) The plain form of dp_ofdm_modulate_why() . |
| size_t | dp_ofdm_modulate_max_out (dp_ofdm_state_t * state, size_t n_in) Samples a render of n_in points writes. |
| int64_t | dp_ofdm_modulate_why (dp_ofdm_state_t * state, const float _Complex * in, size_t n_in, float _Complex * out, size_t max_out, const char ** why) Render OFDM symbols from constellation points, or say why not. |
| size_t | dp_ofdm_points_remaining (dp_ofdm_state_t * state) Constellation points the rest of the layout consumes. |
| void | dp_ofdm_reset (dp_ofdm_state_t * state) Return to the first OFDM symbol, keeping the layout. |
| int | dp_ofdm_set_state (dp_ofdm_state_t * state, const void * blob) Restore the state; nonzero rejects blob . |
| size_t | dp_ofdm_state_bytes (const dp_ofdm_state_t * state) Bytes in the blob dp_ofdm_get_state() writes. |
Macros¶
| Type | Name |
|---|---|
| define | OFDM_ALL_PHASES 0xFFFFFFFFuA fixed entry that applies in every pattern phase. |
| define | OFDM_COUNT_MAX 65536uMost classes, and most fixed entries per class, a layout holds. |
| define | OFDM_CP_DEFAULT 0xFFFFFFFFuA run's cyclic prefix that keeps its class's. |
| define | OFDM_DATA 1uA subcarrier map value: the subcarrier carries a data point. |
| define | OFDM_NULL 0uA subcarrier map value: the subcarrier carries nothing. |
| define | OFDM_N_FFT_MAX 65536uLargest transform length of a class. |
| define | OFDM_N_PHASE_MAX 4096uLargest pattern period of a class, in OFDM symbols. |
| define | OFDM_STATE_MAGIC [**DP\_FOURCC**](dp__state_8h.md#define-dp_fourcc) ('O', 'F', 'D', 'M')State blob magic ('O','F','D','M'). |
| define | OFDM_STATE_VERSION 1uState blob layout version. |
Detailed Description¶
The modulator names no standard and includes nothing of wfmgen. What it renders is described by a layout, a list of classes (one kind of OFDM symbol: a transform length, a subcarrier map, a fixed pattern of pilots or training values, a scale, a cyclic prefix and a window) and a list of runs (a count of OFDM symbols of one class). A standard's preset is a filled-in layout; the design page, docs/design/ofdm.md, owns the shape and what forced each field.
One OFDM symbol¶
Per OFDM symbol the modulator takes the data count of the symbol's pattern phase from the points, places them on the data subcarriers that no fixed entry displaces (in increasing subcarrier order), sets the fixed entries of the phase times the class's polarity element, multiplies the grid by the subcarrier gains, inverse transforms, multiplies by scale, reads useful samples cyclically from the transform output, prefixes the last cyclic_prefix of them, and overlap-adds the window.
With m the sample index into the transform output and k the subcarrier, the unnormalized inverse transform is x[m] = scale * sum_k grid[k] * exp(+2j*pi*k*m/n_fft). The body is x[m mod n_fft] for m < useful; the symbol is the last cyclic_prefix body samples followed by the body.
The window¶
The boundary between two OFDM symbols is a raised-cosine cross-fade of window samples, rise[j] = sin^2 (pi (j + 1/2) / (2 window)) and fall[j] = 1 - rise[j]. The later symbol's first window samples are weighted by rise; the earlier symbol is continued past its end by window samples of the transform output (x[(useful + j) mod n_fft]), weighted by fall, and overlap-added. The length used at a boundary is the later symbol's class window; the first symbol rises from silence over its own, and the last continues over its own. A window of 0 is no window: the output is exactly the symbols, back to back. The continued tail is what crosses a call, so it is state; dp_ofdm_finish returns the last one.
The calls¶
Build the layout with dp_ofdm_add_class, dp_ofdm_add_fixed and dp_ofdm_add_run; the first dp_ofdm_modulate (or dp_ofdm_check) checks it whole. Adding to a checked layout re-opens it (the position and the held window tail stay), so a signal can be extended while it is rendered. Then dp_ofdm_modulate renders whole OFDM symbols from the points it is given.
dp_ofdm_state_t *o = dp_ofdm_create ();
const uint8_t map[8] = { 0, 1, 1, 1, 0, 1, 1, 1 }; // DC and edge null
dp_ofdm_add_class (o, 8u, map, 8u, 0u, 0u, 0u, 1.0, 1u);
dp_ofdm_add_run (o, 0u, 2u, 0xFFFFFFFFu, 0u, 0u);
float _Complex pts[12], out[16]; // 6 data subcarriers x 2 symbols
for (int i = 0; i < 12; i++)
pts[i] = 1.0f;
size_t n = dp_ofdm_modulate (o, pts, 12, out, 16); // n == 16
dp_ofdm_destroy (o);
Public Functions Documentation¶
function dp_ofdm_add_class¶
Append one kind of OFDM symbol and return its index.
int dp_ofdm_add_class (
dp_ofdm_state_t * state,
uint32_t n_fft,
const uint8_t * subcarrier_map,
size_t subcarrier_map_len,
uint32_t useful,
uint32_t cyclic_prefix,
uint32_t window,
double scale,
uint32_t n_phase
)
Copies subcarrier_map. The optional per-subcarrier gains and the polarity sequence are added to the class by dp_ofdm_add_subcarrier_gain() and dp_ofdm_add_polarity(). Refuses (a negative return, nothing changed) what cannot be honoured; a sealed layout is re-opened.
Parameters:
stateThe modulator.n_fftTransform length, 2 to OFDM_N_FFT_MAX.subcarrier_mapn_fftentries, indexk + n_fft/2, each OFDM_DATA or OFDM_NULL.subcarrier_map_lenMust equaln_fft.usefulBody samples read cyclically from the transform; 0 reads asn_fft.cyclic_prefixDefault prefix, samples; at mostuseful.windowWindow transition, samples; at most the symbol length.scaleMultiplies the transform output.n_phasePeriod of the fixed pattern, at least 1.
Returns:
The class index, or a negative value if refused.
>>> import numpy as np
>>> from doppler.ofdm import Ofdm
>>> o = Ofdm()
>>> m = np.zeros(8, np.uint8); m[[1, 2, 3, 5, 6, 7]] = 1
>>> o.add_class(8, m, cyclic_prefix=2)
0
>>> o.add_class(8, m, cyclic_prefix=2, window=1)
1
function dp_ofdm_add_fixed¶
Append one fixed entry to a class: a pilot or a training value.
int dp_ofdm_add_fixed (
dp_ofdm_state_t * state,
uint32_t class_index,
uint32_t phase,
int32_t k,
double _Complex value
)
A fixed entry displaces data on its subcarrier in its phase (when the map has data there) and is multiplied by the class's polarity element.
Parameters:
stateThe modulator.class_indexAn existing class.phaseThe pattern phase it belongs to, below the class'sn_phase, or OFDM_ALL_PHASES.kSubcarrier,-(n_fft/2) .. n_fft - n_fft/2 - 1in integer division: up ton_fft/2 - 1at an even length, andn_fft/2at an odd one.valueThe value placed.
Returns:
0, or a negative value if refused.
>>> import numpy as np
>>> from doppler.ofdm import Ofdm
>>> m = np.zeros(8, np.uint8); m[[1, 2, 3, 5, 6, 7]] = 1
>>> o = Ofdm()
>>> o.add_class(8, m, cyclic_prefix=2)
0
>>> o.add_run(0, 1)
0
>>> o.points_remaining() # six data subcarriers
6
>>> o.add_fixed(0, 2**32 - 1, 3, 1j) # a pilot on a data subcarrier
>>> o.points_remaining() # it displaces one
5
function dp_ofdm_add_polarity¶
Give a class a polarity sequence.
int dp_ofdm_add_polarity (
dp_ofdm_state_t * state,
uint32_t class_index,
const float _Complex * polarity,
size_t polarity_len
)
OFDM symbol n of a run multiplies its fixed entries (never its data) by element (polarity_offset + n) mod polarity_len. Without it the scalar is 1.
Parameters:
stateThe modulator.class_indexAn existing class without a sequence yet.polarityThe sequence.polarity_lenAt least 1.
Returns:
0, or a negative value if refused.
>>> import numpy as np
>>> from doppler.ofdm import Ofdm
>>> z = np.zeros(8, np.uint8) # no data subcarriers at all
>>> p = Ofdm(); p.add_class(8, z, cyclic_prefix=2)
0
>>> p.add_fixed(0, 2**32 - 1, 2, 1.0) # one pilot, every phase
>>> p.add_polarity(0, np.array([1, -1], np.complex64))
>>> p.add_run(0, 2)
0
>>> x = p.modulate(np.empty(0, np.complex64))
>>> bool(np.allclose(x[2:10], -x[12:20])) # the pilot flips sign
True
function dp_ofdm_add_run¶
Append a run of OFDM symbols of one class and return its index.
int dp_ofdm_add_run (
dp_ofdm_state_t * state,
uint32_t class_index,
uint32_t count,
uint32_t cyclic_prefix,
uint32_t polarity_offset,
uint32_t first_phase
)
Parameters:
stateThe modulator.class_indexAn existing class.countOFDM symbols, at least 1.cyclic_prefixOverride of the class's prefix, or OFDM_CP_DEFAULT; at most the class'suseful.polarity_offsetPolarity element of the run's first symbol.first_phasePattern phase of the run's first symbol.
Returns:
The run index, or a negative value if refused.
>>> import numpy as np
>>> from doppler.ofdm import Ofdm
>>> m = np.zeros(8, np.uint8); m[[1, 2, 3, 5, 6, 7]] = 1
>>> o = Ofdm()
>>> o.add_class(8, m, cyclic_prefix=2)
0
>>> o.add_run(0, 2)
0
>>> o.add_run(0, 3)
1
function dp_ofdm_add_subcarrier_gain¶
Give a class a complex multiplier per subcarrier.
int dp_ofdm_add_subcarrier_gain (
dp_ofdm_state_t * state,
uint32_t class_index,
const float _Complex * gain,
size_t gain_len
)
Applied to the whole grid (data and fixed entries alike): a per-subband phase rotation, or any per-subcarrier amplitude. Without it the gain is 1 everywhere.
Parameters:
stateThe modulator.class_indexAn existing class without gains yet.gainn_fftmultipliers, indexk + n_fft/2.gain_lenMust equal the class'sn_fft.
Returns:
0, or a negative value if refused.
>>> import numpy as np
>>> from doppler.ofdm import Ofdm
>>> m = np.zeros(8, np.uint8); m[[1, 2, 3, 5, 6, 7]] = 1
>>> o = Ofdm()
>>> o.add_class(8, m, cyclic_prefix=2)
0
>>> o.add_run(0, 1)
0
>>> pts = np.ones(6, np.complex64)
>>> one = o.modulate(pts)
>>> o.reset()
>>> o.add_subcarrier_gain(0, 2 * np.ones(8, np.complex64))
>>> bool(np.allclose(o.modulate(pts), 2 * one))
True
function dp_ofdm_check¶
The plain form of dp_ofdm_check_why() : 0 if the layout is usable, a negative value if not, with no sentence. What a C caller that does not print the reason calls.
Parameters:
stateThe modulator.
Returns:
0 if the layout is usable, a negative value if not.
function dp_ofdm_check_why¶
Check the whole layout and derive what the render uses; say why when it is not usable. This is the binding's check .
Refuses a layout with no run, a window longer than an OFDM symbol of its class, or two fixed entries on one subcarrier in one phase. Derives what the render uses (the data count per phase, the window weights, one inverse transform per distinct length). Idempotent once it has passed.
Parameters:
stateThe modulator.whyWhere the refusal's sentence goes: a static string naming the condition that failed. Left as the caller set it when the layout is usable. May be NULL.
Returns:
0 if the layout is usable, a negative value if not.
>>> import numpy as np
>>> from doppler.ofdm import Ofdm
>>> o = Ofdm()
>>> m = np.zeros(8, np.uint8); m[[1, 2, 3]] = 1
>>> o.add_class(8, m)
0
>>> o.check() # no run yet
Traceback (most recent call last):
...
ValueError: the layout has no run
>>> o.add_run(0, 1)
0
>>> o.check() # usable: returns None
function dp_ofdm_create¶
Create an empty modulator (no classes, no runs).
Returns:
Heap-allocated state, never NULL: running out of memory aborts.
Note:
Caller must call dp_ofdm_destroy() when done.
function dp_ofdm_destroy¶
Destroy a modulator and release all memory.
Parameters:
stateMay be NULL.
function dp_ofdm_finish¶
Return the window tail still held and clear it.
After the last OFDM symbol this is the final fall of the window; with a window of 0, or before anything is rendered, there is none.
Parameters:
stateThe modulator.nSamples asked for; the held tail is returned up to this.outReceives the tail.max_outCapacity ofout.
Returns:
Samples written.
>>> import numpy as np
>>> from doppler.ofdm import Ofdm
>>> m = np.zeros(8, np.uint8); m[[1, 2, 3, 5, 6, 7]] = 1
>>> o = Ofdm()
>>> o.add_class(8, m, cyclic_prefix=2, window=2)
0
>>> o.add_run(0, 2)
0
>>> x = o.modulate(np.ones(12, np.complex64))
>>> o.finish().size # the window's last fall
2
>>> o.finish().size # and it is cleared
0
function dp_ofdm_finish_max_out¶
Capacity dp_ofdm_finish() needs forn samples.
Parameters:
stateThe modulator.nSamples asked for.
Returns:
The held tail's length, at most n.
function dp_ofdm_get_state¶
Write the state into blob .
The blob holds the position (run index, OFDM symbols rendered of the run, the held window tail) and a hash of the layout, so it never restores into a different one.
Parameters:
stateThe modulator.blobReceives dp_ofdm_state_bytes() bytes.
function dp_ofdm_modulate¶
The plain form of dp_ofdm_modulate_why() .
size_t dp_ofdm_modulate (
dp_ofdm_state_t * state,
const float _Complex * in,
size_t n_in,
float _Complex * out,
size_t max_out
)
Parameters:
stateThe modulator.inConstellation points.n_inNumber of points.outReceives the samples.max_outCapacity ofout.
Returns:
Samples written, or 0 if the call is refused or writes none; a caller who must tell the two apart uses dp_ofdm_modulate_why().
function dp_ofdm_modulate_max_out¶
Samples a render of n_in points writes.
Simulates the render from the current position: OFDM symbols are taken in layout order until the next one needs more points than remain. The result is zero if n_in ends inside an OFDM symbol or runs past the layout (that call is refused), for a layout that does not seal, and for no points when the next OFDM symbol needs some. Use it to size the output before the call.
Parameters:
stateThe modulator.n_inConstellation points.
Returns:
Samples that call will write.
>>> import numpy as np
>>> from doppler.ofdm import Ofdm
>>> o = Ofdm()
>>> m = np.zeros(8, np.uint8); m[[1, 2, 3, 5, 6, 7]] = 1
>>> o.add_class(8, m, cyclic_prefix=2)
0
>>> o.add_run(0, 3)
0
>>> o.modulate_max_out(12) # two OFDM symbols of 10 samples
20
>>> o.modulate_max_out(5) # ends inside a symbol
0
function dp_ofdm_modulate_why¶
Render OFDM symbols from constellation points, or say why not.
int64_t dp_ofdm_modulate_why (
dp_ofdm_state_t * state,
const float _Complex * in,
size_t n_in,
float _Complex * out,
size_t max_out,
const char ** why
)
Parameters:
stateThe modulator; sealed by this call if it is not.inConstellation points, consumed in layout order.n_inNumber of points; must end on an OFDM symbol boundary.outReceives the samples.max_outCapacity ofout. Short is a refusal, not a truncation.whyNULL, or receives a static sentence for a refusal and is left as the caller set it otherwise: an unusable layout (the sentence dp_ofdm_check_why() gives), points that end inside an OFDM symbol, more points than the layout has left, or an output buffer shorter than dp_ofdm_modulate_max_out().
Returns:
Samples written, which may be 0: no points at the end of the layout, or zero points mid-layout when the next OFDM symbol needs some. A refused call changes nothing and reports it by face: C returns a negative value and sets why; the Python binding raises ValueError with that sentence.
>>> import numpy as np
>>> from doppler.ofdm import Ofdm
>>> o = Ofdm()
>>> m = np.zeros(8, np.uint8); m[[1, 2, 3, 5, 6, 7]] = 1
>>> o.add_class(8, m, cyclic_prefix=2)
0
>>> o.add_run(0, 3)
0
>>> o.points_remaining()
18
>>> x = o.modulate(np.ones(12, np.complex64)) # two of the three
>>> x.size
20
>>> o.points_remaining()
6
>>> o.modulate(np.ones(5, np.complex64)) # inside a symbol
Traceback (most recent call last):
...
ValueError: the points end inside an OFDM symbol: pass a count that ends where one does (see points_remaining and modulate_max_out)
function dp_ofdm_points_remaining¶
Constellation points the rest of the layout consumes.
Zero for a layout that does not seal.
Parameters:
stateThe modulator.
Returns:
Points from the current position to the end of the layout.
>>> import numpy as np
>>> from doppler.ofdm import Ofdm
>>> m = np.zeros(8, np.uint8); m[[1, 2, 3, 5, 6, 7]] = 1
>>> o = Ofdm()
>>> o.add_class(8, m, cyclic_prefix=2)
0
>>> o.add_run(0, 3)
0
>>> o.points_remaining()
18
function dp_ofdm_reset¶
Return to the first OFDM symbol, keeping the layout.
The next render starts from the post-seal state: the first run, no held tail. The layout, sealed or not, is unchanged.
Parameters:
stateMust be non-NULL.
>>> import numpy as np
>>> from doppler.ofdm import Ofdm
>>> m = np.zeros(8, np.uint8); m[[1, 2, 3, 5, 6, 7]] = 1
>>> o = Ofdm()
>>> o.add_class(8, m, cyclic_prefix=2)
0
>>> o.add_run(0, 2)
0
>>> x = o.modulate(np.ones(12, np.complex64))
>>> o.reset()
>>> o.points_remaining()
12
function dp_ofdm_set_state¶
Restore the state; nonzero rejects blob .
Rejects a blob whose layout hash differs from this modulator's, whose position names no OFDM symbol of the layout, or whose held tail is not the length the position implies. The modulator is untouched on rejection.
Parameters:
stateA modulator built with the same layout.blobA blob from dp_ofdm_get_state(), dp_ofdm_state_bytes() long.
Returns:
DP_OK, or DP_ERR_INVALID if rejected.
function dp_ofdm_state_bytes¶
Bytes in the blob dp_ofdm_get_state() writes.
A function of the layout alone (the envelope, the position and one window-tail slot per sample of the largest window), so it does not change as the render advances.
Parameters:
stateThe modulator.
Returns:
Blob size in bytes.
Macro Definition Documentation¶
define OFDM_ALL_PHASES¶
A fixed entry that applies in every pattern phase.
define OFDM_COUNT_MAX¶
Most classes, and most fixed entries per class, a layout holds.
define OFDM_CP_DEFAULT¶
A run's cyclic prefix that keeps its class's.
define OFDM_DATA¶
A subcarrier map value: the subcarrier carries a data point.
define OFDM_NULL¶
A subcarrier map value: the subcarrier carries nothing.
define OFDM_N_FFT_MAX¶
Largest transform length of a class.
define OFDM_N_PHASE_MAX¶
Largest pattern period of a class, in OFDM symbols.
define OFDM_STATE_MAGIC¶
State blob magic ('O','F','D','M').
define OFDM_STATE_VERSION¶
State blob layout version.
The documentation for this class was generated from the following file native/inc/doppler/ofdm/ofdm_core.h