Hello
I am using Microsoft Visual C++ 6.0 and using C API's provided in NIDAQ861.exe. The code i write to read single analog input simulated channel of simulated PCI 6255 device is given below.
#include<NIDAQmx.h>
#include<iostream.h>
#include<stdio.h>
int main(void)
{
FILE *fptr;
fptr=fopen("NI_test1.bin","wb");
TaskHandle taskHandle=0;
int ch_no=1;
char chan[256] = "Dev1/ai0";
float64 min = -1, max = 1;
char clockSource[256] = "";
float64 rate =3200;
int samp_per_chan = 20000;
int32 *s1;
s1 = new int32[samp_per_chan];
double *dat1;
dat1 = new double[ch_no*samp_per_chan];
bool32 *dat;
dat = new bool32[256];
DAQmxGetDevIsSimulated(chan,dat);
cout<<*dat<<endl;
DAQmxCreateTask("",&taskHandle);
DAQmxCfgSampClkTiming(taskHandle, clockSource, rate, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, samp_per_chan);
DAQmxCreateAIVoltageChan(taskHandle ,chan ,"", DAQmx_Val_RSE, min, max, DAQmx_Val_Volts, NULL);
DAQmxStartTask(taskHandle);
DAQmxReadAnalogF64(taskHandle, samp_per_chan, 10.0, DAQmx_Val_GroupByChannel ,dat1, ch_no*samp_per_chan, s1, NULL);
fwrite( dat1, sizeof( double ),ch_no*samp_per_chan,fptr );
DAQmxStopTask (taskHandle);
DAQmxClearTask (taskHandle);
delete [] dat1;
delete [] s1;
fclose(fptr);
return 0;
}
First, Kindly tell me if there is any thing wrong in this code?
Now i read the binary file generated above(NI_test1.bin) in MATLAB and plotted it, it show me 20 cycles of sine wave with each cycle consisting of 1000 points. After this i plot its frequency spectrum (using PSD of MATLAB with fs=3200, fft_siz=1024) , i could not see any particular peak at any frequency ?
Kindly explain if anything wrong with this approach? and how frequency spectrum should look like in above case?