LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Sinewave Generation for different time durations & Frequency

Solved!
Go to solution

Hi Folks,

I am trying to generate sine wave using fixed no. of samples with varying Time duration & frequency.

I was unable to achieve the given Frequency for given time duration although the waveform are generated in total duration calculated from different time durations.

 

Can you please check what wrong i have been doing.

 

Thanks.

0 Kudos
Message 1 of 11
(29,026 Views)

Hi Ransher,

 

what is your problem?

(Maybe the empty Fs array was your problem!?)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 11
(29,006 Views)

Hi GerdW

 

Thanks for replying.

 

As you have shared screenshots of the Sinewave generated , you might have observed that the first sinewave having  1 hz frequency is generated till 0.43 ms time. However i want it in duration of 0.3 ms as mentioned in time array and similarly i want it in 0.5 for 10 hz frequency respectively and so on .

 

The no. of sample must be same as set 1000 samples may change if manually changed.

 

However if i am multiplying the no. of sample instead of divide, multiplying the time with no. samples  i am getting waveform as required but waveform samples are increased. 

 

Is there any to achieve no. of samples to remain same and waveform to within the given time duration?

 

S1.PNG

0 Kudos
Message 3 of 11
(28,988 Views)

Hi Ransher,

 

You want 0.3+0.5+0.7+0.25 = 1.75sec of acquisition.

Fs = 1kHz

So you get 1.75*1000 = 1750 samples. Expected.

 

If you want 1000 samples for 1.75sec of acquisition, you should set Fs = 571 Hz.

0 Kudos
Message 4 of 11
(28,982 Views)

Hi Ransher,

 


@RansherS wrote:

As you have shared screenshots of the Sinewave generated , you might have observed that the first sinewave having  1 hz frequency is generated till 0.43 ms time. However i want it in duration of 0.3 ms as mentioned in time array and similarly i want it in 0.5 for 10 hz frequency respectively and so on. 


This is because YOU manipulate the dt value of the resulting waveform…

 


@RansherS wrote:

Is there any to achieve no. of samples to remain same and waveform to within the given time duration?


Don't manipulate the dt value of the resulting waveform.

And fix your input values: when you define a series of waveform parts with a duration of 1.75s in total then the resulting waveform will contain 1750 samples at 1000Hz samplerate.

The basic math behind this is "Time = NumberOfSamples / Samplerate"!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 11
(28,980 Views)

Hi Gredw,

 

i have corrected back to original.

S2.PNG

 

Is it possible to achieve the waveform to be in given time period with samples to be 1000? if yes how ?

0 Kudos
Message 6 of 11
(28,974 Views)

Here what I did to get the closest to what I understood that you wanted:

PinguX_0-1717150712838.png

 

Don't change Fs inside the For Loop, it will mess everything in your graph.

0 Kudos
Message 7 of 11
(28,962 Views)

Hi PinguX,

 

I want 1 complete sine waveform in 0.3 msec , 10 complete sine waveform in 0.5 msec , 1 complete sinewave in 0.7 msec & 10 complete sinewave in 0.25 msec in total duration of 1.75 msec with total no. of samples of 1000 in total.

 

Can you see in the snip, the only thing messing here is time period of waveform and shape of sine wave.

S2.PNG

0 Kudos
Message 8 of 11
(28,958 Views)
Solution
Accepted by RansherS

Well ... so the "frequency (Hz)" array is not frequency, but "number of period" instead ...

Quite confusing you would admit ...

 

PinguX_0-1717151986546.png

 

Message 9 of 11
(28,951 Views)

Hi Ransher,

 


@RansherS wrote:

I want 1 complete sine waveform in 0.3 msec , 10 complete sine waveform in 0.5 msec , 1 complete sinewave in 0.7 msec & 10 complete sinewave in 0.25 msec in total duration of 1.75 msec with total no. of samples of 1000 in total.


I guess you talk about "s" when you write "msec"…

 

A total of 1000 samples for a duration of 1.75s gives a samplerate of 571.4S/s. Do you remember the basic math formula I gave you above? Do you remember what PinguX wrote in its message?

 

Do some more math: "10 complete sinewave in 0.25s with a samplerate of 571.4Hz" results in 571.4×0.25×1/10=14.3 samples per sinewave. While this is not "perfect" it still obeys Mr. Shannon and Mr. Nyquist. (Keep this in mind in case you want to lower the samplerate even more or to put more sinewaves into your 1000 sample waveform!)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 10 of 11
(28,944 Views)