OpenCores
URL https://opencores.org/ocsvn/cascaded_fir_filter/cascaded_fir_filter/trunk

Subversion Repositories cascaded_fir_filter

[/] [cascaded_fir_filter/] [trunk/] [create_IQ_tone.py] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 Juzujka
import matplotlib.pyplot
2
import numpy
3
import math
4
out_file_samp = open("IQ_tone_signal.txt", "w")
5
out_file_ping = open("IQ_tone_ping.txt", "w")
6
samp_rate = 50000               # Hz
7
data_duration = 0.05    # s
8
tone_freq = 5000                # Hz
9
ping_duration = 0.002   # s
10
ping_amplitude = 15
11
echo_position = 0.025   # s
12
echo_amplitude = 10
13
 
14
time_acc = 0
15
time_delta = 1.0 / samp_rate
16
tone_omega = 2.0 * math.pi * 5000
17
ping_length = 0
18
data_length = 0
19
 
20
samps_t = []
21
samps_I = []
22
samps_Q = []
23
 
24
pings_t = []
25
pings_I = []
26
pings_Q = []
27
 
28
samp_I = 0
29
samp_Q = 0
30
 
31
while time_acc < data_duration :
32
        if time_acc < ping_duration :
33
                samp_I = ping_amplitude * math.cos(tone_omega * time_acc)
34
                samp_Q = ping_amplitude * math.sin(tone_omega * time_acc)
35
                pings_t.append(time_acc);
36
                pings_I.append(samp_I);
37
                pings_Q.append(samp_Q);
38
                out_file_ping.write("{0:04x}\r\n{1:04x}\r\n".format(int(samp_I) & 0xFFFF, int(samp_Q) & 0xFFFF))
39
                ping_length += 1
40
        else :
41
                if (time_acc >= echo_position) and (time_acc < echo_position + ping_duration) :
42
                        samp_I = echo_amplitude * math.cos(tone_omega * time_acc)
43
                        samp_Q = echo_amplitude * math.sin(tone_omega * time_acc)
44
                else :
45
                        samp_I = 0
46
                        samp_Q = 0
47
        samps_t.append(time_acc);
48
        samps_I.append(samp_I);
49
        samps_Q.append(samp_Q);
50
        out_file_samp.write("{0:04x}\r\n{1:04x}\r\n".format(int(samp_I) & 0xFFFF, int(samp_Q) & 0xFFFF))
51
        data_length += 1
52
        time_acc += time_delta
53
out_file_ping.close()
54
out_file_samp.close()
55
print "ping length = ", ping_length
56
print "data length = ", data_length
57
matplotlib.pyplot.figure(1)
58
matplotlib.pyplot.subplot(3,1,1)
59
matplotlib.pyplot.plot(samps_t, samps_I)
60
matplotlib.pyplot.plot(samps_t, samps_Q)
61
#matplotlib.pyplot.figure(2)
62
matplotlib.pyplot.subplot(3,1,2)
63
matplotlib.pyplot.plot(pings_t, pings_I)
64
matplotlib.pyplot.plot(pings_t, pings_Q)
65
matplotlib.pyplot.show()

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.