from math import *
import numpy as np
import scipy
#import matcompat
# if available import pylab (from matlibplot)
try:
import matplotlib.pylab as plt
except ImportError:
pass
#clear(all)
u_basic = input('Signal elements (row complex vector, each element last tb sec) = ? ')
m_basic = len(u_basic)
#%returns the largest array dimension in matrix
fcode = input(' Allow frequency coding (yes=1, no=0) = ? ')
if fcode == 1.:
f_basic = input(' Frequency coding in units of 1/tb (row vector of same length) = ? ')
F = input(' Maximal Doppler shift for ambiguity plot [in units of 1/Mtb] (e.g., 1)= ? ')
K = input(' Number of Doppler grid points for calculation (e.g., 100) = ? ')
F = np.float(F)
df=F/K/m_basic;
T = input(' Maximal Delay for ambiguity plot [in units of Mtb] (e.g., 1)= ? ')
N = input(' Number of delay grid points on each side (e.g. 100) = ? ')
sr = input(' Over sampling ratio (>=1) (e.g. 10)= ? ')
r=ceil(sr*(N+1)/T/m_basic);
if r == 1.:
dt = 1.
m = m_basic
uamp = np.abs(u_basic)
phas = uamp*0.
phas = np.angle(u_basic)
if fcode == 1.:
phas = phas+np.dot(2.*np.pi, np.cumsum(f_basic))
uexp = np.exp(np.dot(j, phas))
u = uamp*uexp
else:
dt = 1./r
ud = np.diag(u_basic)
ao = np.ones((r, m_basic))
m = np.dot(m_basic, r)
u_basic=np.reshape(ao*ud,(1,m),order='F')
uamp = np.abs(u_basic)
phas = np.angle(u_basic)
u = u_basic
if fcode == 1.:
ff = np.diag(f_basic)
phas = np.dot(np.dot(2.*np.pi, dt), np.cumsum(np.reshape(np.dot(ao, ff), 1., m)))+phas
uexp = np.exp(np.dot(j, phas))
u = uamp*uexp
t = np.array(np.hstack((np.arange(0., np.dot(r,m_basic)-1.)+1)))/r
tscale1 = (np.array(np.hstack((0., np.arange(0., (np.dot(r, m_basic)-1.)+1), np.dot(r, m_basic)-1.))))/r
#dphas = np.dot(np.array(np.hstack((np.NaN, np.diff(phas)))), r)/2./np.pi
plt.figure(1.)
plt.clf
#plt.hold(off)
plt.subplot(3., 1., 1.)
plt.plot(tscale1, np.array(np.hstack((0., np.abs(uamp), 0.))), 'linewidth', 1.5)
plt.ylabel(' Amplitude ')
plt.axis(np.array(np.hstack((-np.inf, np.inf, 0., np.dot(1.2, amax(np.abs(uamp)))))))
执行代码时,绘图错误为: ---> 66 plt.plot(tscale1,np.array(np.hstack((0。,np.abs(uamp),0。))),'linewidth',1.5) ValueError:数组必须具有相同的维数
输入如下: np.mat([1,2,3]) 0 1 100 1 10
答案 0 :(得分:0)
检查两个输入数组的形状为plot
in
plt.plot(tscale1, np.array(np.hstack((0., np.abs(uamp), 0.))), ...)