繁体   English   中英

如何绘制在MATLAB中根据积分定义的函数的FFT?

[英]How to plot FFT of a function defined in terms of an integral in MATLAB?

我想使用MATLAB绘制通过以下代码绘制的数据的傅立叶变换:

x = -2:0.01:2; % position vector
s = @(x)heaviside(x+1).*heaviside(-x)+heaviside(x).*heaviside(1-x); % Step    
function between -1 and 1
phi = @(x) exp(-1./(1-x.^2)).*s(x); % Test function
d = @(t) integral(@(x)phi(x),0,t); % Data
fplot(d,[0,1])

但是,在绘制d的快速傅立叶变换时,似乎都没有MATLAB教程有用,后者是根据变量积分定义的。

如果我尝试

Fs = 1000;            % Sampling frequency
T = 1/Fs;             % Sampling period
L = 1000;             % Length of signal
t = (0:L-1)*T;        % Time vector
s = @(x)heaviside(x+1).*heaviside(-x)+heaviside(x).*heaviside(1-x); % Step     
function
phi = @(x) exp(-1./(1-x.^2)).*s(x); % Test function
d = @(t) integral(@(x)phi(x),0,t); %Data
plot(1000*t(1:50),d(1:50))

然后我得到以下错误:

Error using integral
A and B must be floating-point scalars.

Error in @(t)integral(@(x)phi(x),0,t)

我不知道该如何解决。

发生错误是因为integrate的第二个和第三个参数(积分的上下限)必须是标量 为了获得一个值向量,用于计算fft您需要在for循环中计算元素的值

d = zeros(size(t));
for i = 1:length(t)
    d(i) = integral(phi,0,t(i));
end

然后,你就可以绘制td ,并计算fftd致电

y = fft(d);

文档中查看示例,以了解如何绘制fft返回的结果。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM