-1
$\begingroup$

I want to simulate short term white noise with Yuler and Burg. It's said that it can give better results than Gauss-Markov. The problem is that each time the series diverge. Do you think that I made a mistake in my code Burg

import numpy as np
import matplotlib.pyplot as plt
import pywt
from scipy import signal
from spectrum import *
from pylab import *


def simulate_noise_burg(self,x,ordre):#x = data series
    var=numpy.var(x)
    noise = np.random.normal(0, var**0.5, len(x))
    ar, variance, coeff_reflection = arburg(x, ordre)
    i=0
    tmp_ar=[]
    tmp_coef=[]
    while i<len(ar):
        tmp_ar.append(ar[i].real)
        tmp_coef.append(coeff_reflection[i].real)
        i+=1

    last_elements=np.array(tmp_ar)
    coeff_reflection=np.array(tmp_coef)

    result=[]
    i=0
    new_element=0
    while i<len(x): 
        new_element= last_elements.dot(coeff_reflection)+ noise[i]
        resultat.append(float(new_element))
        j=1
        while j<len(last_elements):
            last_elements[j]=last_elements[j-1]
            j+=1
        last_elements[0]=new_element
        i+=1
    return result

Yuler

import numpy as np
import matplotlib.pyplot as plt
import pywt
from scipy import signal
from spectrum import *
from pylab import *


def simulate_noise_yuler (self,x,ordre):#x = data series
    var=np.var(x)
    noise = np.random.normal(0, var**0.5, len(x))
    ar, variance, coeff_reflection = aryule(x, ordre)

    last_elements=np.array(ar)

    tmp_coef=[]
    i=0
    while i<len(coeff_reflection):
        tmp_coef.append([coeff_reflection[i]])
        i+=1
    coef=np.array(tmp_coef)

    result=[]
    i=0
    new_element=0
    while i<len(x): 
        new_element= last_elements.dot(coef)+ noise[i]
        resultat.append(float(new_element))
        j=1
        while j<len(last_elements):
            last_elements[j]=last_elements[j-1]
            j+=1
        last_elements[0]=new_element
        i+=1
    return result
$\endgroup$
-1
$\begingroup$

Yuler code :

    def simulate_noise_YULER (self,data_to_simulat,ordre):
    ar, var, coeff_reflection = aryule(data_to_simulat, ordre)
    noise = np.random.normal(0, var**0.5, len(data_to_simulat))

    ar=np.array(ar)
    elements=np.array([0]*ar.size)
    result=[]
    i=0
    new_element=0
    while i<len(data_to_simulat): 
        new_element= elements.dot(ar)+ noise[i]
        result.append(float(new_element))
        j=0
        while j<len(elements)-1:
            elements[j+1]=elements[j]
            j+=1
        elements[0]=new_element
        i+=1
    return result

and Burg :

    def simulate_noise_BURG(self,data_to_simulat,ordre):
    ar, var, coeff_reflection = arburg(data_to_simulat, ordre)
    noise = np.random.normal(0, var**0.5, len(data_to_simulat))

    i=0
    tmp_ar=[]
    while i<len(ar):
        tmp_ar.append(ar[i].real)
        i+=1

    ar=np.array(tmp_ar)

    elements=np.array([0]*ar.size)

    result=[]
    new_element=0
    i=0

    while i<len(data_to_simulat): 
        new_element= elements.dot(ar)+ noise[i]
        result.append(float(new_element))
        j=0
        while j<len(elements)-1:
            elements[j+1]=elements[j]
            j+=1
        elements[0]=new_element
        i+=1

    return result
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.