02-03-2015 10:16 AM
First, I'm developping with Visual Studio 2010, Measurement Studio 2013, NI-DAQmx 14.0, Framework 4.0, Windows 7, NI-PCI 6250
At the date of today, i'm testing C# & Measurement studio / daq mx and I don't use daq assistant (see post : I created here)
I'm acquiring an analog signal, plotting it, get an FFT and plotting it.
I would like to make some real time analysis thanks to the FFT plot.
At start my FFT is shown on all the frequency domain I study (10 Hz to 350kHz)
I changed Range thanks to a toolstrip I made : Start Freq, Stop Freq.
I get my zoom, cool.
but how can I make my library reprocess the FFT between the start and stop frequency to get a better definition ?
If I do things wrong from the start any advice is welcome 🙂
Code :
private void AnalogInCallback(IAsyncResult ar)
{
try
{
if (taskRunning)
{
//Read the available data from the channels
data = analogInReader.EndReadMultiSample(ar); //data is double[,]
//Plot your data here
waveformGraph1.PlotYMultiple(data);
analogInReader.BeginReadMultiSample(SAMPLES_PER_CHANNEL, analogCallback, null); //repetition de la ligne du Start_Click pour MAJ dans le runtime
// Generate the complex signal and apply the selected window to it
NationalInstruments.ComplexDouble[] complexSignal = new NationalInstruments.ComplexDouble[SAMPLES_PER_CHANNEL - 1];
for (int i = 0; i < complexSignal.Length; i++)
{
complexSignal[i] = new NationalInstruments.ComplexDouble(data[0, i], data[0, i]);
}
ScaledWindow.CreateHammingWindow();
// Display the power spectrum
double[] powerSpectrum = Transforms.PowerSpectrum(complexSignal);
freqDomainWaveformGraph.PlotY(powerSpectrum);
}
private void toolStripStart_Click(object sender, EventArgs e)
{
if (!taskRunning)
{
try
{
myTask = new Task("aiTask");
//Create a virtual channel myTask.AIChannels.CreateVoltageChannel("Dev1/Ai0",
"aiChannel",
AITerminalConfiguration.Differential,
Convert.ToDouble("-2"),
Convert.ToDouble("+2"),
AIVoltageUnits.Volts);
//Configure the timing parameters
myTask.Timing.ConfigureSampleClock("", SAMPLE_FREQUENCY,
SampleClockActiveEdge.Rising,
SampleQuantityMode.ContinuousSamples, SAMPLES_PER_CHANNEL);
//Verify the Task
myTask.Control(TaskAction.Verify);
taskRunning = true;
analogInReader = new AnalogMultiChannelReader(myTask.Stream);
//analogInReader.SynchronizingObject = this;
analogCallback = new AsyncCallback(AnalogInCallback);
analogInReader.BeginReadMultiSample(SAMPLES_PER_CHANNEL, analogCallback, null);
}
When I click on OK button in my toolstrip
private void butt_FreqDomain_OK_Click(object sender, EventArgs e)
{
double a, b, c;
a = Double.Parse(text_StartFreq.Text);
b = Double.Parse(text_StopFreq.Text);
c = a + (b - a)/2;
text_CenterFreq.Text = c.ToString();
freqDomainPlot.XAxis.Range = new NationalInstruments.UI.Range(Double.Parse(text_StartFreq.Text), Double.Parse(text_StopFreq.Text));
}
Captures :
without zoom
With zoom
Second question :
I'm generating a 55kHz Wave signal, where is the problem ? why the fundamental is at 55002 ~55003 Hz ?
Thank you in advance
02-19-2015 11:14 AM
Hello,
If you want to have more precision you could take more point using FFT zero padding : http://www.bitweenie.com/listings/fft-zero-padding/
An another solution is to use the FFT Zoom function which is use in CVI labwindows, we can find it in “NI Spectral Measurement Toolkit C”.
Here is the explanation : http://www.ni.com/white-paper/3995/en/
I hope this could answer your first question.
Regards,
Maxime G. | Application Engineer
National Instruments France