Last active
December 30, 2019 14:55
-
-
Save tovask/5b19b11e48b40e39fc3a3e6603a538e7 to your computer and use it in GitHub Desktop.
homework for signals & systems 2
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
function log(a){console.log(a);};log("\n\n--- start ---\n"); | |
function printmatrix(m){ | |
var ki=""; | |
if( ( typeof m ) === "number" ){ | |
return m; | |
} | |
ki+="{"; | |
for(var i=0;i<m.length;i++){ | |
ki+=(i==0?" ":", "); | |
if( ( typeof m[i] ) === "number" ){ | |
ki+=Math.round(m[i]*100000)/100000; | |
}else{ | |
ki+=printmatrix(m[i]); | |
} | |
}; | |
ki+=" }"; | |
return ki; | |
} | |
var A,B,C,D; | |
var a,b,c,d; | |
a = 0.4; | |
b = -2; | |
c = 0.8; | |
d = 0.5; | |
c = -2; | |
A = [ [ 1+a*c, 0, a*d ], [ 2+a*c, 0, a*d ], [ b*(2+a*c), 0, 1+a*b*d ] ]; | |
B = [ a, a, a*b ]; | |
C = [ b*(2+a*c), 1, 2+a*b*d ]; | |
D = a*b; | |
log("A mátrix: "+printmatrix(A)); | |
// sajátértékek: | |
// http://www.wolframalpha.com/input/?i=eigenvalues+{+{+0.2,+0,+0.2+},+{+1.2,+0,+0.2+},+{+-2.4,+0,+0.6+}+} | |
// impulzus válasz lépegetéssel: | |
var x1=[],x2=[],x3=[],w=[]; | |
x1[0]=x2[0]=x3[0]=0; | |
for(var i=0;i<10;i++){ | |
w[i] = C[0]*x1[i] + C[1]*x2[i] + C[2]*x3[i] + D*(i==0?1:0); | |
x1[i+1] = A[0][0]*x1[i] + A[0][1]*x2[i] + A[0][2]*x3[i] + B[0]*(i==0?1:0); | |
x2[i+1] = A[1][0]*x1[i] + A[1][1]*x2[i] + A[1][2]*x3[i] + B[1]*(i==0?1:0); | |
x3[i+1] = A[2][0]*x1[i] + A[2][1]*x2[i] + A[2][2]*x3[i] + B[2]*(i==0?1:0); | |
} | |
log("Impulzus válasz lépegetve:") | |
log(printmatrix(w)); | |
// impulzus válasz analitikusan: | |
// c1 és c2: http://www.wolframalpha.com/input/?i=a%2Bb%3D-1.792,+-0.7296%3Da*%28+0.4%2B0.663325+*I+%29%2Bb*%28+0.4-0.663325+*I+%29 | |
// imp vál anal: http://www.wolframalpha.com/input/?i=plot+0.896052*0.774^%28k%29*2*cos%28+3.1308+%2B+1.02816*k%29,+0%3Ck%3C10 | |
function impval(k){ | |
if(k==0){ | |
return -0.8; | |
} | |
if(k==1){ | |
return -1.84; | |
} | |
k = k-2; | |
return 0.896052*Math.pow(0.774,k)*2*Math.cos( 3.1308 + 1.02816*k) | |
} | |
w=[]; | |
for(var i=0;i<10;i++){ | |
w[i] = impval(i); | |
} | |
log("Impulzus válasz analitikuasn:") | |
log(printmatrix(w)); | |
// gerjesztés: | |
var s=[]; | |
f = 3; | |
g = 1.2; | |
p = -10/13; | |
for(var i=0;i<5;i++){ | |
s[i] = f + g*Math.pow(p,i); | |
} | |
log("Gerjesztés:"); | |
log(printmatrix(s)); | |
var y=[]; | |
// konvolóció: | |
for(var k=0;k<5;k++){ | |
y[k] = 0; | |
for(var n=0;n<=k;n++){ | |
y[k] += s[n]*w[k-n]; | |
} | |
} | |
log("Válasz:"); | |
log(printmatrix(y)); | |
/** Kimenet: | |
Impulzus válasz lépegetve: | |
{ -0.8, -1.84, -1.792, -0.7296, 0.49152, 0.83098, 0.36987, -0.20269, -0.38407, -0.18564 } | |
Impulzus válasz analitikuasn: | |
{ -0.8, -1.84, -1.792, -0.72906, 0.49074, 0.82906, 0.36874, -0.20191, -0.3823, -0.18465 } | |
Gerjesztés: | |
{ 4.2, 2.07692, 3.71006, 2.4538, 3.42015 } | |
Válasz: | |
{ -3.36, -9.38954, -14.31598, -15.57346, -13.35262 } | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment