aboutsummaryrefslogtreecommitdiff
path: root/stm32/unittest/scripts/plot_ofdm_demod_syms
blob: 28eb063ce5f4bc9c11b9b2a7bd4680389712e91c (plain)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python3
""" plot_ofdm_demod_syms

    Plot QPSK constelations of reference demods.

    Later read stm32 log......

    """

import numpy as np
import os
import sys


##############################################################################
# Read Octave text file
##############################################################################

def read_octave_text(fname):
    data = {}
    with open(fname, "r") as f:
      for line in f:
        if (line[0:8] == '# name: '):
          var = line.split()[2]
          print('found {}'.format(var))
          line = next(f)
          if (line.startswith('# type: matrix')):
            line = next(f)
            rows = int(line.split()[2])
            line = next(f)
            cols = int(line.split()[2])
            print('  matrix({}, {})'.format(rows, cols))
            data[var] = np.empty((rows, cols), np.float32)
            # Read rows one at a time
            for row in range(rows):
              line = next(f)
              data[var][row] = np.fromstring(line, np.float32, cols, ' ')

          # end while True
      # end with
    return(data)


##############################################################################
# Main
##############################################################################

### Text not supported!!!  ref_data = sio.loadmat('ofdm_demod_ref_log.mat')

ref_data = read_octave_text('ofdm_demod_ref_log.txt')

import pprint
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(ref_data)