Manual triangle wave generation
5 次查看(过去 30 天)
显示 更早的评论
Hello
I want to generate a triangle wave without built in function and I want to do it using this formula

Unfortunately, the output plot is not looking right
I'd appreciate any suggestions

clc;
clear all;
A = 1;
f = 1;
fs = 1000;
t = 0 : 1/fs : 10;
n = [300];
omega0 = 2 * pi * f;
for i = 1 : length(n)
b = 0;
for j = 1 : 2 : n(i)
H = [0 : 0.5 : n(i)];
sr = (1 / j) * (-1)^H(j) *sin(j * omega0 * t);
b = b + sr;
end
b = ( 8 * A / pi ^ 2 ) * b;
figure()
plot(t, b)
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!