How to plot a periodic signal with variable duty cycle?

1 回表示 (過去 30 日間)
Ana Júlia Lanzarin
Ana Júlia Lanzarin 2018 年 10 月 13 日
回答済み: madhan ravi 2018 年 10 月 14 日
Hi, I would like to plot a periodic function with a variable duty cycle. I think my ploblem is using the plot function, should I store the values of 'x' in a vector?
N = 500; %number of interactions
fs = 1000; %frequency of sampling
ts = 1/fs;
f0 = 100;
t0 = 1/f0;
dc = 0.5; %duty cycle=50%
t = 0;
Na = t0/ts; %number of samples
for n = 1:N
if rem(n, Na*dc) == 0
x = 1
else
x = 0
end
t = t+ts;
end
plot(t,x)

回答 (1 件)

madhan ravi
madhan ravi 2018 年 10 月 14 日
N = 500; %number of interactions
fs = 1000; %frequency of sampling
ts = 1/fs;
f0 = 100;
t0 = 1/f0;
dc = 0.5; %duty cycle=50%
t = 0;
Na = t0/ts; %number of samples
for n = 1:N
if rem(n, Na*dc) == 0
x(n) = 1
else
x(n) = 0
end
end
t=0:ts:numel(x);
plot(t(1:numel(x)),x)

カテゴリ

Help Center および File ExchangePulse and Transition Metrics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by