I would like to plot the following function:
$$
\begin{align}
\Lambda(\delta\tau) &\equiv\ \chi(\delta\tau, 0)
= \frac{1}{T_i} \int_0^{T_i} a(t_0+t')a(t_0+t'+\delta\tau) dt' \\
&= \begin{cases}
1 - \frac{\left|\delta\tau\right|}{\tau_c}, &\left|\delta\tau\right| \le \tau_c(1+\frac{\tau_c}{T_i}) \\
-\frac{\tau_c}{T_i}, &\left|\delta\tau\right| \gt \tau_c(1+\frac{\tau_c}{T_i}) \\
\end{cases}
\end{align}
$$
which represents a simple triangular shape.
There is a conditional statement. My implementation uses a for loop as follows:
def waf_delay(delay_increment):
for d in delay_increment:
if np.abs(d) <= delay_chip*(1+delay_chip/integration_time):
yield 1 - np.abs(d)/delay_chip
else:
yield -delay_chip/integration_time;
integration_time = 1e-3 # seconds
delay_chip = 1/1.023e6 # seconds
x=np.arange(-5.0, 5.0, 0.1)
y=list(waf_delay(x))
plt.plot(x, y)
plt.show()
Is there a more correct way to transform an array based on a condition rather than just looping through it? Instead of having something like this:
def f(x_array): for x in x_array: if np.abs(x) <= 3: yield 1 - x/3 else: yield 0 x=np.arange(-5.0, 5.0, 0.1) y=list(f(x)) plt.plot(x, y) plt.show()
I would like to write something like this:
def f(x): if np.abs(x) <= 3: yield 1 - x/3 else: yield 0 x=np.arange(-5.0, 5.0, 0.1) plt.plot(x, f(x)) plt.show()
that could take an array.