P contains the poles, and Q contains the zeroes, or nills. In this post, I use only Q = 1.
The criterion for stability is that all roots of P is in the unit circle. To get a uniform sampling from the unit circle, we can sample an angle from a uniform distribution, and an absolute value from a triangle distribution (since the density must increase linearly with the absolute value). The code:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def poles(k): | |
""" | |
Generates k pairs of poles in the unit circle | |
Returns the resulting polynomial coefficients | |
""" | |
pol = np.array([1]) | |
for _ in range(k): | |
theta = np.random.random()*np.pi | |
r = np.random.random()**0.5 # to get uniform over area | |
coeffs = np.array([1, -2*np.cos(theta)*r, r**2]) | |
pol = np.convolve(pol, coeffs) # polynomial multiplication | |
return pol | |
def main(): | |
ar = poles(5) | |
ps = ArmaProcess(ar, [1]) | |
y = ps.generate_sample(1000) | |
plt.plot(y) | |
plt.show() |
![]() |
Random stable AR process from 5 pairs of poles. |
Inga kommentarer:
Skicka en kommentar