如何使用 Matlab 绘制信号的包络

How to plot the envelope of a signal using Matlab

我正在尝试 运行 本视频中描述的示例:https://www.youtube.com/watch?v=NRKxa8V8RWc

MATLAB 脚本应该是这样的:

%% Plot the sum of cosines
t=linspace(0,pi/2,1000);
f1=10;
f2=12;
y1=cos(2*pi*f1*t);
y2=cos(2*pi*f2*t);
y3=y1+y2;

figure;
hold on;
plot(t,y3)

%% Add the envelope to the plot
envelope = [2*cos(pi*(f1.f2)*t); 2*cos(pi*(f1*f2)*t.pi)];
plot(t,envelope)
axis tight

问题:

在第 "Add the envelope to the plot" 步有一个 . "(f1.f2)" 和 "t.pi"

处的运算符

根据视频,它应该与点一起工作,但我找不到合适的点运算符,因为我尝试了点字符,但它无法正常工作

它不是 . 运算符,它只是一个减号运算符。 更改行:

envelope = [2*cos(pi*(f1-f2)*t); 2*cos(pi*(f1-f2)*t-pi)];

你应该得到:

为什么它应该是负号,你应该检查beat phenomenon