This repository has been archived by the owner on Jul 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
fmcw.py
121 lines (118 loc) · 3.27 KB
/
fmcw.py
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
from numpy import *
from math import *
import cmath
from scipy.misc import imsave
import scipy
from scipy import signal
import time
h=100
lmin=100
l=800
x=500
dx=0.25
dl=0.5
k=4e8
c=3e8
bw=1e7
st=bw/k
sp=1.5e7
freq=5e8
pwr=100
tm=2e-5
slen=tm*sp
dt=1/sp
v=10
sst=dx/v
sp2=1e6
dtt=1.0/sp2
def signalr(t,par):
tt=pi*k*pow((t%st)-st/2,2)
#print t
return complex(cos(tt+par),sin(tt+par))
print slen
print "1"
stp=time.time()
snls=zeros(int(sp*st),dtype=complex)
for i in range(len(snls)):
snls[i]=signalr(i*dt,0)
rx=zeros(int(sst*sp),dtype=complex)
tx=zeros(int(sst*sp),dtype=complex)
mix=zeros(int(sst*sp),dtype=complex)
mixx=zeros(int(sst*sp2),dtype=complex)
mixx2=zeros(int(sst*sp2),dtype=complex)
def r2i(r):
return 2*k*sst*r/c
snlr=zeros([int(x/dx),len(mixx)/2],dtype=complex)
#snl2=zeros([int(x/dx),int(slen)],dtype=complex)
#snl3=zeros([int(x/dx),int(slen)],dtype=complex)
def PointTarget(i,t,px,py):
tt=sst*i+t
x=i*dx+t*v
rr=sqrt(pow(h,2)+pow(px,2)+pow(x-py,2))
tos=2*rr/c
return signalr(tt-tos,-2*pi*tos*freq)/pow(rr,4)
def i2r(i):
return i*c/(2*k*sst)
print str(len(mixx))+"to"+str(len(snlr[1]))
for i in range(len(snlr)):
for j in range(len(mixx)):
mixx[j]=(PointTarget(i,j*dtt,lmin+l/2,x/2)+PointTarget(i,j*dtt,lmin+l/2,x/2+100)+PointTarget(i,j*dtt,lmin+l/2+100,x/2))*conjugate(signalr(i*sst+j*dtt,0))
mixx=fft.fftshift(fft.fft(mixx))
for j in range(len(mixx)):
ph=pi*pow((j-len(mixx)/2)*sp2/len(mixx),2)/k
mixx[j]=mixx[j]*complex(cos(ph),sin(ph))
snlr[i]=flipud(mixx[0:len(mixx)/2])
print "i:"+str(i)
#print j
imsave("test.bmp",real(snlr));
print time.time()-stp
print "2"
#for i in range(len(snlr)):
# snl2[i]=convolve(snlr[i],flipud(conjugate(snls)),'same')
#imsave("test2.bmp",real(snl2));
print time.time()-stp
print "3"
snl3=fft.fftshift(fft.fft(snlr,axis=0),axes=0)## range doppler
imsave("test3.bmp",real(snl3));
print time.time()-stp
print "4"
def rcmc(ll,fr):
if(((2*freq+c*fr)*(2*freq-c*fr)*(pow(h,2)+pow(ll,2)))>0):
a=-(2*c*fr*sqrt(((2*freq+c*fr)*(2*freq-c*fr)*(pow(h,2)+pow(ll,2)))/4))/(-pow(c,2)*pow(fr,2)+4*pow(freq,2))
rrr=sqrt(pow(ll,2)+pow(h,2)+pow(a,2))
return rrr
else:
return (-1)
snl4=zeros([int(x/dx),int(l/dl)],dtype=complex)
for i in range(len(snl4)):
for j in range(len(snl4[i])):
#print i,j,j*dl+lmin,(i*dx/x-0.5)/dx
if(len(snl3[i])>int(r2i(rcmc(j*dl+lmin,(i*dx/x-0.5)/dx))) and int(r2i(rcmc(j*dl+lmin,(i*dx/x-0.5)/dx)))>=0):
snl4[i][j]=snl3[i][int(r2i(rcmc(j*dl+lmin,(i*dx/x-0.5)/dx)))]
imsave("test4.bmp",real(snl4));
print time.time()-stp
print "5"
snl5=fft.ifft(fft.ifftshift(snl4,axes=0),axis=0)
imsave("test5.bmp",real(snl5));
print time.time()-stp
print "6"
filt=zeros([int(x/dx),int(l/dl)],dtype=complex)
for i in range(len(filt)):
for j in range(len(filt[i])):
rrr=sqrt(pow(j*dl+lmin,2)+pow(h,2)+pow((i*dx)-x/2,2))
tos=2*rrr/c
par=-tos*2*pi*freq
filt[i][j]=complex(cos(par),sin(par))
imsave("filt.bmp",real(filt));
snl6=zeros([int(x/dx),int(l/dl)],dtype=complex)
for i in range(len(snl6[0])):
snl6[:,i]=signal.fftconvolve(snl5[:,i],flipud(conjugate(filt[:,i])),'same')
imsave("test6.bmp",abs(snl6));
print time.time()-stp
print "m"
mapp=zeros([int(x/dx),int(l/dl)],dtype=float)
mapp[int((x/2)/dx)][int((l/2)/dl)]=1
mapp[int((x/2)/dx)][int((l/2+100)/dl)]=1
mapp[int((x/2+100)/dx)][int((l/2)/dl)]=1
imsave("mapp.bmp",mapp);
print time.time()-stp