Christophe Favergeon | 5f2be8f | 2019-09-20 13:13:15 +0200 | [diff] [blame^] | 1 | import numpy as np |
| 2 | from pylab import figure, clf, plot, xlabel, ylabel, xlim, ylim, title, grid, axes, show,semilogx, semilogy |
| 3 | import scipy.fftpack |
| 4 | import os.path |
| 5 | import struct |
| 6 | import argparse |
| 7 | |
| 8 | import PatternGeneration.DebugTools as d |
| 9 | |
| 10 | # Example script to read patterns and test outputs |
| 11 | |
| 12 | parser = argparse.ArgumentParser(description='Debug description') |
| 13 | parser.add_argument('-f', nargs='?',type = str, default="f32", help="Format") |
| 14 | parser.add_argument('-n', nargs='?',type = str, default="1", help="Test number") |
| 15 | parser.add_argument('-i', nargs='?',type = bool, default=False, help="Ifft") |
| 16 | parser.add_argument('-ui', nargs='?',const=True,type = bool, default=False, help="Display curves") |
| 17 | |
| 18 | args = parser.parse_args() |
| 19 | |
| 20 | FFTSIZES=[16,32,64,128,256,512,1024,2048,4096] |
| 21 | |
| 22 | if int(args.n) >= 19: |
| 23 | args.i = True |
| 24 | |
| 25 | if args.i: |
| 26 | n = int(args.n) - 18 |
| 27 | s = FFTSIZES[n-1] |
| 28 | sc = n - 1 + 4 |
| 29 | inputPath = os.path.join("Patterns","DSP","Transform","Transform%s" % args.f.upper(),"ComplexInputIFFTSamples_Noisy_%d_%d_%s.txt" % (s,n,args.f)) |
| 30 | refPath = os.path.join("Patterns","DSP","Transform","Transform%s" % args.f.upper(),"ComplexInputSamples_Noisy_%d_%d_%s.txt" % (s,n,args.f)) |
| 31 | outputPath= os.path.join("Output","DSP","Transform","Transform%s" % args.f.upper(),"ComplexFFTSamples_%s.txt" % args.n) |
| 32 | else: |
| 33 | s = FFTSIZES[int(args.n)-1] |
| 34 | inputPath = os.path.join("Patterns","DSP","Transform","Transform%s" % args.f.upper(),"ComplexInputSamples_Noisy_%d_%s_%s.txt" % (s,args.n,args.f)) |
| 35 | refPath = os.path.join("Patterns","DSP","Transform","Transform%s" % args.f.upper(),"ComplexFFTSamples_Noisy_%d_%s_%s.txt" % (s,args.n,args.f)) |
| 36 | outputPath= os.path.join("Output","DSP","Transform","Transform%s" % args.f.upper(),"ComplexFFTSamples_%s.txt" % args.n) |
| 37 | |
| 38 | print(inputPath) |
| 39 | |
| 40 | |
| 41 | if args.f == "f32": |
| 42 | inSig = d.readF32Pattern(inputPath) |
| 43 | inSig=inSig.view(dtype=np.complex128) |
| 44 | |
| 45 | refSig = d.readF32Pattern(refPath) |
| 46 | refSig=refSig.view(dtype=np.complex128) |
| 47 | |
| 48 | sig = d.readF32Output(outputPath) |
| 49 | sig=sig.view(dtype=np.complex128) |
| 50 | |
| 51 | if args.f == "q31": |
| 52 | inSig = d.readQ31Pattern(inputPath) |
| 53 | inSig=inSig.view(dtype=np.complex128) |
| 54 | |
| 55 | refSig = d.readQ31Pattern(refPath) |
| 56 | refSig=refSig.view(dtype=np.complex128) |
| 57 | |
| 58 | sig = d.readQ31Output(outputPath) |
| 59 | sig=sig.view(dtype=np.complex128) |
| 60 | |
| 61 | if args.f == "q15": |
| 62 | inSig = d.readQ15Pattern(inputPath) |
| 63 | inSig=inSig.view(dtype=np.complex128) |
| 64 | |
| 65 | refSig = d.readQ15Pattern(refPath) |
| 66 | refSig=refSig.view(dtype=np.complex128) |
| 67 | |
| 68 | sig = d.readQ15Output(outputPath) |
| 69 | sig=sig.view(dtype=np.complex128) |
| 70 | |
| 71 | |
| 72 | if args.i and args.f != "f32": |
| 73 | refSig = refSig / 2**sc |
| 74 | |
| 75 | if args.ui: |
| 76 | if args.i: |
| 77 | figure() |
| 78 | plot(abs(inSig)) |
| 79 | figure() |
| 80 | plot(np.real(refSig)) |
| 81 | figure() |
| 82 | plot(np.real(sig)) |
| 83 | else: |
| 84 | figure() |
| 85 | plot(np.real(inSig)) |
| 86 | figure() |
| 87 | plot(abs(refSig)) |
| 88 | figure() |
| 89 | plot(abs(sig)) |
| 90 | |
| 91 | print(d.SNR(refSig,sig)) |
| 92 | |
| 93 | #figure() |
| 94 | #plot(np.unwrap(np.angle(refSig))) |
| 95 | #figure() |
| 96 | #plot(np.unwrap(np.angle(sig))) |
| 97 | #figure() |
| 98 | #plot(np.unwrap(np.angle(sig)) - np.unwrap(np.angle(refSig))) |
| 99 | show()# |