Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Using ComponentWorks++ how can I get a FrequencySpectrum with amplitude values every 100Hz?

When I call AutoPowerSpectrum() I get a frequency spectrum where each frequency is evenly spaced over the possible frequency range given the sampling rate used. The number of frequencies out of AutoPowerSpectrum() is half of the size of the sample provided to AutoPowerSpectrum() with each evenly spaced.

What I need in this specific case is the amplitude of frequencies starting at 200Hz up to and including 20kHz in 100Hz increments?

Is the common solution just to grab the amplitude of the frequency closest to what I am looking for? This doesn't look attractive because sometimes the closest doesn't appear to be of the expected amplitude where the next frequen
cy does.

Thanks in advance.
0 Kudos
Message 1 of 7
(4,225 Views)
Hello JackMetcalfe,
The question is, do you want the average or maximum amplitude of the signals in each frequency range (200-300hz for example)? If you want the average, you can use the CNiMath::Mean method on each frequency range by using the CNiVectorT::Subset method. If you simply want the maximum amplitude in each range, that is also easy to calculate using Subset with the MinMax method. If I have misunderstood your question, please clarify with additional details.

Jeremiah Cox
Applications Engineer
National Instruments
http://www.ni.com/ask
0 Kudos
Message 2 of 7
(4,225 Views)
I want the peak amplitude at 100Hz, 200Hz, 300Hz, ... up to 8000Hz.

When I use the functions mentioned in the initial e-mail I have very little control over the frequencies for which amplitudes are reported.

The little control I have is by varying my sample rate and the size of my sample. If I ballon the size of the sample I may get such a small increment that I can get a value for a frequency very close to each desired value. But this seems like an inefficient approach.

Thanks for your help,
Jack
0 Kudos
Message 3 of 7
(4,225 Views)
Jack,

In order to get the spectrum you want, the most important factors are your sampling rate and the number of samples you pass in to AutoPowerSpectrum. In order to get valid results for signals of up to 20kHz, you must sample your signal at a rate of at least 44kHz (multiply the frequency of the highest signal you are interested in by 2.2).

The next step is to acquire a large enough number of samples to get the resolution you need. The resolution is arrived at by dividing your sample rate by the number of samples. For instance, at 44kHz, 440 samples will give you a resolution of 100Hz. This means that the first number of your spectrum will be the total power from 0 to 100Hz, the second number will be for 100-200Hz, etc. If you need the bands to be centered aroun
d 100, 200, etc, then using 880 samples will give you a resolution of 50Hz. After calling AutoPowerSpectrum, throw out the first number of the result, add the second and third numbers to give you the total power from 50-150Hz. The sum of the fourth and fifth will be the total power from 150-250Hz, etc. If you need smaller bands, increase the number of samples accordingly.

Tony
0 Kudos
Message 4 of 7
(4,225 Views)
I appreciate your response but the problem is that AutoPowerSpectrum wants the number of samples in a power of 2. As a result none of the number of samples you mention will work.

I could use a sample rate of 32,768 with 8,192 samples so that I have a resolution of 4Hz and then sum them up on even 100Hz boundaries. The problem is that 32,768 is below the desired sampling rate. My next chance is 64K which is above the max sampling rate.

Even with that said what I am really after is to find the amplitude at a given frequency not a range of frequencies as the summing you describe would provide. I am new to the field so if this is not how it works let me know.

If I am missing something or should be using a different ComponentWorks::CNiMath function le
t me know.

Thanks for you help,
Jack
0 Kudos
Message 5 of 7
(4,225 Views)
AutoPowerSpectrum does not require that the sampling rate be a power of two, only that the number of samples be a power of two. You should be able to use any sampling rate that your hardware allows.

As far as finding amplitude at a given frequency vs. a range of frequencies, you are always measuring a range of frequencies. It is just a question of whether the range is 90Hz-110Hz or 99.99Hz to 100.01Hz. Just how small the range has to be to suit your needs depends heavily on what the measurement will be used for. Once you know your required resolution, then the needed number of samples can be calculated. Because of the power-of-two requirement, the number of samples and sample rate may have to then be adjusted to get something that fits your needs.


Depending on how strict the requirements for this measurement are, you may want to look in to a dedicated DSA board which would be able to do zoom-FFT measurements. Zoom-FFT is a way to reduce the sample count needed by looking only at a narrow range around the desired frequency and ignoring everything else (i.e. getting the spectrum for only 99-101Hz instead of 0-101Hz). You can call NI or visit http://ni.com/dsa for more information about dynamic signal analyzers.

I hope that helps,
TonyH
Software Engineer
Measurement Studio
0 Kudos
Message 6 of 7
(4,225 Views)
Thanks for the additional input.

I may have things working well enough now. I am using a sampling rate of 51,200 which as you pointed out does not need to be a power of two. This rate will give me values that are multiples of the 100Hz increment I was looking for when I use a sample size that must be a powere of two of 512( 100Hz increments ), 1024 ( 50Hz increments ) and 2048 ( 25Hz increments ).

I didn't know about Zoom-FFT and how the dedicated DSA boards ( ie.) 4551? ) support it. I will keep that in mind as an alternative if this proves inadequate.

Thanks again,
Jack
0 Kudos
Message 7 of 7
(4,225 Views)