12-12-2011 09:45 PM
I have a square sygnal, 25000 samples.
1. When I call
NationalInstruments.Analysis.SpectralMeasurements.MultipleToneInformation mi = new NationalInstruments.Analysis.SpectralMeasurements.MultipleToneInformation
(signal, samplingFrequency,threshold, maximumToneCount,
tonesSortingOrder == TonesSortingOrder.DecreasingAmplitude?
NationalInstruments.Analysis.SpectralMeasurements.ToneSortingOrder.DecreasingAmplitude:
NationalInstruments.Analysis.SpectralMeasurements.ToneSortingOrder.IncreasingFrequency );
I have always results according to the ToneSortingOrder.IncreasingFrequency, even when I request ToneSortingOrder.DecreasingAmplitude
2. When I call
NationalInstruments.Analysis.SpectralMeasurements.SingleToneInformation si = new NationalInstruments.Analysis.SpectralMeasurements.SingleToneInformation(signal, samplingFrequency);
The samplingFrequency value is , but consitent with result above: the returned frequency is always equal to the first frequency
NationalInstruments.Analysis.SpectralMeasurements.MultipleToneInformation created with option ToneSortingOrder.IncreasingFrequency
12-14-2011 12:08 PM
Hello gremlm,
Thank you for contacting National Instruments support. My name is Shawn.
I was unable to reproduce the issue on my end and I used the following code.
double samplingFrequency = 1000;
double threshold = 0;
int maximumToneCount = 10;
BasicFunctionGenerator sigGen = new BasicFunctionGenerator(BasicFunctionGeneratorSignal.Sine,100,10);
double[] signal = sigGen.Generate();
ToneSortingOrder toneSortingOrder = NationalInstruments.Analysis.SpectralMeasurements.ToneSortingOrder.DecreasingAmplitude;
//toneSortingOrderResult is matching toneSortingOrder as expected
ToneSortingOrder toneSortingOrderResult = (toneSortingOrder == NationalInstruments.Analysis.SpectralMeasurements.ToneSortingOrder.DecreasingAmplitude ?
NationalInstruments.Analysis.SpectralMeasurements.ToneSortingOrder.DecreasingAmplitude :
NationalInstruments.Analysis.SpectralMeasurements.ToneSortingOrder.IncreasingFrequency);
NationalInstruments.Analysis.SpectralMeasurements.MultipleToneInformation mi = new NationalInstruments.Analysis.SpectralMeasurements.MultipleToneInformation
(signal, samplingFrequency, threshold, maximumToneCount, toneSortingOrderResult);
I did notice that in your post the ToneSorting class had an extra 's' in it. As well, I would verify the value of the toneSorting property before this code executes.
I'm also not sure what the problem was with the second issue you mentioned. Would you please clarify?
12-15-2011 05:23 PM
Hi Shawn,
The problem I have described can't be verified with sygnal having only one frequency, as you setup in your example.
you should try sygnal wich is a sum of multiple singletones with different frequencies and amplitude:
public static int MultipleToneInformation(double[] signal, double samplingFrequency, double threshold, int maximumToneCount,
ToneSortingOrder tonesSortingOrder,
out double[] amplitudes, out double[] frequencies, out double[] phases )
{
NationalInstruments.Analysis.SpectralMeasurements.MultipleToneInformation mi = new NationalInstruments.Analysis.SpectralMeasurements.MultipleToneInformation
(signal, samplingFrequency,threshold, maximumToneCount,
tonesSortingOrder == TonesSortingOrder.DecreasingAmplitude?
NationalInstruments.Analysis.SpectralMeasurements.ToneSortingOrder.DecreasingAmplitude:
NationalInstruments.Analysis.SpectralMeasurements.ToneSortingOrder.IncreasingFrequency );
amplitudes = mi.GetAmplitudes();
frequencies = mi.GetFrequencies();
phases = mi.GetPhases();
return mi.DetectedToneCount;
}////////////////////////////////////////////////////////////
We have sygnal with 5 frequences, so our result arrays have 5 items
amplitudes.Length == 5
frequencies.Length == 5
phases.Length == 5
and we tried to to pass
tonesSortingOrder = ToneSortingOrder.IncreasingFrequency to our function, the values in the
the result arrays amplitudes, frequencies, phases
still are sorted according to the DecreasingAmplitude.
If you have a sygnal having only one frequency, your arrays will have only one item and sorting allways be the same!
You need a signal with multiple frequences, where each harmonics havre different amplitudes but order of the amplitudes not the same as frequences, i.e. something like this:
first tone amplitude A1 = 10, frequency F1 = 50;
second tone amplitude A2 = 20, frequency F1 = 100;
When ToneSortingOrder.DecreasingAmplitude is set, the result should be
amplitudes[0] = 20;
amplitudes[1] = 10;
frequencies[0] = 100;
frequencies[1] = 50;
When ToneSortingOrder.IncreasingFrequency is set, the result should be
amplitudes[0] = 10;
amplitudes[1] = 50;
frequencies[0] = 50;
frequencies[1] = 100;
but in the case like the last one I still see the data ToneSortingOrder.DecreasingAmplitude is set!
12-16-2011 04:53 PM
Hello gremlm,
We were able to get the function to operate successfully on our end with the following code. Please try it on your end.
namespace WindowsApplication8
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
double samplingFrequency = 1000;
double threshold = 0;
int maximumToneCount = 10;
BasicFunctionGenerator sigGen = new BasicFunctionGenerator(BasicFunctionGeneratorSignal.Triangle,100,10);
double[] signal = sigGen.Generate();
//ToneSortingOrder toneSortingOrder = NationalInstruments.Analysis.SpectralMeasurements.ToneSortingOrder.IncreasingFrequency;
//toneSortingOrderResult is matching toneSortingOrder as expected
//ToneSortingOrder toneSortingOrderResult = (toneSortingOrder == NationalInstruments.Analysis.SpectralMeasurements.ToneSortingOrder.DecreasingAmplitude ?
//NationalInstruments.Analysis.SpectralMeasurements.ToneSortingOrder.DecreasingAmplitude :
//NationalInstruments.Analysis.SpectralMeasurements.ToneSortingOrder.IncreasingFrequency);
NationalInstruments.Analysis.SpectralMeasurements.MultipleToneInformation mi = new NationalInstruments.Analysis.SpectralMeasurements.MultipleToneInformation
(signal, samplingFrequency, threshold, maximumToneCount, NationalInstruments.Analysis.SpectralMeasurements.ToneSortingOrder.IncreasingFrequency);
// add breakpoint here to watch results from previous line of code
mi = new NationalInstruments.Analysis.SpectralMeasurements.MultipleToneInformation
(signal, samplingFrequency, threshold, maximumToneCount, NationalInstruments.Analysis.SpectralMeasurements.ToneSortingOrder.DecreasingAmplitude);
// add breakpoint here to watch results from previous line of code
}
}
}
12-20-2011 10:12 AM
Hi Gremlm,
Were you able to try the code that Shawn has provided and was this successful for you?
Regards,
Jackie