LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Automatically Changing the frequency of a sinwave, using 5 actual frequency as the period

Hi,

 

Here is a program changing the frequency of a sinwave every 10s (starting from a Max of 10000Hz (control button), and a min of 0.01Hz (control as well button).

Every 10s, the frequency is being divided by two.

 

I have an issue in this program. First, for quite a few frequencies, it stops to generate a sinwave (you can check by running the attached .vi), and creates something quick shaky.

Is it because the sinwave highest frequencies, cannot be processed in Labview? Or is it much faster than the computer logging? Any chance I can get around that? Using FIFO maybe?

 

Then, I want to change something else in the program.

Instead of changing the frequencies every 10s, I want to keep the same frequency for a certain number of period. Like keep the same frequency for 100 periods (between 10KHz and 10Hz), and then,  5 periods, between 10Hz and the min value.

 

I would very much appreciate some help on this, as I am quite new on labview.

 

best regards,

 

KentMey.

 

 

Kentmey
0 Kudos
Message 1 of 7
(2,612 Views)

Oh sorry, it is not the right .vi

 

There it is, just minor changes between them anyway.

Kentmey
0 Kudos
Message 2 of 7
(2,600 Views)

Hi Kentmey,

 

Sorry it has taken some time to answer your question.

 

I have taken a look at your code and I think the reason for your shaky sine wave is due to the inherent processing power when using your OS. Typically your computer will only be able to process information at about 1 kHz. The code inside your while loop takes time to process and hence with an absolute max of about 1kHz sample rate on your computer the data you are receiving is unrepresentative of the true values. An easy way to see this is to use the wait(ms) function at different settings and view the resultant graph (also try 0 ms wait).

 

I have re-coded your vi to avoid using a formula node as this provides the processor with more tasks to complete (greater overhead). Also avoiding the use of property nodes is always advised to alleviate some of the stress on the processor. You will still not be able to generate a sine wave at 10kHz though.

 

An alternative to how you are generating your signal is to use a simulate signal express vi. What this does is simulate the signal and buffer this until it is finished after which it outputs the data. You could add a time factor in by altering the number of samples generated per simulation for each frequency. This will allow you to simulate any frequency provided the number of samples per second is at least twice that of the frequency (the higher, the better the waveform).

 

I hope this information helps you with your project.

 

Kind Regards,


Larry Colvin
Associate Principal Engineer
Dyson Technology Ltd.

0 Kudos
Message 3 of 7
(2,580 Views)

hi Laurence C,

 

I have followed your advice and add a simulate express vi.

 

However, I don't see how I can add the time factor.

 

And what about the other part of my question, being :

 

"Instead of changing the frequencies every 10s, I want to keep the same frequency for a certain number of period. Like keep the same frequency for 100 periods (between 10KHz and 10Hz), and then,  5 periods, between 10Hz and the min value."

 

thanks for you help

 

Kentmey
0 Kudos
Message 4 of 7
(2,568 Views)

Hi Kentmey,

 

To add a time factor:

 

Using the simulate signal you are asked how many samples you would like for a particular sampling frequency when you set it up. So if you have a sampling frequency of 10,000 Hz it means you will see 10,000 samples per second. So if you would like to have it run for 10 seconds you require 100,000 samples. set number of samples = sampling frequency * time (s)

 

To base it on periods:

 

Simply set the number of samples you require to number of periods required * (sampling frequency / signal frequency).

 

To change the number of samples you can look in properties (see attached picture)

 

I hope this information helps you with your project.

 

Kind Regards,


Larry Colvin
Associate Principal Engineer
Dyson Technology Ltd.

0 Kudos
Message 5 of 7
(2,556 Views)

Sorry, but I can't write any formula for the number of sample.

 

Or I didn't get clearly what you had in mind.

Kentmey
0 Kudos
Message 6 of 7
(2,543 Views)

Hi Kentmey,

 

When using express vi's many of the settings can only be accessed via the properties dialog box. If you wanted to use the express vi you could use case structures to change how the waveform generates as frequency changes.

 

A much simpler solution though would be to use the following vi:

 

Functions Pallette >> Signal Processing >> Waveform Generation >> Sine Waveform.vi

 

This vi will perform the same function as the express vi but also has a terminal called sampling info. This sampling info is a cluster of 2 numerics. The first is sampling frequency and the second is number of samples.

 

I hope this helps!

 

Kind Regards,


Larry Colvin
Associate Principal Engineer
Dyson Technology Ltd.

0 Kudos
Message 7 of 7
(2,530 Views)