Signal Generators

cancel
Showing results for 
Search instead for 
Did you mean: 

SignalGeneration.SquareSignal Generate() - buffer same for different frequencies ?!

I came across wierd behaviour of the Generate() method.

 

I want to create 2 buffers, one for each signal with different frequency.

for example sake, lets assume:

signal1: 1khz

signal2: 200hz

 

i want to create 2 buffers, both with same number of samples, only each one with different frequency.

 

So i've made following code:  

 

NationalInstruments.Analysis.SignalGeneration.SquareSignal tmp_signal1 = new NationalInstruments.Analysis.SignalGeneration.SquareSignal(1000, 2.5, 0, 50); double[] adMyBuffer1 = tmp_signal1.Generate(2*1000,10); NationalInstruments.Analysis.SignalGeneration.SquareSignal tmp_signal2 = new NationalInstruments.Analysis.SignalGeneration.SquareSignal(200, 2.5, 0, 50); double[] adMyBuffer2 = tmp_signal2.Generate(2 * 200, 10);

 

My logic would be to expect the buffer generated from lower frequency signal, would be different,

but when i run it, both end up with same results:

adMyBuffer1 holds {2.5, -2.5, 2.5, -2.5, ...}

adMyBuffer2 holds {2.5, -2.5, 2.5, -2.5, ...}

 

while i was hoping to get perhaps something like:

adMyBuffer1 holds {2.5, -2.5, 2.5, -2.5, ...}

adMyBuffer2 holds {2.5, 2.5, 2.5, -2.5, -2.5, -2.5, 2.5...} (depands on frequency, but something different).

 

Meaning, i was hoping to get some buffer array that would allow me to write it with high frequncy to AO channel, but would still produce a lower frequency signal... 

 

Code Note: On both signals, i gave sampling rate to be x2 (nyquist).

 

would appreicate any help as to why this is working like this, and what am i missing in here...

Or if my approach was wrong, what would be the correct approach to get 2 buffers, each with same number of cycles, but have 1 produce signal with high frequncy and another with low frequency.

 

regards.

Idan

 

0 Kudos
Message 1 of 4
(6,916 Views)

Hi Idan,

 

Just for my information, what hardware are you using? It appears that you are trying to build buffers that output a 1 kHz square wave and a 200 Hz square wave.  To do this, you will have to sample much higher than the Nyquist frequency.  Nyquist will ensure that the frequency information is correct, however, to see the shape of the signal, you will have to sample 10x or more.  The picture below will show what I am talking about - this is a sine wave, but the fundamentals are the same.

sample rate.JPG

 

To answer your question, your buffers have to be the same, otherwise, you will get errors when you actually start generating with DAQmx.  This is because our DAQ cards only have 1 analog output timing engine. In order to create 2 signals, both signals will have to be the same length, so you will not be able to output the same number of cycles. 

Regards,
Jim Schwartz
Message 2 of 4
(6,902 Views)

I'm using Analog Out card (NI6723).

During my testing & "playing" with code, i did gave higher sampling rate than 2.

When i saw it doesnt work in any of those methods, i posted 2 to clear my point in this question.

it seems that even when i do 100 samples per frequency, still, the two buffers contain exactly same data array...

 

It looks like a bug with "SquareSignal" class, as when i'm using the "BasicFunctionGenerator" it seems to work ok...

Message Edited by idanbis on 11-11-2009 12:03 AM
0 Kudos
Message 3 of 4
(6,896 Views)

Hi idanbis,

 

This is because your buffer is 2*frequency in both cases.  If this is the case, both will always have the same buffer - one high and one low.  What you should be doing is sampling the 1 kHz one wherever you need then set that same sample rate at the 200 Hz signal.  What I am basically saying is both arrays should have the same number of points so .Generate() should be the same.

Regards,
Jim Schwartz
0 Kudos
Message 4 of 4
(6,869 Views)