Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Square Function in Matlab

Status
Not open for further replies.

eyestrainx

Junior Member level 2
Joined
Feb 24, 2010
Messages
20
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,281
Location
Malaysia
Activity points
1,373
I have write the followings.

My target to have a square wave, where y=0 at 0<=x<=30, y=1 at 30<=x<=60 and y=0 at 60<=x<=100.

x = 30:0.1:60;
y = square(2*pi*25*x,100);
plot(x,y)


but it only works at 30<=x<=60

anybody can help this?
 

keep in mind that >, <, ==, >=, !=, and <= are also operators. eg, y = (sin(t) > 0); is a valid expression, as is y = m.*(sin(t) > 0)+b;
 

First up, that not really a square wave, a square wave should have equal low time as high time, or a least a constant duty cycle.

you wave is low for 30, high for 30 and then low for 40? are you sure this is what you want?

the typical way to generate real square waves is something like:
Code:
x = 0:0.1:100;
y = double((mod(x,60) > 30));
plot(x,y);

what this does is takes the modulus (i.e. the remainder) from 60 and check if its greater than 30. since a greater than check returns a boolean (1 or 0) result, the double() casts the number back into a 'normal' matlab number...
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top