Plotting a square wave

조회 수: 10 (최근 30일)
Ahmed Adel
Ahmed Adel 2017년 6월 16일
댓글: Muhammad Wasim Akhtar Khan 2017년 6월 20일
How can I plot a square wave of period 2 seconds, with step 0.01 second ,amplitude from -1 to 1 and 50% duty cycle?
  댓글 수: 3
dpb
dpb 2017년 6월 16일
stairs will be easier for square wave; it does the "doubling up" needed by plot automagically (or builds the vectors for plot)
Muhammad Wasim Akhtar Khan
Muhammad Wasim Akhtar Khan 2017년 6월 20일
duty = 50;
t = 0:0.01:8;
f = 0.5;
x = square(2*pi*f*t,duty);
plot(t,x)
axis([0 8 -1.5 1.5])
grid on

댓글을 달려면 로그인하십시오.

답변 (1개)

dpb
dpb 2017년 6월 16일
편집: dpb 2017년 6월 16일
If you have Signal Processing TB, then use square function. Without, you'll have to compute the transition spacings ( linspace should be helpful there) and then stairs will do a plot or create the filled-in x- y- vectors including the "doubled-up" values at the breakpoints.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by