필터 지우기
필터 지우기

I cant generate a square wave in matlab using the square wave command

조회 수: 18 (최근 30일)
Rapheal
Rapheal 2012년 5월 16일
댓글: Arabinda 2024년 1월 8일
hello, i tried to create a square wave using the following command:
t = 0:0.001:0.1; y = square(2*pi*100*t,50); plot(t,y); axis([0 0.1 -1.5 1.5]); xlabel('Seconds'); ylabel('Amplitude');
i keep getting an error with the square wave:
error message: Error in Untitledsqwave (line 2) y = square(2*pi*100*t,50);
is there an error because i dont have the signal processing toolbox. and what command can i use to see if i have the signal processing toolbox.
thanks

답변 (3개)

Dr. Seis
Dr. Seis 2012년 5월 16일
If you dont have the Signal Processing Toolbox, will the following work as an alternative:
y = sign(sin(2*pi*100*t));
  댓글 수: 5

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


Wayne King
Wayne King 2012년 5월 16일
You can enter
>>ver
at the command line to see what is installed. If you see the Signal Processing Toolbox listed try:
license('test','signal_toolbox')
to see if you have a license checked out
  댓글 수: 1
Daniel Shub
Daniel Shub 2012년 5월 16일
Also
which -all square
should return something like
.../toolbox/signal/signal/square.m

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


Daniel Shub
Daniel Shub 2012년 5월 16일
You can get similar functionality with
square = @(M, N, duty)repmat([ones(floor(N/duty), 1); -ones(ceil(N/duty), 1)], M, 1);
where M is the number of periods, N is the samples per period, and duty is the duty cycle.
  댓글 수: 2
Dr. Seis
Dr. Seis 2012년 5월 16일
I wasn't able to get similar functionality without some modifications. I.e.,
squarez = @(M, N, duty)repmat([ones(floor(N*duty/100), 1); -ones(ceil(N*(100-duty)/100), 1)], M, 1);
Daniel Shub
Daniel Shub 2012년 5월 18일
@Elige, you are correct. Thank you for the fix, my answer is sloppy and wrong.

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

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by