Plotting periodic sawtooth wave with 25%, 50% and 75% duty cycle

25 ビュー (過去 30 日間)
Ginnie Lim
Ginnie Lim 2022 年 3 月 10 日
コメント済み: Ginnie Lim 2022 年 3 月 15 日
How do I generate a periodic sawtooth with varying duty cycle (e.g 25%, 50%, 75%) using x = sawtooth(2*pi*t)?
  3 件のコメント
Ginnie Lim
Ginnie Lim 2022 年 3 月 10 日
Hi sir, thank you for your response! I would like to generate a wave like the one shown in the photo attached.
Scott MacKenzie
Scott MacKenzie 2022 年 3 月 10 日
Ok got it! Just posted an answer. Hope this helps.

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

採用された回答

Scott MacKenzie
Scott MacKenzie 2022 年 3 月 10 日
編集済み: Scott MacKenzie 2022 年 3 月 10 日
I'm sure there are other (perhaps better) ways to do this, but I think the following code achieves what you are after:
% create sawtooth waveform (from sawtooth documentation)
T = 5*(1/50);
fs = 1000;
t = 0:1/fs:T-1/fs;
y = sawtooth(2*pi*50*t);
tiledlayout('flow');
% duty cycle = 100%
nexttile;
plot(t,y);
title('100% Duty Cycle');
spread = abs(max(y) - min(y));
% duty cycle = 50%
nexttile;
floor = max(y) - 0.50 * spread;
y1 = y;
y1(y1<floor) = floor;
plot(t,y1);
title('50% Duty Cycle');
% duty cycle = 25%
nexttile;
floor = max(y) - 0.25 * spread;
y2 = y;
y2(y2<floor) = floor;
plot(t,y2);
title('25% Duty Cycle');
% duty cycle = 75%
nexttile;
floor = max(y) - 0.75 * spread;
y3 = y;
y3(y3<floor) = floor;
plot(t,y3);
title('75% Duty Cycle');
  1 件のコメント
Ginnie Lim
Ginnie Lim 2022 年 3 月 15 日
Thank you so much for your help!!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangePeriodic Waveform Generation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by