【问题标题】:Truncated sinusoidal signal截断的正弦信号
【发布时间】:2020-05-10 09:13:26
【问题描述】:

我想绘制一个截断的正弦信号。我尝试的是:

tstep = 0.1;
t = -1:0.05:2;
f0 = 1;
fi = 10;
t = 0:tstep:2;
s = sin(2*pi*f0*t+fi);
plot(t,s);

我必须得到这样的东西(f0 = 1):


问题的文字是:

编写一个绘制截断正弦信号的 Matlab 程序:
s(t) = PT (t) sin (2πf0t + φ)
其中:
T = 1 固定
f0 是从 GUI(键盘)输入的 110 之间的整数
φ 是在 0 和 @ 之间随机生成的相位987654332@辐射点

【问题讨论】:

  • 可能还有其他问题,但您的fi = 10,它应该是根据您的 0 和 2π 之间随机生成的问题陈述。此行也没有做任何事情:t = -1:0.05:2; 因为您在几行后通过在t 中存储不同的值使其无效,请谷歌如何截取屏幕截图
  • 是的,是随机生成的。但是,我将 fi 设为静态...我尝试使用许多 fi 值(0、1、5、10),但我认为我对PT (t) 做错了(我想是 1)..
  • 我的意思是10 ∉ [0,2π]PT 是什么?
  • PT(t) 是矩形信号。
  • 我用谷歌搜索截断的正弦信号,我发现它与 s (t) = APT (t) sin (2π0t) 相等,其中 APT 是矩形信号,sin (2π0t) 是正弦信号。

标签: matlab plot signals


【解决方案1】:

您已经定义了fi=10。根据您的问题陈述,fi 应该在0 之间随机生成。这条线也不做任何事情:t = -1:0.05:2;,因为你在几行之后重新定义了t。要生成矩形脉冲,您可以使用pulstran(需要信号处理工具箱)。完整的修复代码如下:

tstep=0.005;     t=-1:tstep:2;      fi = 2*pi*rand(1);
%Loop to take f0 as an integer number between 1 to 10 input from keyboard
while 1
    f0 = input('f0 = ');  %requesting user input
    if mod(f0,1) || f0<1 || f0>10
       %mod checks whether the value is not an integer and then we check 
       %if it doesn't belong to [1,10]
       disp('Wrong value entered. Please enter an integer between 1 to 10');
    else, break;  %break if the correct value is entered
    end
end

PT = pulstran(t,0.5,'rectpuls');  %Generating rectangular pulse
SW = sin(2*pi*f0*t+fi);           %Generating sinusoidal wave

%I have added two plots just so you know what's happening
subplot(1,2,1); 
plot(t, PT, t, SW, 'linewidth', 2);
legend({'Rectangular Pulse','Sinusoidal Wave'},'location','northoutside','NumColumns',2);
xlabel('Time (t)');    ylabel('Signals');

subplot(1,2,2);
y = PT.*SW;
plot(t, y, 'linewidth', 2);
legend('Truncated Sinusoidal Wave','location','northoutside');
xlabel('Time (t)');    ylabel('s(t)');

fi=pif0=1 时的结果:

【讨论】:

    猜你喜欢
    • 2022-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-23
    相关资源
    最近更新 更多