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 CenterFile Exchange에서 Pulse and Transition Metrics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by