05-31-2024 02:16 AM
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.
Solved! Go to Solution.
05-31-2024 03:08 AM - edited 05-31-2024 03:09 AM
05-31-2024 04:23 AM
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?
05-31-2024 04:37 AM
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.
05-31-2024 04:39 AM
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"!
05-31-2024 04:58 AM
Hi Gredw,
i have corrected back to original.
Is it possible to achieve the waveform to be in given time period with samples to be 1000? if yes how ?
05-31-2024 05:19 AM
Here what I did to get the closest to what I understood that you wanted:
Don't change Fs inside the For Loop, it will mess everything in your graph.
05-31-2024 05:30 AM
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.
05-31-2024 05:39 AM
Well ... so the "frequency (Hz)" array is not frequency, but "number of period" instead ...
Quite confusing you would admit ...
05-31-2024 05:43 AM
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!)