Manual triangle wave generation

조회 수: 5 (최근 30일)
quando
quando 2020년 6월 1일
댓글: quando 2020년 6월 2일
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

답변 (1개)

KSSV
KSSV 2020년 6월 1일
편집: KSSV 2020년 6월 1일
A = 1;
f = 1;
fs = 1000;
t = 0 : 1/fs : 10;
n = [300];
omega0 = 2*pi*f;
K = 8*A/pi^2 ;
N = 20 ; % can be changed
x = zeros(size(t)) ;
for i = 0:N
x = x+(-1)^i*1/(2*i+1)*sin((2*i+1)*omega0*t) ;
end
plot(t,x)
  댓글 수: 1
quando
quando 2020년 6월 2일
It's the same plot, it's not triangle wave

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by