本文目录
- 怎么用matlab做傅里叶变换
- 如何在MATLAB里实现信号的快速傅里叶变换FFT
- 初学者,求教matlab中快速傅里叶变换如何编程序,非常感谢!
- 求个快速傅里叶变换的C语言程序
- 关于matlab的傅里叶变换的代码求解释
- 求基2、基4、基8FFT(快速傅里叶变换)的c语言程序,要能运行得出来的
- C语言 1024点快速傅里叶变换(FFT)程序,最好经过优化,执行速度快
怎么用matlab做傅里叶变换
这样用matlab做傅里叶变换:
1、我们使用matlab开发的傅立叶变换程序代码如下:
syms x
f = exp(-2*x^2); %our function
ezplot(f,[-2,2]) % plot of our function
FT = fourier(f) % Fourier transform
将其写入到我们的matlab程序模块中。
2、我们运行上面的傅立叶变换程序代码,将得出运行结果:FT = (2^(1/2)*pi^(1/2)*exp(-w^2/8))/2。
3、如果我们需要更高级的显示,我们修改上述代码即可,如使用ezplot(FT)作傅里叶变换折线图。
以上就是如何用matlab做傅里叶变换的解决步骤。
如何在MATLAB里实现信号的快速傅里叶变换FFT
代码:
1 N=8; %原离散信号有8点
2 n=[0:1:N-1] %原信号是1行8列的矩阵
3 xn=0.5.^n; %构建原始信号,为指数信号
4
5 w=[-800:1:800]*4*pi/800; %频域共-800----+800 的长度(本应是无穷,高频分量很少,故省去)
6 X=xn*exp(-j*(n’*w)); %求dtft变换,采用原始定义的方法,对复指数分量求和而得
7 subplot(311)
8 stem(n,xn);
9 title(’原始信号(指数信号)’);
10 subplot(312);
11 plot(w/pi,abs(X));
12 title(’DTFT变换’)
初学者,求教matlab中快速傅里叶变换如何编程序,非常感谢!
F=fourier(f,t,w)
自己编的话
function F = fuliye(varargin)
if nargin 》= 4
error(’symbolic:sym:fourier:errmsg1’,’FOURIER can take at most 3 input variables’);
end
f = sym(varargin{1});
var = findsym(f,1);
if isempty(var)
var = sym(’x’);
end
w_test = strcmp(char(var),’w’);
if nargin == 1 & w_test == 1
x = var;
w = ’t’;
end
if nargin == 1 & w_test == 0
x = var;
w = ’w’;
end
if nargin == 2
x = var;
if isempty(x), x = ’x’; end;
w = sym(varargin{2});
end
if nargin == 3
x = sym(varargin{2});
w = sym(varargin{3});
end
F = maple(’map’,’fourier’,f,x,w);
求个快速傅里叶变换的C语言程序
void fft()
{
int nn,n1,n2,i,j,k,l,m,s,l1;
float ar,ai; // 实部 虚部
float a;
float t1,t2,x,y;
float w1,w2,u1,u2,z;
float fsin={0.000000,1.000000,0.707107,0.3826834,0.1950903,0.09801713,0.04906767,0.02454123,0.01227154,0.00613588,};// 优化
float fcos={-1.000000,0.000000,0.7071068,0.9238796,0.9807853,0.99518472,0.99879545,0.9996988,0.9999247,0.9999812,};
nn=1024;
s=10;
n1=nn/2; n2=nn-1;
j=1;
for(i=1;i《=nn;i++)
{
a[2*i]=ar[i-1];
a[2*i+1]=ai[i-1];
}
for(l=1;l《n2;l++)
{
if(l《j)
{
t1=a[2*j];
t2=a[2*j+1];
a[2*j]=a[2*l];
a[2*j+1]=a[2*l+1];
a[2*l]=t1;
a[2*l+1]=t2;
}
k=n1;
while (k《j)
{
j=j-k;
k=k/2;
}
j=j+k;
}
for(i=1;i《=s;i++)
{
u1=1;
u2=0;
m=(1《《i);
k=m》》1;
w1=fcos[i-1];
w2=-fsin[i-1];
for(j=1;j《=k;j++)
{
for(l=j;l《nn;l=l+m)
{
l1=l+k;
t1=a[2*l1]*u1-a[2*l1+1]*u2;
t2=a[2*l1]*u2+a[2*l1+1]*u1;
a[2*l1]=a[2*l]-t1;
a[2*l1+1]=a[2*l+1]-t2;
a[2*l]=a[2*l]+t1;
a[2*l+1]=a[2*l+1]+t2;
}
z=u1*w1-u2*w2;
u2=u1*w2+u2*w1;
u1=z;
}
}
for(i=1;i《=nn/2;i++)
{
ar[i]=a[2*i+2]/nn;
ai[i]=-a[2*i+3]/nn;
a[i]=4*sqrt(ar[i]*ar[i]+ai[i]*ai[i]); // 幅值
}
}
关于matlab的傅里叶变换的代码求解释
这段函数应该是一个做信号分析的GUI里的一个功能吧。
这段代码是要干啥?对应的按钮上有文字说明么。
感觉是观察一段离散信号经过DFT后的功率谱密度。
y=fft(x,xlength);
这个是快速傅里叶变换,也就是对信号x做DFT
Pyy =y.*conj(y)/xlength;
这个是信号x的功率谱,也就是频谱y的幅值平方除以信号长度
至于为什么只看一半我就不知道了
求基2、基4、基8FFT(快速傅里叶变换)的c语言程序,要能运行得出来的
1.FFT:
// data为输入和输出的数据,N为长度
bool CFFT::Forward(complex *const Data, const unsigned int N)
{
if (!Data || N 《 1 || N & (N - 1))
return false;
// 排序
Rearrange(Data, N);
// FFT计算:const bool Inverse = false
Perform(Data, N);
return true;
}
2.IFFT:
// Scale 为是否缩放
bool CFFT::Inverse(complex *const Data, const unsigned int N,
const bool Scale /* = true */)
{
if (!Data || N 《 1 || N & (N - 1))
return false;
// 排序
Rearrange(Data, N);
// FFT计算,ture表示是逆运算
Perform(Data, N, true);
// 对结果进行缩放
if (Scale)
CFFT::Scale(Data, N);
return true;
}
3.排序:
void CFFT::Rearrange(complex *const Data, const unsigned int N)
{
// Swap position
unsigned int Target = 0;
// Process all positions of input signal
for (unsigned int Position = 0; Position 《 N; ++Position)
{
// Only for not yet swapped entries
if (Target 》 Position)
{
// Swap entries
const complex Temp(Data[Target]);
Data[Target] = Data[Position];
Data[Position] = Temp;
}
// Bit mask
unsigned int Mask = N;
// While bit is set
while (Target & (Mask 》》= 1))
// Drop bit
Target &= ~Mask;
// The current bit is 0 - set it
Target |= Mask;
}
}
4.FFT计算:
void CFFT::Perform(complex *const Data, const unsigned int N,
const bool Inverse /* = false */)
{
const double pi = Inverse ? 3.14159265358979323846 : -3.14159265358979323846;
// Iteration through dyads, quadruples, octads and so on...
for (unsigned int Step = 1; Step 《 N; Step 《《= 1)
{
// Jump to the next entry of the same transform factor
const unsigned int Jump = Step 《《 1;
// Angle increment
const double delta = pi / double(Step);
// Auxiliary sin(delta / 2)
const double Sine = sin(delta * .5);
// Multiplier for trigonometric recurrence
const complex Multiplier(-2. * Sine * Sine, sin(delta));
// Start value for transform factor, fi = 0
complex Factor(1.);
// Iteration through groups of different transform factor
for (unsigned int Group = 0; Group 《 Step; ++Group)
{
// Iteration within group
for (unsigned int Pair = Group; Pair 《 N; Pair += Jump)
{
// Match position
const unsigned int Match = Pair + Step;
// Second term of two-point transform
const complex Product(Factor * Data[Match]);
// Transform for fi + pi
Data[Match] = Data[Pair] - Product;
// Transform for fi
Data[Pair] += Product;
}
// Successive transform factor via trigonometric recurrence
Factor = Multiplier * Factor + Factor;
}
}
}
5.缩放:
void CFFT::Scale(complex *const Data, const unsigned int N)
{
const double Factor = 1. / double(N);
// Scale all data entries
for (unsigned int Position = 0; Position 《 N; ++Position)
Data[Position] *= Factor;
}
C语言 1024点快速傅里叶变换(FFT)程序,最好经过优化,执行速度快
void fft()
{
int nn,n1,n2,i,j,k,l,m,s,l1;
float ar,ai; // 实部 虚部
float a;
float t1,t2,x,y;
float w1,w2,u1,u2,z;
float fsin={0.000000,1.000000,0.707107,0.3826834,0.1950903,0.09801713,0.04906767,0.02454123,0.01227154,0.00613588,};// 优化
float fcos={-1.000000,0.000000,0.7071068,0.9238796,0.9807853,0.99518472,0.99879545,0.9996988,0.9999247,0.9999812,};
nn=1024;
s=10;
n1=nn/2; n2=nn-1;
j=1;
for(i=1;i《=nn;i++)
{
a[2*i]=ar[i-1];
a[2*i+1]=ai[i-1];
}
for(l=1;l《n2;l++)
{
if(l《j)
{
t1=a[2*j];
t2=a[2*j+1];
a[2*j]=a[2*l];
a[2*j+1]=a[2*l+1];
a[2*l]=t1;
a[2*l+1]=t2;
}
k=n1;
while (k《j)
{
j=j-k;
k=k/2;
}
j=j+k;
}
for(i=1;i《=s;i++)
{
u1=1;
u2=0;
m=(1《《i);
k=m》》1;
w1=fcos[i-1];
w2=-fsin[i-1];
for(j=1;j《=k;j++)
{
for(l=j;l《nn;l=l+m)
{
l1=l+k;
t1=a[2*l1]*u1-a[2*l1+1]*u2;
t2=a[2*l1]*u2+a[2*l1+1]*u1;
a[2*l1]=a[2*l]-t1;
a[2*l1+1]=a[2*l+1]-t2;
a[2*l]=a[2*l]+t1;
a[2*l+1]=a[2*l+1]+t2;
}
z=u1*w1-u2*w2;
u2=u1*w2+u2*w1;
u1=z;
}
}
for(i=1;i《=nn/2;i++)
{
ar[i]=a[2*i+2]/nn;
ai[i]=-a[2*i+3]/nn;
a[i]=4*sqrt(ar[i]*ar[i]+ai[i]*ai[i]); // 幅值
}
}