LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Releationship between sample rate and number of samples

Solved!
Go to solution

I writing an application to write 60 Hz analog output signal to 9 channels. I picked 400 as the number of samples (

numSampsPerChannel) . I calculated the sample_rate using the relationship 

numSampsPerChannel = sampleRate * (1/ frequency). I calculated a sample_rate of 24000 which I used as input to  DAQmxCfgSampClkTiming functions. I used 400 as the number of samples per channel. I used the code below to get my data. When I plot the data for one channel, the 400 samples corresponds to only one sine wave. I had expected 60 sine waves which I thought was calculated using a one second interval divided by 400. To get the full 60 cycles, I need to set numSampsPerChannel the same as the sample_rate. I thought I had to follow numSampsPerChannel = sampleRate * (1/ frequency). When is this formula applicable? The program runs and does not complain about setting the sample_rate the same as numSampsPerChannel.

 

for (; i < numSampsPerChannel; i++)
	{
		for (; j < numChannels; j++) {
			offsetIndex = phaseOffsets[j] * PI / 180.0;
			
			if (j == 1) {
				data[j *  numSampsPerChannel + i] = amplitude[j] * sin((double)i*2.0*PI / (samplingRate / sineWavefrequency2) + offsetIndex);
			}
			else {
				data[j *  numSampsPerChannel + i] = amplitude[j] * sin((double)i*2.0*PI / (samplingRate / sineWavefrequency) + offsetIndex);
			}

			}
		j = 0;
	}
0 Kudos
Message 1 of 2
(2,380 Views)
Solution
Accepted by topic author carlosjbb

Hi,

The behaviour is consistent with your code. Your expectations are not correct.

Generically;

numSamples = sampleRate * timeInterval

(note: the unit of sampleRate is samples/sec)

If timeInterval = (1/frequency) = period = ~0.01667 sec, then you acquire a period length of samples, which is obviously a single sine cycle.

If timeInterval is 1 sec, you get the number of samples requierd to acquire 1 second length of samples. Which includes 60 cycles, because your signal is 60cycles/second.

When timeInterval is 1 sec, numSamples becomes equal to sampleRate.

So theory matches with your experience. You should reconsider your expectations.

Hope this helps,

S. Eren BALCI
IMESTEK
0 Kudos
Message 2 of 2
(2,353 Views)