Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
help generating square wave

Subject: help generating square wave

From: George Nychis

Date: 29 Nov, 2009 20:15:08

Message: 1 of 4

Hi,

I am trying to generate a square wave of period 2, where in the first
period its amplitude is 1 from 0 to 1, and 0 from 1 to 2. Using this:
gensig('square',2,10,0.01)

... I get the opposite, where the amplitude is 0 from 0 to 1, and 1
from 1 to 2. How can I get the opposite? It's like I need to time
shift it by 1.

- George

Subject: help generating square wave

From: Georgios

Date: 30 Nov, 2009 03:33:03

Message: 2 of 4

George Nychis <gnychis@gmail.com> wrote in message <3e8ac43d-99de-401b-9bdd-c6745281cc24@j9g2000vbp.googlegroups.com>...
> Hi,
>
> I am trying to generate a square wave of period 2, where in the first
> period its amplitude is 1 from 0 to 1, and 0 from 1 to 2. Using this:
> gensig('square',2,10,0.01)
>
> ... I get the opposite, where the amplitude is 0 from 0 to 1, and 1
> from 1 to 2. How can I get the opposite? It's like I need to time
> shift it by 1.
>
> - George

>> [u,t]=gensig('square',2,10,0.01);
>> u=u';
>> t=t';
>> u=fliplr(u);
>> plot(t,u)
>> axis([0 10 0 1.2])

Regards,
Georgios

Subject: help generating square wave

From: Greg Heath

Date: 30 Nov, 2009 05:03:39

Message: 3 of 4

On Nov 29, 3:15 pm, George Nychis <gnyc...@gmail.com> wrote:
> Hi,
>
> I am trying to generate a square wave of period 2, where in the first
> period its amplitude is 1 from 0 to 1, and 0 from 1 to 2.  Using this:
> gensig('square',2,10,0.01)
>
> ... I get the opposite, where the amplitude is 0 from 0 to 1, and 1
> from 1 to 2.  How can I get the opposite?  It's like I need to time
> shift it by 1.

clear all, close all, clc
T = 10, dt = 0.01, N = round(T/dt)
t = dt*(0:N-1);
T0 = 2, f0 = 1/T0

x = 0.5+0.5*square(2*pi*f0*t)
plot(t,x)
ylim([-1 2])

Hope this helps.

Greg

Subject: help generating square wave

From: Jos (10584)

Date: 30 Nov, 2009 09:23:01

Message: 4 of 4

George Nychis <gnychis@gmail.com> wrote in message <3e8ac43d-99de-401b-9bdd-c6745281cc24@j9g2000vbp.googlegroups.com>...
> Hi,
>
> I am trying to generate a square wave of period 2, where in the first
> period its amplitude is 1 from 0 to 1, and 0 from 1 to 2. Using this:
> gensig('square',2,10,0.01)
>
> ... I get the opposite, where the amplitude is 0 from 0 to 1, and 1
> from 1 to 2. How can I get the opposite? It's like I need to time
> shift it by 1.
>
> - George

I don't have the control system toolbox but I suspect that this should work:

[u,t] = gensig('square',2,10,0.01)
u = 1 - u ;

hth
Jos

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us