新聞中心
如何實現(xiàn)64點FFT?越詳細越好!
matlab實現(xiàn)的代碼:
成都創(chuàng)新互聯(lián)公司主要從事成都網(wǎng)站設計、網(wǎng)站建設、網(wǎng)頁設計、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務。立足成都服務上黨,十年網(wǎng)站建設經(jīng)驗,價格優(yōu)惠、服務專業(yè),歡迎來電咨詢建站服務:13518219792
x=importdata('aa.txt') %從aa.txt文件中讀取數(shù)據(jù),64點FFT就取64點數(shù)據(jù)
n=[1:64]; %64個數(shù)據(jù)
N=64;
y=fft(x); %進行FFT計算
%輸出y
M=abs(y); %取幅值
M(1)=M(1)/2;
plot(n,2*M/N); %繪制幅頻圖,
title('幅頻相應');
xlabel('頻率');
ylabel('幅度');
如果要單片機實現(xiàn)的話,cortex及ARM有相應的庫函數(shù),但是要注意采樣率,采樣周期與信號周期的關系,頻譜泄露的影響。
java中如何對arm音頻文件進行FFT轉(zhuǎn)換?
首先要先把arm音頻解碼后,分幀處理(如128個樣點),然后用fft函數(shù)就可以了。
我想問一下 java 中沒有有Complex 這個變量,是需要自己定義嗎?可是我看有些代碼是直接用的。代碼如下
從你的問題描述看你是問是否有一個復數(shù)類型complex,我查了一下沒有,都是自己定義的。下面的代碼你可以參考:
/******************************************************************************
*??Compilation:??javac?Complex.java
*??Execution:????java?Complex
*
*??Data?type?for?complex?numbers.
*
*??The?data?type?is?"immutable"?so?once?you?create?and?initialize
*??a?Complex?object,?you?cannot?change?it.?The?"final"?keyword
*??when?declaring?re?and?im?enforces?this?rule,?making?it?a
*??compile-time?error?to?change?the?.re?or?.im?instance?variables?after
*??they've?been?initialized.
*
*??%?java?Complex
*??a????????????=?5.0?+?6.0i
*??b????????????=?-3.0?+?4.0i
*??Re(a)????????=?5.0
*??Im(a)????????=?6.0
*??b?+?a????????=?2.0?+?10.0i
*??a?-?b????????=?8.0?+?2.0i
*??a?*?b????????=?-39.0?+?2.0i
*??b?*?a????????=?-39.0?+?2.0i
*??a?/?b????????=?0.36?-?1.52i
*??(a?/?b)?*?b??=?5.0?+?6.0i
*??conj(a)??????=?5.0?-?6.0i
*??|a|??????????=?7.810249675906654
*??tan(a)???????=?-6.685231390246571E-6?+?1.0000103108981198i
*
******************************************************************************/
import?java.util.Objects;
public?class?Complex?{
private?final?double?re;???//?the?real?part
private?final?double?im;???//?the?imaginary?part
//?create?a?new?object?with?the?given?real?and?imaginary?parts
public?Complex(double?real,?double?imag)?{
re?=?real;
im?=?imag;
}
//?return?a?string?representation?of?the?invoking?Complex?object
public?String?toString()?{
if?(im?==?0)?return?re?+?"";
if?(re?==?0)?return?im?+?"i";
if?(im???0)?return?re?+?"?-?"?+?(-im)?+?"i";
return?re?+?"?+?"?+?im?+?"i";
}
//?return?abs/modulus/magnitude
public?double?abs()?{
return?Math.hypot(re,?im);
}
//?return?angle/phase/argument,?normalized?to?be?between?-pi?and?pi
public?double?phase()?{
return?Math.atan2(im,?re);
}
//?return?a?new?Complex?object?whose?value?is?(this?+?b)
public?Complex?plus(Complex?b)?{
Complex?a?=?this;?????????????//?invoking?object
double?real?=?a.re?+?b.re;
double?imag?=?a.im?+?b.im;
return?new?Complex(real,?imag);
}
//?return?a?new?Complex?object?whose?value?is?(this?-?b)
public?Complex?minus(Complex?b)?{
Complex?a?=?this;
double?real?=?a.re?-?b.re;
double?imag?=?a.im?-?b.im;
return?new?Complex(real,?imag);
}
//?return?a?new?Complex?object?whose?value?is?(this?*?b)
public?Complex?times(Complex?b)?{
Complex?a?=?this;
double?real?=?a.re?*?b.re?-?a.im?*?b.im;
double?imag?=?a.re?*?b.im?+?a.im?*?b.re;
return?new?Complex(real,?imag);
}
//?return?a?new?object?whose?value?is?(this?*?alpha)
public?Complex?scale(double?alpha)?{
return?new?Complex(alpha?*?re,?alpha?*?im);
}
//?return?a?new?Complex?object?whose?value?is?the?conjugate?of?this
public?Complex?conjugate()?{
return?new?Complex(re,?-im);
}
//?return?a?new?Complex?object?whose?value?is?the?reciprocal?of?this
public?Complex?reciprocal()?{
double?scale?=?re*re?+?im*im;
return?new?Complex(re?/?scale,?-im?/?scale);
}
//?return?the?real?or?imaginary?part
public?double?re()?{?return?re;?}
public?double?im()?{?return?im;?}
//?return?a?/?b
public?Complex?divides(Complex?b)?{
Complex?a?=?this;
return?a.times(b.reciprocal());
}
//?return?a?new?Complex?object?whose?value?is?the?complex?exponential?of?this
public?Complex?exp()?{
return?new?Complex(Math.exp(re)?*?Math.cos(im),?Math.exp(re)?*?Math.sin(im));
}
//?return?a?new?Complex?object?whose?value?is?the?complex?sine?of?this
public?Complex?sin()?{
return?new?Complex(Math.sin(re)?*?Math.cosh(im),?Math.cos(re)?*?Math.sinh(im));
}
//?return?a?new?Complex?object?whose?value?is?the?complex?cosine?of?this
public?Complex?cos()?{
return?new?Complex(Math.cos(re)?*?Math.cosh(im),?-Math.sin(re)?*?Math.sinh(im));
}
//?return?a?new?Complex?object?whose?value?is?the?complex?tangent?of?this
public?Complex?tan()?{
return?sin().divides(cos());
}
//?a?static?version?of?plus
public?static?Complex?plus(Complex?a,?Complex?b)?{
double?real?=?a.re?+?b.re;
double?imag?=?a.im?+?b.im;
Complex?sum?=?new?Complex(real,?imag);
return?sum;
}
//?See?Section?3.3.
public?boolean?equals(Object?x)?{
if?(x?==?null)?return?false;
if?(this.getClass()?!=?x.getClass())?return?false;
Complex?that?=?(Complex)?x;
return?(this.re?==?that.re)??(this.im?==?that.im);
}
//?See?Section?3.3.
public?int?hashCode()?{
return?Objects.hash(re,?im);
}
//?sample?client?for?testing
public?static?void?main(String[]?args)?{
Complex?a?=?new?Complex(5.0,?6.0);
Complex?b?=?new?Complex(-3.0,?4.0);
StdOut.println("a????????????=?"?+?a);
StdOut.println("b????????????=?"?+?b);
StdOut.println("Re(a)????????=?"?+?a.re());
StdOut.println("Im(a)????????=?"?+?a.im());
StdOut.println("b?+?a????????=?"?+?b.plus(a));
StdOut.println("a?-?b????????=?"?+?a.minus(b));
StdOut.println("a?*?b????????=?"?+?a.times(b));
StdOut.println("b?*?a????????=?"?+?b.times(a));
StdOut.println("a?/?b????????=?"?+?a.divides(b));
StdOut.println("(a?/?b)?*?b??=?"?+?a.divides(b).times(b));
StdOut.println("conj(a)??????=?"?+?a.conjugate());
StdOut.println("|a|??????????=?"?+?a.abs());
StdOut.println("tan(a)???????=?"?+?a.tan());
}
}
FFT的公式是什么和算法是怎樣實現(xiàn)
二維FFT相當于對行和列分別進行一維FFT運算。具體的實現(xiàn)辦法如下:
先對各行逐一進行一維FFT,然后再對變換后的新矩陣的各列逐一進行一維FFT。相應的偽代碼如下所示:
for (int i=0; iM; i++)
FFT_1D(ROW[i],N);
for (int j=0; jN; j++)
FFT_1D(COL[j],M);
其中,ROW[i]表示矩陣的第i行。注意這只是一個簡單的記法,并不能完全照抄。還需要通過一些語句來生成各行的數(shù)據(jù)。同理,COL[i]是對矩陣的第i列的一種簡單表示方法。
所以,關鍵是一維FFT算法的實現(xiàn)。下面討論一維FFT的算法原理。
【1D-FFT的算法實現(xiàn)】
設序列h(n)長度為N,將其按下標的奇偶性分成兩組,即he和ho序列,它們的長度都是N/2。這樣,可以將h(n)的FFT計算公式改寫如下 :
(A)
由于
所以,(A)式可以改寫成下面的形式:
按照FFT的定義,上面的式子實際上是:
其中,k的取值范圍是 0~N-1。
我們注意到He(k)和Ho(k)是N/2點的DFT,其周期是N/2。因此,H(k)DFT的前N/2點和后N/2點都可以用He(k)和Ho(k)來表示
文章標題:fft的java代碼 fft 代碼
文章URL:http://ef60e0e.cn/article/ddjegci.html