Clear Filters
Clear Filters

how to create a triangle wave in matlab?

92 views (last 30 days)
Ningyi Liu
Ningyi Liu on 9 Nov 2017
Answered: Simon Leary on 11 Apr 2022
How do I plot "a triangle wave with frequency of 1 kHz that's 3 V peak-to-peak with a minimum voltage of 0 volts" in matlab?
I attached the excel graphs that is my simulation plot and measured plot, the theoretical graph created from Matlab should look similar to it.

Answers (3)

Simon Leary
Simon Leary on 11 Apr 2022
function output = triangle(t, period, amplitude)
% sawtooth uses amplitude of time array to get period
% multiply t by 2pi, divide by your desired period
t1 = t*2*pi/period;
% 0.5 is the fraction of the period where sawtooth peaks, I think
output = sawtooth(t1, 0.5);
% default range of sawtooth is -1 to 1, add 1 to get 0 to 2
% then divide by 1 to get 0 to 1
output = (output + 1)/2;
output = output*amplitude;
end

Image Analyst
Image Analyst on 9 Nov 2017

Eyad Samaan
Eyad Samaan on 19 Mar 2018
V=10; f0=1; w0=2*pi*f0; T=1/f0; T1=T/2; T2=1-T/2; f1=1/T1; f2=1/T2; d=1/2; dT=T/512; t1=0:dT: d* T-dT ; t2=d*T:dT: T-dT; t=[t1 t2]; figure; v1= V * triangle ( 2* pi* f1*t1 ); v2=-V*triangle (2*pi*f2*t2);

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!