這是javascript。對Go進行適當的更改。我沒有測試過所有東西,只是將數學方程式轉換成代碼。如果有錯誤,請更正答案。
var pi = 3.14;
var blackmann = function(N){
var a = 0.16;
var a0 = (1-a)/2, a1 = 1/2, a2 = a/2;
var w = [];
for (var i=0; i<N, i++){
w[i] = a0 - a1*Math.cos(2*pi*i/N) - a2*Math.cos(4*pi*i/N);
}
return w;
}
var fft = function(x, K){
var X1 = [], X2 = [];
var N = x.length;
// X1 for the real spectrum, X2 for the imaginary part.
// For magnitude spectrum take |X1^2 + X2^2|
// For a K point fft
for (var k=0; k<K; k++){
for (var n=0; n<N; n++){
X1[k] = Math.cos(2*pi*n/N);
X2[k] = Math.sin(-2*pi*n/N);
}
}
return {"real":X1, "img":X2}
}
var smooting = function(x){
var s = [], t = 0.16
s[0] = x[0];
for (var i=1; i<x.length; i++){
s = t*s[i-1] + (1-t)*x[i]
}
return s
}
var decibel = function(X){
var Y = [];
for (var i =0;i<X.length(); i++){
Y[i] = Math.log10(Math.abs(X[i]));
}
return Y;
}
嗨非常感謝你,我會測試。 – Aron
我有一個問題,你可以在fft中稍微解釋一下K? – Aron
詢問DSP stachexchange – TheChetan