Simulation d'un PAR sur Matlab

rianis24 Messages postés 1 Date d'inscription   Statut Membre Dernière intervention   -  
 rlo -
Bonjour,
j'ai un programme a simuler sur Matlab, il s'agit d'un modèle autoregressif périodiquement corrélé, pour faciliter la tache je vais vous donner le programme il est presque fini, j'ai just un problème quand je choisi "fi= sqrt(3)" ça ne marche pas, sachant que le choix de fi est seulement 0 ou 1 ou sqrt(3)
voici le programme, j'aimerais avoir votre aide le plutôt possible:

function [y,u] = genercomplex
fi = input('fi est:');
u=randn(200,1);
u=u';
y= 0;
y(1)= u(1);
y(2)= y(1) + 0.8*(y(1))+u(2);
for tau= 1:99
if fi==0
y(1+2*tau)= y(1+2*(tau-1))+0.5*(y(2+2*(tau-1))-y(1+2*(tau-1)))+u(1+2*(tau));
y(2+2*tau)= y(2+2*(tau-1))+ 0.8*(y(1+2*tau)-y(2+2*(tau-1)))+u(2+2*tau);
end
if fi==1
y(1+2*tau)= -y(2+2*(tau-1))+y(1+2*(tau-1))+0.5*(y(2+2*(tau-1))-y(1+2*(tau-1)))+u(1+2*(tau));
y(2+2*tau)= -y(1+2*tau)+y(2+2*(tau-1))+ 0.8*(y(1+2*tau)-y(2+2*(tau-1)))+u(2+2*tau);
end
if fi== sqrt(3)
y(1+2*(tau))= -fi* (y(2+2*(tau-1)))+y(1+2*(tau-1))+0.5*(y(2+2*(tau-1))-fi* y(1+2*(tau-1))+ y(2+2*(tau-2)))+u(1+2*(tau));
y(2+2*(tau))= -fi* (y(1+2*(tau)))+y(2+2*(tau-1))+ 0.8*(y(1+2*(tau))- fi* y(2+2*(tau-1))+y(1+2*(tau-1)))+u(2+2*(tau));
end
end
plot(y)
end

1 réponse

rlo
 
sans regarder en détail ton codage, je dirais que faire un test sur des réels avec un simple test d'égalité est une grosse bêtise (classique d'ailleurs), on teste plutot abs(fi - sqrt(3))<epsilon avec epsilon la précision de calcul
tu peux essayer avec la calculatrice windows (pourrie) : 2-racine(2^2) pour avoir une surprise
0