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

Subversion Repositories cascaded_fir_filter

[/] [cascaded_fir_filter/] [trunk/] [create_IQ_chirp.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_chirp_signal.txt", "w")
5
out_file_ping = open("IQ_chirp_ping.txt", "w")
6
#mod_list = array('b', [1, 1, -1, 1, -1, 1, -1])
7
#mod_length = 100
8
samp_rate = 50000
9
data_leng = 0.080
10
pulse_freq_carry = 250000
11
pulse_freq_sweep =   5000
12
pulse_leng = 0.001
13
pulse_amp = 32.0
14
noise_amp = 4.0
15
sig_offs = 0.003
16
sig_amp = 16.0
17
leak_amp = 4.0
18
samp_per = 1.0 / samp_rate
19
print "samp_per: ", samp_per
20
adc_rate = pulse_freq_carry * 4.0
21
adc_per = 1.0 / adc_rate
22
print "adc_per: ", adc_per
23
samp_div = round(1.0 / (samp_rate * adc_per))
24
print "samp_div: ", samp_div
25
samp_per = adc_per * samp_div
26
time_var = 0
27
carr_phase_delta      = 2.0 * math.pi * (pulse_freq_carry) * adc_per
28
carr_phase_curr       = 0
29
pulse_phase_mod_start = 2.0 * math.pi * pulse_freq_sweep * ( - pulse_leng)
30
pulse_phase_mod_step_const  = 2.0 * math.pi * pulse_freq_sweep / pulse_leng * adc_per**2
31
pulse_phase_mod_step_var_c  = 4.0 * math.pi * pulse_freq_sweep / pulse_leng * adc_per
32
 
33
#print "pulse_phase_delta: ", pulse_phase_delta
34
pulse_delta_freq = pulse_freq_sweep / pulse_leng / samp_rate
35
pulse_freq_carry_curr = pulse_freq_carry - pulse_freq_sweep / 2
36
print "samp_per: ", samp_per
37
samps_t = []
38
samps_phi = []
39
samps_I = []
40
samps_Q = []
41
samps_freq = []
42
adc_I = []
43
adc_Q = []
44
adc_t = []
45
iteration = 0
46
samp_counter = 0
47
time_start_mod = 0
48
while time_var < data_leng and iteration < 100000 or samp_counter % 2 == 1:
49
        iteration += 1
50
        samp_I = 0
51
        samp_Q = 0
52
        if samp_counter == samp_div :
53
                samp_counter = 0
54
        if time_var < pulse_leng :
55
                if time_var == 0 :
56
                        time_start_mod = time_var
57
                if samp_counter == 0 :
58
                        samp_I = pulse_amp * math.sin(carr_phase_curr)
59
                if samp_counter == 1 :
60
                        samp_Q = pulse_amp * math.sin(carr_phase_curr)
61
                carr_phase_curr += pulse_phase_mod_step_const + pulse_phase_mod_step_var_c * (time_var - time_start_mod)
62
        elif time_var >= sig_offs and time_var < sig_offs + pulse_leng :
63
                if samp_counter == 0 :
64
                        samp_I = sig_amp * math.sin(carr_phase_curr)
65
                if samp_counter == 1 :
66
                        samp_Q = sig_amp * math.sin(carr_phase_curr)
67
                carr_phase_curr += pulse_phase_mod_step_const + pulse_phase_mod_step_var_c * (time_var - time_start_mod)
68
        else :
69
                #pulse_freq_carry_curr = pulse_freq_carry - pulse_freq_sweep / 2
70
                time_start_mod = time_var
71
                if samp_counter == 0 :
72
                        samp_I = leak_amp * math.sin(carr_phase_curr)
73
                if samp_counter == 1 :
74
                        samp_Q = leak_amp * math.sin(carr_phase_curr)
75
        #carr_phase_curr += carr_phase_delta
76
        adc_I.append(pulse_amp * math.sin(carr_phase_curr))
77
        adc_t.append(time_var);
78
        if samp_counter == 0 :
79
                samps_I.append(samp_I);
80
        if samp_counter == 1 :
81
                samps_Q.append(samp_Q);
82
                samps_t.append(time_var);
83
                samps_phi.append(carr_phase_curr);
84
        carr_phase_curr += carr_phase_delta
85
        time_var += adc_per
86
        samp_counter += 1
87
samps_I
88
samps_Q
89
samps_t
90
print "len(samps_I) ", len(samps_I)
91
for i1 in range(len(samps_I)) :
92
        #out_file_samp.write("{0:04x}_{1:04x} {2} {3}\r\n".format(int(samps_I[i]) & 0xFFFF, int(samps_Q[i]) & 0xFFFF, int(samps_I[i]), int(samps_Q[i])))
93
        #print "i1: ", i1, " ", samps_I[i1], " ", samps_Q[i1]
94
        out_file_samp.write("{0:04x}\r\n{1:04x}\r\n".format(int(samps_I[i1]) & 0xFFFF, int(samps_Q[i1]) & 0xFFFF))
95
for i1 in range(int(pulse_leng/samp_per)) :
96
        #out_file_samp.write("{0:04x}_{1:04x} {2} {3}\r\n".format(int(samps_I[i]) & 0xFFFF, int(samps_Q[i]) & 0xFFFF, int(samps_I[i]), int(samps_Q[i])))
97
        #print "i1: ", i1, " ", samps_I[i1], " ", samps_Q[i1]
98
        out_file_ping.write("{0:04x}\r\n{1:04x}\r\n".format(int(samps_I[i1]) & 0xFFFF, int(samps_Q[i1]) & 0xFFFF))
99
out_file_samp.close()
100
matplotlib.pyplot.figure(1)
101
matplotlib.pyplot.subplot(3,1,1)
102
matplotlib.pyplot.plot(samps_t, samps_I)
103
matplotlib.pyplot.plot(samps_t, samps_Q)
104
#matplotlib.pyplot.figure(2)
105
matplotlib.pyplot.subplot(3,1,2)
106
#matplotlib.pyplot.plot(samps_t, samps_freq)
107
matplotlib.pyplot.plot(samps_t, samps_phi)
108
matplotlib.pyplot.subplot(3,1,3)
109
matplotlib.pyplot.plot(adc_t, adc_I)
110
matplotlib.pyplot.show()

powered by: WebSVN 2.1.0

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