File: msequence_example.c

package info (click to toggle)
liquid-dsp 1.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,216 kB
  • sloc: ansic: 115,859; sh: 3,513; makefile: 1,350; python: 274; asm: 11
file content (35 lines) | stat: -rw-r--r-- 1,020 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// This example demonstrates the property of maximal-length sequence
// (m-sequence) linear feedback shift registers (LFSR) where the state
// cycles through all permutations of integers from 1 to 2^m-1.
#include <stdlib.h>
#include <stdio.h>
#include <complex.h>
#include <math.h>

#include "liquid.h"

int main(int argc, char*argv[])
{
    // create and initialize m-sequence
    msequence q = msequence_create_default(5);
    msequence_print(q);

    // cycle through values and print state
    unsigned int i;
    for (i=0; i<msequence_get_length(q); i++) {
        // verify we never hit the '1' state except on the first iteration
        if (i > 0 && msequence_get_state(q)==1) {
            printf("invalid state!\n");
            break;
        }
        printf("%u\n",msequence_get_state(q));
        msequence_advance(q);
    }

    // ensure final state is 1 (circled all the way back around)
    printf("final state (should be 1): %u\n", msequence_get_state(q));

    msequence_destroy(q);
    return 0;
}