-
Notifications
You must be signed in to change notification settings - Fork 2
/
LPC.js
206 lines (165 loc) · 19.7 KB
/
LPC.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
// LPC library for speech processing
// Developed by Gerard Llorach and Mattes Ohlenbusch
// 2020
// Temporal arrays and useful variables
let tempArray = [];
let tempBuffer = [];
let acorr = [];
// LPC calculation based on the Levinson algorithm, described in:
/*Dutoit, T., 2004, May. Unusual teaching short-cuts to the Levinson
and lattice algorithms. In 2004 IEEE International Conference on Acoustics,
Speech, and Signal Processing (Vol. 5, pp. V-1029). IEEE.
*/
export function calculateLPC(inBuffer, inM, inLpcCoeff, inKCoeff){
// Levinson's method
// Input variables
let lpcCoeff = inLpcCoeff || [];
let kCoeff = inKCoeff || [];
let M = inM || 12;
// Autocorrelation values
// Reuse acorr array
let phi = acorr || [];//[] makes garbage
for (let i = 0; i<M+1; i++){
phi[i] = autoCorr(inBuffer, i);
}
// M = 1
let a1_m = -phi[1] / phi[0];
kCoeff[0] = a1_m;
// Iterate to calculate coefficients
lpcCoeff[0] = 1
lpcCoeff[1] = a1_m;
let tempCoeff = tempArray || []; // Reuse tempArray array
tempCoeff.splice(0);
tempCoeff[0] = 1;
tempCoeff[1] = a1_m;
let mu = 0;
let alpha = 0;
let k = 0;
for (let m = 0; m < M-1; m++){
mu = 0;
alpha = 0;
// Calculate mu and alpha
for (let i = 0; i<m+2; i++){
mu += lpcCoeff[i]*phi[m+2-i];
alpha += lpcCoeff[i]*phi[i];
}
k = - mu / alpha;
kCoeff[m+1] = k;
// Calculate new coefficients
lpcCoeff[m+2] = 0;
for (let i = 1; i<m+3; i++){
tempCoeff[i] = lpcCoeff[i] + lpcCoeff[m+2-i]*k;
}
// Assign temp values (if we do tempCoeff.slice() we lose the array reference)
for (let i = 0; i<tempCoeff.length; i++)
lpcCoeff[i] = tempCoeff[i];
}
return lpcCoeff;
}
// Autocorrelation function
export function autoCorr(buffer, delay){
let value = 0;
for (let i = 0; i< buffer.length - delay; i++){
// Because autocorrelation is symmetric, I use "i + delay", not "i - delay"
value += buffer[i] * buffer[(i + delay)];
}
return value;
}
// Recalulcate LPC using new K coefficients
export function recalculateLPC(lpcCoeff, kCoeff){
let M = lpcCoeff.length-1;
// Reuse array
let tempCoeff = tempArray || []; // Reuse tempArray array
tempCoeff.splice(0);
tempCoeff[0] = 1;
// Recalulate coefficients
for (let m = 0; m < M; m++){
lpcCoeff[m+1] = 0;
for (let i = 1; i<m+2; i++){
tempCoeff[i] = lpcCoeff[i] + kCoeff[m]*lpcCoeff[m+1-i];
}
// Assign values to reusable lpc array
for (let i = 0; i<tempCoeff.length; i++)
lpcCoeff[i] = tempCoeff[i];
}
return lpcCoeff;
}
// Calculate error signal
export function calculateErrorSignal(inBuffer, lpcCoeff, inErrorSignal){
let errorSignal = inErrorSignal || new Float32Array(inBuffer.length);
errorSignal.fill(0); // Reset erroBuffer
let tBuffer = tempBuffer || [];
tBuffer.splice(0);
for (let j = 0; j<lpcCoeff.length; j++){
tBuffer[j] = 0;
}
// Convolution
for (let i = 0; i< inBuffer.length; i++){
tBuffer.unshift(inBuffer[i]); // Array at end looks like x[n], ..., x[2], x[1], x[0]
tBuffer.pop();
for (let j = 0; j<lpcCoeff.length; j++){
errorSignal[i] += tBuffer[j]*lpcCoeff[j]; // a[0]*x[n] + a[1]*x[n-1] + a[2]*x[n-2] ... + a[M]*x[n-M]
}
}
return errorSignal;
}
export function IIRFilter(excitationSignal, lpcCoeff, inOutBuffer){
// IIR Filter
// y[n] = b[0]*x[n]/a[0] - a[1]*y[n-1] - a[2]*y[n-2] ... - a[M]*y[n-M]
// In our case, b[0] and a[0] are 1, therefore:
// y[n] = x[n] - a[1]*y[n-1] - a[2]*y[n-2] ... - a[M]*y[n-M]
let outBuffer = inOutBuffer || new Float32Array(excitationSignal.length);
let M = lpcCoeff.length - 1;
let y_prev = tempArray || [];// As many zeros as M;
y_prev.splice(0); // Empty array
for (let i=0; i < M; i++){
y_prev[i] = 0;
//y_prev[i] = outBuffer[outBuffer.length - M + i]; // Use samples from previous-previous frame?
}
// Iterate for each sample. O(fSize*M)
for (let i = 0; i< excitationSignal.length; i++){
outBuffer[i] = excitationSignal[i]; // x[n]
for (let j = 1; j<M+1; j++){
outBuffer[i] -= y_prev[j-1]*lpcCoeff[j]; // - a[1]*y[n-1] - a[2]*y[n-2] ... - a[M]*y[n-M]
}
y_prev.unshift(outBuffer[i]);
y_prev.pop();
}
return outBuffer;
}
/*
// Test code
// Test signal
var testBuffer = [-0.028351,-0.032048,-0.034923,-0.035744,-0.037387,-0.038619,-0.040673,-0.04437,-0.048066,-0.05053,-0.052995,-0.054638,-0.05628,-0.057102,-0.059155,-0.060798,-0.060388,-0.057102,-0.050941,-0.042727,-0.034102,-0.026298,-0.020548,-0.017673,-0.016851,-0.017262,-0.018905,-0.020959,-0.023834,-0.026298,-0.028351,-0.028351,-0.025887,-0.020548,-0.012333,-0.0020654,0.009024,0.019292,0.029149,0.038596,0.048042,0.0579,0.068578,0.078436,0.088293,0.097329,0.10472,0.11129,0.11704,0.12238,0.1269,0.12854,0.1269,0.12156,0.1117,0.09815,0.082132,0.06365,0.043114,0.020113,-0.0057619,-0.033691,-0.063263,-0.094067,-0.12241,-0.1491,-0.17292,-0.19305,-0.2103,-0.22262,-0.23043,-0.23412,-0.23207,-0.22632,-0.21728,-0.20619,-0.19428,-0.18237,-0.16964,-0.15526,-0.13884,-0.11994,-0.099406,-0.078049,-0.057102,-0.036977,-0.018905,-0.0024761,0.010667,0.020935,0.028328,0.032024,0.032435,0.032435,0.02956,0.027917,0.026274,0.025864,0.027096,0.031614,0.039007,0.049275,0.063239,0.079668,0.1002,0.12279,0.14867,0.17619,0.20699,0.23985,0.27558,0.31501,0.3569,0.3988,0.43946,0.47437,0.50066,0.51626,0.51708,0.50394,0.47355,0.42837,0.36964,0.30105,0.22588,0.14908,0.073507,0.0024525,-0.062441,-0.12035,-0.1721,-0.21728,-0.25753,-0.29409,-0.32777,-0.35857,-0.3865,-0.41032,-0.42757,-0.43702,-0.43414,-0.41771,-0.38609,-0.33886,-0.27807,-0.20866,-0.13309,-0.056691,0.014363,0.076793,0.12567,0.16058,0.18071,0.18851,0.18687,0.18071,0.1729,0.16551,0.16099,0.15935,0.15812,0.15565,0.14826,0.13388,0.11088,0.078846,0.040239,-0.0032976,-0.046423,-0.086263,-0.1183,-0.14048,-0.15116,-0.15198,-0.14335,-0.12939,-0.11378,-0.098585,-0.087495,-0.080102,-0.076816,-0.076406,-0.075584,-0.072299,-0.064084,-0.05053,-0.031637,-0.0086369,0.016006,0.038596,0.055846,0.065703,0.064061,0.051328,0.028328,-0.0020654,-0.036977,-0.071477,-0.10146,-0.12364,-0.13637,-0.14048,-0.13637,-0.12569,-0.11173,-0.098174,-0.087084,-0.081745,-0.081334,-0.086674,-0.094477,-0.10351,-0.10885,-0.10926,-0.10146,-0.087084,-0.064084,-0.036566,-0.0065833,0.022578,0.048042,0.067346,0.078846,0.082543,0.077204,0.065703,0.049275,0.030381,0.01231,-0.0045297,-0.018083,-0.029173,-0.038619,-0.047245,-0.056691,-0.066548,-0.077227,-0.088317,-0.10064,-0.11173,-0.122,-0.12939,-0.13391,-0.13309,-0.12775,-0.11707,-0.10228,-0.085031,-0.066959,-0.048477,-0.031227,-0.016441,-0.004119,0.0057383,0.012721,0.018881,0.024221,0.031203,0.040649,0.051328,0.063239,0.074739,0.082954,0.08665,0.084597,0.07515,0.059132,0.037774,0.01231,-0.014798,-0.038619,-0.057923,-0.069423,-0.071888,-0.065727,-0.051763,-0.032869,-0.010691,0.011078,0.031203,0.048042,0.062418,0.073096,0.0809,0.087061,0.092811,0.098972,0.10842,0.12074,0.13758,0.15688,0.17701,0.19549,0.2111,0.22054,0.22424,0.22054,0.2111,0.19754,0.18276,0.17126,0.16633,0.17044,0.18358,0.20288,0.2226,0.23533,0.23533,0.21808,0.18194,0.13101,0.070632,0.0082026,-0.050941,-0.10146,-0.14048,-0.16717,-0.18278,-0.18976,-0.191,-0.19018,-0.19223,-0.19716,-0.20496,-0.21276,-0.21605,-0.21318,-0.20003,-0.17826,-0.1491,-0.1146,-0.075995,-0.033691,0.011899,0.060775,0.11006,0.15565,0.19179,0.21479,0.22178,0.21397,0.19426,0.16797,0.13922,0.11253,0.090347,0.072686,0.059543,0.050096,0.041882,0.032024,0.019703,0.003274,-0.017673,-0.039441,-0.057923,-0.069423,-0.071888,-0.064906,-0.051352,-0.037387,-0.027119,-0.02753,-0.037387,-0.055048,-0.077227,-0.098585,-0.11419,-0.12446,-0.12939,-0.1298,-0.12734,-0.12282,-0.11953,-0.11789,-0.11953,-0.12528,-0.1335,-0.14171,-0.14582,-0.14376,-0.13391,-0.11666,-0.094067,-0.069423,-0.045191,-0.021369,0.0012204,0.023399,0.045989,0.068578,0.090347,0.11129,0.12813,0.14045,0.14908,0.1536,0.15565,0.15319,0.14703,0.13594,0.11992,0.1002,0.077204,0.052971,0.028739,0.0053276,-0.015619,-0.034102,-0.048887,-0.058745,-0.063673,-0.065727,-0.066548,-0.069423,-0.075174,-0.083799,-0.094888,-0.10433,-0.11008,-0.10926,-0.10064,-0.083799,-0.059977,-0.031637,-0.0016547,0.025864,0.048864,0.065293,0.074739,0.078025,0.076793,0.073918,0.071453,0.070632,0.069811,0.070632,0.070221,0.068168,0.063239,0.054614,0.043935,0.030792,0.017238,0.0036847,-0.0094584,-0.020137,-0.028762,-0.036155,-0.042727,-0.049709,-0.057513,-0.067781,-0.078049,-0.089549,-0.10064,-0.11214,-0.12241,-0.13103,-0.13596,-0.13637,-0.13062,-0.11912,-0.1031,-0.083388,-0.06162,-0.040262,-0.020137,-0.0024761,0.011488,0.022578,0.031614,0.040239,0.050096,0.062828,0.078846,0.096507,0.11417,0.1306,0.1421,0.14949,0.15278,0.15195,0.1499,0.14785,0.14579,0.14497,0.1421,0.13717,0.12772,0.11376,0.094454,0.070632,0.042292,0.011078,-0.020959,-0.051763,-0.079281,-0.1031,-0.12158,-0.13432,-0.145,-0.15321,-0.16142,-0.16882,-0.17703,-0.18484,-0.19264,-0.1988,-0.20332,-0.20455,-0.20291];
var lpcMatlab = [1,-1.4948,0.21722,0.18926,0.12374,0.067671,0.0061364,-0.024856,-0.04672,-0.034917,-0.029394,0.0053483,0.066432];
var M = 12;
var lpcCoeff = calculateLPC(testBuffer, M);
var error = 0;
for (let i = 0; i<M+1; i++)
error += Math.pow(lpcCoeff[i]-lpcMatlab[i],2)
error = Math.sqrt(error);
console.log("Error is : " + error);
// Error signal
var errorSignalMatlab = [-0.028351,0.010333,0.006825,0.0041326,-0.0011146,-0.0029895,-0.0044934,-0.0053129,-0.0030231,-0.00018791,0.00029858,0.00063727,-0.0019543,-0.0017917,-0.0036958,-0.0028343,-0.00059119,0.0014335,0.0023356,0.0017955,-3.2288e-06,-0.0016999,-0.0031584,-0.0040534,-0.0032394,-0.0019039,-0.0016817,-0.0014373,-0.0023656,-0.0020657,-0.0020877,-0.00045817,0.00090602,0.0021569,0.0030019,0.0028951,0.0020907,0.00068509,0.0010848,0.0019158,0.0030515,0.0040749,0.0048067,0.0033431,0.0033382,0.002703,0.0018628,0.0026336,0.0033143,0.0041318,0.0040873,0.0019035,0.00033537,-0.00077399,-0.002092,-0.0021057,-0.0012242,-0.0014495,-0.0020742,-0.003683,-0.0056653,-0.0063692,-0.0067145,-0.0069935,-0.0040468,-0.0040921,-0.0037803,-0.0034507,-0.0044699,-0.0030137,-0.002487,-0.0023949,-0.00042123,-0.0011155,-0.0015848,-0.0026383,-0.0038076,-0.0046922,-0.0038553,-0.0023253,-0.0011777,-0.00027939,-0.00073877,-0.0016859,-0.0028829,-0.0031905,-0.0037489,-0.0029242,-0.0037003,-0.0035813,-0.0035567,-0.0045624,-0.0049149,-0.0024497,-0.0039382,-0.00097088,-0.00091103,0.0001119,0.0010433,0.0033402,0.0043998,0.0053292,0.0071942,0.0074836,0.0099221,0.0099026,0.011741,0.011871,0.014268,0.015001,0.016842,0.01939,0.020198,0.018972,0.018136,0.014375,0.010815,0.0079999,0.0030952,0.0013138,-0.0036393,-0.0053765,-0.0072213,-0.0071482,-0.0067555,-0.0046412,-0.0033637,-0.0017553,-0.00088072,-0.0004752,-0.0013073,-0.00095052,-0.0018877,-0.0030834,-0.0042151,-0.0048098,-0.0055114,-0.0053335,-0.0036888,-0.0025714,0.0016891,0.0046311,0.007736,0.010491,0.011355,0.0091294,0.00842,0.0059893,0.0016233,-0.0013242,-0.0059626,-0.0080281,-0.010097,-0.0099134,-0.0088206,-0.0055625,-0.0032349,-0.0019127,0.00021727,0.0012016,-8.3497e-05,-0.0010425,-0.003638,-0.0055481,-0.0072331,-0.0083867,-0.0073141,-0.0067128,-0.0033213,-0.001193,0.0021474,0.0043033,0.0062553,0.0058795,0.0064032,0.0044359,0.0018286,0.00050855,-0.0022302,-0.0023843,-0.0027784,-0.0025216,-0.00035922,0.0013203,0.0032923,0.0038051,0.0039498,0.0034216,0.0019663,-0.00075953,-0.0037204,-0.0057607,-0.010034,-0.011755,-0.012496,-0.011542,-0.010309,-0.0072233,-0.0038724,-0.00075532,0.0014061,0.0015486,0.0020948,0.0024581,0.0013628,-0.00086643,-0.0023388,-0.0052073,-0.0054794,-0.0067525,-0.0051499,-0.0045185,-0.00092691,0.00064283,0.0036616,0.0033317,0.0057421,0.0042423,0.0032402,0.0015582,-0.00017745,-0.0019998,-0.0037093,-0.0045175,-0.0067695,-0.0062601,-0.0062399,-0.0055022,-0.0033108,-0.0030565,-0.0016869,-0.0020494,-0.0028026,-0.0033359,-0.0043882,-0.003718,-0.0033593,-0.0027312,-0.003636,-0.0022791,-0.0026411,-0.0014788,-0.0013098,0.00096408,0.0013211,0.0025275,0.0024155,0.0014614,0.00031233,0.00035326,-0.00037667,-0.0013291,-0.0015032,-0.0015647,-0.0022917,-0.00098684,-0.00077236,0.0013905,0.0030568,0.0025369,0.0024341,0.0013211,-0.0013336,-0.0030664,-0.0044025,-0.0063635,-0.0067499,-0.0064119,-0.0062723,-0.0052272,-0.0012776,0.00056245,0.003732,0.0061588,0.0071485,0.0077271,0.006635,0.0062318,0.0042274,0.0035971,0.0027354,0.003541,0.0026116,0.0022527,0.0024879,0.0030084,0.0034234,0.0061099,0.00698,0.0092682,0.0089173,0.0079113,0.00607,0.0051955,0.0025856,0.0023687,0.00085461,0.0012704,0.0021804,0.0042208,0.008329,0.012439,0.016047,0.017565,0.015987,0.010884,0.003018,-0.0042516,-0.010423,-0.01428,-0.012888,-0.0094021,-0.0043009,-0.0011193,0.0014237,0.0025019,0.002559,0.0018435,0.00086663,0.00014026,-0.0012682,-0.0048161,-0.0052898,-0.0050931,-0.0026965,0.0016315,0.0036242,0.006972,0.0059761,0.0041657,0.0023778,0.0023813,0.0044942,0.0073453,0.010457,0.010164,0.0065614,-0.00031701,-0.0066901,-0.011852,-0.01285,-0.011004,-0.0064679,-0.0027334,0.00062234,0.0021953,0.0014736,0.00092354,0.00083624,-1.6132e-05,-0.0015579,-0.001748,-0.0026693,-0.0035339,-0.00091334,0.0033074,0.0075469,0.010137,0.010683,0.0078446,0.0011281,-0.0045524,-0.012117,-0.012734,-0.010437,-0.0067578,-0.0017175,0.0028153,0.0018228,-0.000671,-0.0031189,-0.00498,-0.0049104,-0.0061677,-0.0058368,-0.0064871,-0.0075962,-0.0070635,-0.0051758,-0.0011083,0.0018581,0.004029,0.0043079,0.0027801,-6.4597e-06,-0.0020424,-0.00095974,0.00050015,0.0029738,0.0051998,0.0055136,0.0043525,0.0035005,-3.5123e-05,-0.0017342,-0.0010631,-0.00069113,0.0011311,-0.00033027,-0.0008729,-0.0029083,-0.0043841,-0.0042439,-0.0041512,-0.002564,-0.0013318,-0.00079895,0.00030795,0.00030496,0.0013169,0.0030791,0.0042184,0.0030393,0.0012093,-0.0024103,-0.0044872,-0.0050339,-0.0048323,-0.0011124,0.001876,0.0049394,0.0066001,0.0073494,0.0068782,0.0053761,0.0035977,0.0006369,-0.0010057,-0.0024913,-0.0030934,-0.0027616,-0.0018884,4.287e-05,0.0015408,0.0022009,6.4846e-05,0.00047911,-0.0016342,-0.0023215,-0.002934,-0.0033904,-0.0017182,-0.0015405,-0.00012903,0.00010902,-0.00024261,0.0009639,0.00072785,-0.00030076,-0.0011089,-0.0023855,-0.0030796,-0.0048174,-0.0031479,-0.0037354,-0.0029132,-0.0039661,-0.0035799,-0.0034223,-0.0016339,-5.1574e-05,0.0023722,0.00339,0.0030659,0.0027658,0.0020513,0.00039112,-0.00010909,-0.00069613,-0.0017158,-0.0013425,-0.00057719,0.00091485,0.0027235,0.0047421,0.0058599,0.0048779,0.0033106,0.0022795,-0.0006986,-0.00027945,0.00068439,0.0012644,0.0039195,0.005601,0.0053951,0.0057171,0.0022904,0.00065047,-0.0020824,-0.0028834,-0.0038387,-0.0036835,-0.0043073,-0.0042079,-0.0034406,-0.0023972,-0.0010679,-0.00089815,0.00021325,0.0010793,-0.0019792,-0.0025797,-0.0045366,-0.004003,-0.0049561,-0.0042647,-0.0046968,-0.0039509,-0.0042632,-0.0034701,-0.0038045
];
var errSignal = calculateErrorSignal(testBuffer, lpcCoeff);
var error = 0;
for (let i = 0; i<errSignal.length; i++)
error += Math.pow(errSignal[i]-errorSignalMatlab[i],2)
error = Math.sqrt(error);
console.log("Error is : " + error);
// Synthesized signal (error signal filtered with LPC coeff)
var synthBufferMatlab = [-0.028351,-0.032048,-0.034923,-0.035744,-0.037387,-0.038619,-0.040673,-0.04437,-0.048066,-0.05053,-0.052995,-0.054638,-0.05628,-0.057102,-0.059155,-0.060798,-0.060388,-0.057102,-0.050941,-0.042727,-0.034102,-0.026298,-0.020548,-0.017673,-0.016851,-0.017262,-0.018905,-0.020959,-0.023834,-0.026298,-0.028351,-0.028351,-0.025887,-0.020548,-0.012333,-0.0020654,0.009024,0.019292,0.029149,0.038596,0.048042,0.0579,0.068578,0.078436,0.088293,0.097329,0.10472,0.11129,0.11704,0.12238,0.1269,0.12854,0.1269,0.12156,0.1117,0.09815,0.082132,0.06365,0.043114,0.020113,-0.0057619,-0.033691,-0.063263,-0.094067,-0.12241,-0.1491,-0.17292,-0.19305,-0.2103,-0.22262,-0.23043,-0.23412,-0.23207,-0.22632,-0.21728,-0.20619,-0.19428,-0.18237,-0.16964,-0.15526,-0.13884,-0.11994,-0.099406,-0.078049,-0.057102,-0.036977,-0.018905,-0.0024761,0.010667,0.020935,0.028328,0.032024,0.032435,0.032435,0.02956,0.027917,0.026274,0.025864,0.027096,0.031614,0.039007,0.049275,0.063239,0.079668,0.1002,0.12279,0.14867,0.17619,0.20699,0.23985,0.27558,0.31501,0.3569,0.3988,0.43946,0.47437,0.50066,0.51626,0.51708,0.50394,0.47355,0.42837,0.36964,0.30105,0.22588,0.14908,0.073507,0.0024525,-0.062441,-0.12035,-0.1721,-0.21728,-0.25753,-0.29409,-0.32777,-0.35857,-0.3865,-0.41032,-0.42757,-0.43702,-0.43414,-0.41771,-0.38609,-0.33886,-0.27807,-0.20866,-0.13309,-0.056691,0.014363,0.076793,0.12567,0.16058,0.18071,0.18851,0.18687,0.18071,0.1729,0.16551,0.16099,0.15935,0.15812,0.15565,0.14826,0.13388,0.11088,0.078846,0.040239,-0.0032976,-0.046423,-0.086263,-0.1183,-0.14048,-0.15116,-0.15198,-0.14335,-0.12939,-0.11378,-0.098585,-0.087495,-0.080102,-0.076816,-0.076406,-0.075584,-0.072299,-0.064084,-0.05053,-0.031637,-0.0086369,0.016006,0.038596,0.055846,0.065703,0.064061,0.051328,0.028328,-0.0020654,-0.036977,-0.071477,-0.10146,-0.12364,-0.13637,-0.14048,-0.13637,-0.12569,-0.11173,-0.098174,-0.087084,-0.081745,-0.081334,-0.086674,-0.094477,-0.10351,-0.10885,-0.10926,-0.10146,-0.087084,-0.064084,-0.036566,-0.0065833,0.022578,0.048042,0.067346,0.078846,0.082543,0.077204,0.065703,0.049275,0.030381,0.01231,-0.0045297,-0.018083,-0.029173,-0.038619,-0.047245,-0.056691,-0.066548,-0.077227,-0.088317,-0.10064,-0.11173,-0.122,-0.12939,-0.13391,-0.13309,-0.12775,-0.11707,-0.10228,-0.085031,-0.066959,-0.048477,-0.031227,-0.016441,-0.004119,0.0057383,0.012721,0.018881,0.024221,0.031203,0.040649,0.051328,0.063239,0.074739,0.082954,0.08665,0.084597,0.07515,0.059132,0.037774,0.01231,-0.014798,-0.038619,-0.057923,-0.069423,-0.071888,-0.065727,-0.051763,-0.032869,-0.010691,0.011078,0.031203,0.048042,0.062418,0.073096,0.0809,0.087061,0.092811,0.098972,0.10842,0.12074,0.13758,0.15688,0.17701,0.19549,0.2111,0.22054,0.22424,0.22054,0.2111,0.19754,0.18276,0.17126,0.16633,0.17044,0.18358,0.20288,0.2226,0.23533,0.23533,0.21808,0.18194,0.13101,0.070632,0.0082026,-0.050941,-0.10146,-0.14048,-0.16717,-0.18278,-0.18976,-0.191,-0.19018,-0.19223,-0.19716,-0.20496,-0.21276,-0.21605,-0.21318,-0.20003,-0.17826,-0.1491,-0.1146,-0.075995,-0.033691,0.011899,0.060775,0.11006,0.15565,0.19179,0.21479,0.22178,0.21397,0.19426,0.16797,0.13922,0.11253,0.090347,0.072686,0.059543,0.050096,0.041882,0.032024,0.019703,0.003274,-0.017673,-0.039441,-0.057923,-0.069423,-0.071888,-0.064906,-0.051352,-0.037387,-0.027119,-0.02753,-0.037387,-0.055048,-0.077227,-0.098585,-0.11419,-0.12446,-0.12939,-0.1298,-0.12734,-0.12282,-0.11953,-0.11789,-0.11953,-0.12528,-0.1335,-0.14171,-0.14582,-0.14376,-0.13391,-0.11666,-0.094067,-0.069423,-0.045191,-0.021369,0.0012204,0.023399,0.045989,0.068578,0.090347,0.11129,0.12813,0.14045,0.14908,0.1536,0.15565,0.15319,0.14703,0.13594,0.11992,0.1002,0.077204,0.052971,0.028739,0.0053276,-0.015619,-0.034102,-0.048887,-0.058745,-0.063673,-0.065727,-0.066548,-0.069423,-0.075174,-0.083799,-0.094888,-0.10433,-0.11008,-0.10926,-0.10064,-0.083799,-0.059977,-0.031637,-0.0016547,0.025864,0.048864,0.065293,0.074739,0.078025,0.076793,0.073918,0.071453,0.070632,0.069811,0.070632,0.070221,0.068168,0.063239,0.054614,0.043935,0.030792,0.017238,0.0036847,-0.0094584,-0.020137,-0.028762,-0.036155,-0.042727,-0.049709,-0.057513,-0.067781,-0.078049,-0.089549,-0.10064,-0.11214,-0.12241,-0.13103,-0.13596,-0.13637,-0.13062,-0.11912,-0.1031,-0.083388,-0.06162,-0.040262,-0.020137,-0.0024761,0.011488,0.022578,0.031614,0.040239,0.050096,0.062828,0.078846,0.096507,0.11417,0.1306,0.1421,0.14949,0.15278,0.15195,0.1499,0.14785,0.14579,0.14497,0.1421,0.13717,0.12772,0.11376,0.094454,0.070632,0.042292,0.011078,-0.020959,-0.051763,-0.079281,-0.1031,-0.12158,-0.13432,-0.145,-0.15321,-0.16142,-0.16882,-0.17703,-0.18484,-0.19264,-0.1988,-0.20332,-0.20455,-0.20291
];
var outsynth = IIRFilter(errSignal, lpcCoeff);
var error = 0;
for (let i = 0; i<outsynth.length; i++)
error += Math.pow(outsynth[i]-synthBufferMatlab[i],2)
error = Math.sqrt(error);
console.log("Error is : " + error);
// Error with original signal:
var error = 0;
for (let i = 0; i<outsynth.length; i++)
error += Math.pow(outsynth[i]-testBuffer[i],2)
error = Math.sqrt(error);
console.log("Error is : " + error);*/