Help recreating square wave from equation
1 次查看(过去 30 天)
显示 更早的评论
Hello,
I need help recreating a square wave from the following equation:

Thanks!
0 个评论
采纳的回答
Sulaymon Eshkabilov
2021-5-24
编辑:Sulaymon Eshkabilov
2021-5-24
Hi,
IHere is the correct code:
t = ..
T = ..
n=1:2:15; % By increasing n = 1:2:25, you will get much better approximation.
U1 = sum((4/pi)*(1./n(:)).*sin(2*pi*n(:).*t/T));
figure
plot(t, U1, 'r')
Good luck.
更多回答(1 个)
Sulaymon Eshkabilov
2021-5-24
Hi,
It is a quite straightforward exercise. You can create this signal using a colon operator (:), or [for .. end] or [while .. end] loop. Colon operator is the most efficient one.
Good luck.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!