如何绘制根据 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])
但是,none 的 MATLAB 教程似乎对绘制 d 的快速傅里叶变换很有用,它是根据变量积分定义的。
如果我尝试
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
的第二个和第三个参数(积分的下限和上限)必须是 scalars。要获得用于计算 fft
的值向量,您需要在 for
循环
中计算元素的值
d = zeros(size(t));
for i = 1:length(t)
d(i) = integral(phi,0,t(i));
end
然后,您将能够绘制 t
与 d
的关系图,并计算 d
的 <a href="https://www.mathworks.com/help/matlab/ref/fft.html" rel="nofollow noreferrer">fft</a>
打电话
y = fft(d);
查看 docs 中的示例,了解如何绘制 fft
returns.
的结果
我想使用 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])
但是,none 的 MATLAB 教程似乎对绘制 d 的快速傅里叶变换很有用,它是根据变量积分定义的。
如果我尝试
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
的第二个和第三个参数(积分的下限和上限)必须是 scalars。要获得用于计算 fft
的值向量,您需要在 for
循环
d = zeros(size(t));
for i = 1:length(t)
d(i) = integral(phi,0,t(i));
end
然后,您将能够绘制 t
与 d
的关系图,并计算 d
的 <a href="https://www.mathworks.com/help/matlab/ref/fft.html" rel="nofollow noreferrer">fft</a>
打电话
y = fft(d);
查看 docs 中的示例,了解如何绘制 fft
returns.