Help to Generate triangle wave

3 ビュー (過去 30 日間)
taher zaouali
taher zaouali 2019 年 12 月 10 日
コメント済み: taher zaouali 2019 年 12 月 10 日
Si i have this code for a square wave and i need to modify it to a triangle wave how??
t=-0.4:0.001:0.4;
T=0.2;
A=2;
Nt=length(t);
xt=zeros(1,Nt);
P=-0.4;
for n=1:Nt
if t(n)<P+T/2
xt(n)=A;
else
xt(n)=-A;
end
if t(n)>=P+T
P=P+T;
end
end
  2 件のコメント
Erivelton Gualter
Erivelton Gualter 2019 年 12 月 10 日
By the way, your code can be replaced by:
t = -0.4:0.001:0.4; % Time Array
T = 0.2 % Wave Period
A = 2; % Amplitude
xt = A*square(2*pi*t/T);
plot(t,xt)
taher zaouali
taher zaouali 2019 年 12 月 10 日
Yes i know but my assignment is to use matematical equation.

サインインしてコメントする。

回答 (1 件)

Erivelton Gualter
Erivelton Gualter 2019 年 12 月 10 日
編集済み: Erivelton Gualter 2019 年 12 月 10 日
There is a function you might use for this task called sawtooth. You might find some help in this page.
t = -.4:0.001:.4; % Time Array
A = 2;
T = 0.2;
x = 2*sawtooth(2*pi*t/T, 1/2); % sawtooth(T, xmax):
% xmax = 1/2: For triangle wave
plot(t,x)
  1 件のコメント
taher zaouali
taher zaouali 2019 年 12 月 10 日
i know the function but i need to use a mathematical equation based on the one i wrote

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by