ASCII Spectral Periodogram (asgram)

API Keywords: asgram asgramf asgramcf ASCII text power spectral density spgram periodogram

The asgram family of objects use a spgram object to estimate the power spectral density of a signal and generate an ASCII representation for displaying on a terminal screen. While using text to display an image (commonly known as ASCII art ) does not provide much resolution for a spectral periodogram; however it often can be useful when no graphical display is available.

The asgram family uses 10 characters to represent the signal level at a particular frequency. The default values (from lowest to highest are): a single space, . , , , - , + , * , & , N , M , # . The asgramcf_set_scale(q,ref,div) method sets the scale of the object according to a baseline power spectral density offset dB with div dB per character. For example, if ref=-80 dB and div=10 dB per divistion, and the & character were displayed (the character at index 6), then this would represent a power spectral density value in the range of -25 to -15 dB. Like I said, not a high resolution. But if you want to use your own character set, just invoke the asgramcf_set_display(q,ascii) method.

Figure [ref:fig-asgram-example] below shows a spectral waterfall plot of a set of signals, both with a high-resolution image, and the complementary ASCII version.

doc/asgram/waterfall.png
doc/asgram/asgramcf.png

Figure [fig-asgram-example-text]. Not so high resolution asgramcf text output with a reference set to -70 dB and scale set to 5 dB/div.

Figure [fig-asgram-example-waterfall]. High-resolution waterfall image

The interface to the asgramcf object is very similar that of the spgramcf object. The FFT size parameter, however, represents the number of characters to display on the screen. Here is a quick example:

#include <liquid/liquid.h>

int main() {
    // options
    unsigned int nfft    =   72;    // FFT size (display)
    unsigned int buf_len = 3456;    // input buffer size

    // create spectral periodogram and set scale
    asgramcf q = asgramcf_create(nfft);
    asgramcf_set_scale  (q, -80.0f, 5.0f);
    asgramcf_set_display(q, "...++++###"); // set custom display characters

    // allocated memory arrays
    float complex * buf = (float complex*) malloc(buf_len*sizeof(float complex));

    // ... initialize input ...

    // write block of samples to spectral periodogram object
    asgramcf_write(q, buf, buf_len);

    // print result to screen
    asgramcf_print(q);

    // destroy object and free memory arrays
    asgramcf_destroy(q);
    free(buf);
}