Phase Shift Sawtooth Wave

19 次查看(过去 30 天)
Ethan
Ethan 2020-10-15
回答: Ethan 2020-10-16
Hi everyone,
I am trying to plot a triangular wave for a specified time using the sawtooth function in Matlab. The user inputs values for T_amp, T_freq, and ft and the code then calculates the sawtooth and plots the function vs time, ft.
When plotted, the plot shows the sawtooth starting at -T_amp. I was wondering if there was a way to shift the function so that the sawtooth starts at 0, where the first point would be (0,0) instead of (0, -T_amp). If anyone could help me out with this, I would really appreciate it. Thanks!
tri = T_amp*sawtooth(T_freq*ft, .5);
plot(ft, tri;)

采纳的回答

Ethan
Ethan 2020-10-16
The sawtooth function does not automatically account for the 2*pi required to plot with frequency. To add a phase shift, you can do the same as if it were a sign wave by adding or subtracting your phase:
tri = sawtooth(2*pi*T_freq*ft+(pi/2), .5);

更多回答(1 个)

Jon
Jon 2020-10-15
编辑:Jon 2020-10-15
if you just want to shift it so that it starts at (0,0):
tri = T_amp*sawtooth(T_freq*ft, .5) + T_amp;
Note that with the above tri will range from 0 to 2*T_amp,
if you actually wanted it to range from 0 to T_amp you could use:
tri = T_amp/2*sawtooth(T_freq*ft, .5) + T_amp/2;
  6 个评论
Jon
Jon 2020-10-15
Oh even better, just feeding the sawtooth with the shifted angles
Jon
Jon 2020-10-16
It would be good to either post your solution as an answer and then accept it, or accept this thread and let people find it in the comments just so that others who might have a similar question will know there is an answer available

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Numerical Integration and Differentiation 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by