LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

mathscript square wave

Hello,

I am trying to figure out a problem in which I am supposed to use a MathScript Node to evaluate the given expression in the range t>=0, t<=3.

The book I'm using says to input: y(t)=(4/pi)*(sin(2*pi*t)+(sin(6*pi*t)/3)+(sin(10*pi*t)/5)+(sin(14*pi*t)/7)), and that this formula should create a square wave.

 

I have put in the following code:

delta_t=1/f_s
start=0
step=delta_t
stop=(N-1)*delta_t
t=start:step:stop

t>=0
t<=3

y=4*(sin(2*pi*t)+(sin(6*pi*t)/3)+(sin(10*pi*t)/5)+(sin(14*pi*t)/7))/pi

 

However, the result I am getting is not a square wave at all.  I have attached the VI (I am using N=500 and f_s=10000).

Any ideas?

 

-Jill

0 Kudos
Message 1 of 2
(3,051 Views)

Hello Jill,

 

Thanks for providing the code you're using- the signal you are currently seeing is because you are sampling the waveform quite fast compared to the signal frequency and you don't have a full period of the waveform to display; increasing the number of samples generated gives a waveform something like this:

 

Squarewave.png

 

Which appears to be a square wave built with a sin function as you have described. With the values you specified (N=500), you're only seeing part of that initial curve (T=0 to T=0.05, or about 1/20th of the waveform's apparent fundamental period.)

 

Regards,

 

 

Tom L.
Message 2 of 2
(3,019 Views)