LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

time interval

Solved!
Go to solution

Hi everyone;

I have a problem that I want to build a time interval like this...delta_t = [-T/2 : 1/fs : T/2].....I tried to build it but the result array was random numbers,I am new on labview ,anyone can help me to do this time interval using labview??

0 Kudos
Message 1 of 6
(3,225 Views)

If you are are you trying to build an array, look at the Ramp subVI.

 

If you have already tried something that didn't work, you should ATTACH THAT VI so that we can see what you did and tell you how to fix it.

0 Kudos
Message 2 of 6
(3,201 Views)
Solution
Accepted by topic author ASHLY19

@ASHLY19 wrote:

I have a problem that I want to build a time interval like this...delta_t = [-T/2 : 1/fs : T/2].....I tried to build it but the result array was random numbers,I am new on labview ,anyone can help me to do this time interval using labview??


strongly suggest a different name for your array of times.  Most people, certainly most LabVIEW users, would say that delta_t represents a difference in time, and in your formulation, delta_t = 1/fs (using the convention that fs is a constant frequency, hence 1/fs is a constant change in time).  I'm also assuming that the formulation [-T/2 : 1/fs : T/2] is meant to be an array of equally spaced times from -T/2 to T/2 (not worrying, at the moment, if the total time T can be exactly divided into 1/fs intervals).

 

So call it something like Sample_Times.  Now all you have to worry about is how to "map" LabVIEW's array indices (which start at 0 and increment by 1] into [-T/2, +T/2] in 1/fs intervals.  I'm going to call 1/fs "dt" (for delta-t), a name LabVIEW also uses in defining a "Waveform", which is more-or-less what you are creating.  Let's assume that dt exactly divides T. 

 

So now you have an interesting "representation" problem/question -- you are dividing time T into N intervals, so each interval is T/N = dt wide.  Where do you make the measurement?  At the beginning of the interval, at the end of the interval, or at the middle of the interval?  [Yes, it sounds like a silly question, but there are situations where it make a (small) different.  One example is when you plot a 100-point Waveform and wonder why Time goes from 0 to 99 ...].  In particular, when you design your "mapping" function, to get N intervals of width dt, you can either use t = [-T/2, -T/2 + dt, -T/2 + 2*dt, ... T/2 - dt] (N intervals), [-T/2 + dt, -T/2 + 2*dt, ... T/2 - dt, T/2] (N intervals, or [-T/2 + dt/2, -T/2 + dt/2 + dt, ...T/2 + dt/2 + (N-1)*dt, which is T/2 - dt/2] (N intervals).

 

Let's keep it "simple", go with the first "start of the dt interval" method.  Thinking in LabVIEW terms, if we put an N element Array (which we now know represents data from [-T/2 to T/2 - dt] (unless you want N+1 elements, and if you have multiples of them, like continuous sampling of a waveform, you realize that the last point of the previous array is at the same time point as the first point of the current array).  LabVIEW arrays (indexed in a For loop by the "i" terminal) run from 0 to N-1, so the computation (-T/2 + i*dt) will yield the corresponding Time points -T/2, -T/2 + dt, ... as noted in the first set of intervals in the previous paragraph.

 

I leave it as a (simple) Exercise for the Reader to, given a time point "t" (from -T/2 to T/2 - dt), compute the corresponding Array index "i".

 

Bob Schor

0 Kudos
Message 3 of 6
(3,193 Views)

I understood you and your explanation simplify the topic to me ,I did this array of time on matlab on one step, but now  I want to do this using labview,I already built the example using for loop but my problem is N [length of the array] ????

 

0 Kudos
Message 4 of 6
(3,182 Views)

You still haven't attach the VI for your attempt!

 

N would be T times the sample rate.

0 Kudos
Message 5 of 6
(3,170 Views)

@ASHLY19 wrote:

I already built the example using for loop but my problem is N [length of the array]  


I thought I explained that in my Solution, and RavensFan also gave you the answer.  I'll be a little less "wordy" this time ...

 

In Matlab, you have N+1 time points [-T/2 : 1/fs : T/2].  (I hope you understand why I say this is N+1 points -- I did a fair amount of "hand-waving", also known as "Song and Dance", trying to make that clear ...).

 

Using the same symbols, N = ((T/2) - (-T/2)) / (1/fs) = T * fs.  This is what RavensFan said.

 

If you recall I set dt = 1/fs (I think I called it the "sampling time" or "sampling interval"), then N = T / dt.  One of the things I remember from High School Chemistry is formulas need to "balance the Units".  N is a number, T and dt both have the units of Time, so to get a unit-less number N, you need a unit-less "right-hand side", which you accomplish by dividing a Time interval by another Time interval.  [Sorry, I can't easily take of my "Teaching" hat -- I'm trying to show you how you might have figured it out yourself, knowing you had Time and Frequency, and needed to do something "logical" with them to get a unitless Number ...].

 

Bob Schor

0 Kudos
Message 6 of 6
(3,144 Views)