I cant generate a square wave in matlab using the square wave command
Mostrar comentarios más antiguos
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
Respuestas (3)
Dr. Seis
el 16 de Mayo de 2012
If you dont have the Signal Processing Toolbox, will the following work as an alternative:
y = sign(sin(2*pi*100*t));
5 comentarios
Jenn Mariel Biso
el 4 de Jul. de 2020
Thank you for this.
venkata santhoshnaidu koribilli
el 8 de Nov. de 2020
Dr.seis
appriciate your code which work to me since last 4 hours strugling.
square_wave_f=A/2 + A/2*square(2*pi*t/T);
square_wave_f=A/2 + A/2*sign(sin(2*pi*t/T)); worked
Thanks
Nanduri kunkuma Sri kamaladevi
el 8 de Mayo de 2022
Tq sir
ikram
el 27 de Mzo. de 2023
thanks
Arabinda
el 8 de En. de 2024
Thank you sir
Wayne King
el 16 de Mayo de 2012
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 comentario
Daniel Shub
el 16 de Mayo de 2012
Also
which -all square
should return something like
.../toolbox/signal/signal/square.m
Daniel Shub
el 16 de Mayo de 2012
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 comentarios
Dr. Seis
el 16 de Mayo de 2012
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
el 18 de Mayo de 2012
@Elige, you are correct. Thank you for the fix, my answer is sloppy and wrong.
Categorías
Más información sobre Multirate Signal Processing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!