【问题标题】:How to plot FFT of a function defined in terms of an integral in MATLAB?如何绘制在 MATLAB 中根据积分定义的函数的 FFT?
【发布时间】:2017-05-12 03:44:24
【问题描述】:

我想使用 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)

我不知道如何解决这个问题。

【问题讨论】:

    标签: matlab plot fft


    【解决方案1】:

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

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

    然后,您将能够绘制 td 的图,还可以通过调用计算 @987654322@d

    y = fft(d);
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-17
      • 1970-01-01
      • 2015-12-09
      • 1970-01-01
      • 2013-07-26
      相关资源
      最近更新 更多