03-19-2016 10:59 AM - edited 03-19-2016 11:16 AM
Hi, I am able to get the maximum amplitude from a data but I also want to get its corresponding X-Axis value. How do I do that?
Here's a look at the reading in my Front Panel:
Looking at the TDMS file of my data. It can be seen that 2.9238 (amplitude) is actually the highest. However, the displayed Fundamental Frequency is not the corresponding value of the highest amplitude.
Solved! Go to Solution.
03-19-2016 11:32 AM - edited 03-19-2016 11:32 AM
I would do something like this. I have two elements in the cluster: the Amplitude and the Frequency, in that order. You can then use the Max & Min on the cluster. Make sure the Max & Min has the comparison mode set to "Aggregates". It will compare the first element first, which is why you want the amplitude to be the first element in the cluster.
03-19-2016 11:37 AM
Hi Jerson,
In your code you are writing values of amplitude and fundamental frequency for each iteration of the For Loop. So each amplitude corresponds to its fundamental frequency.
To find the highest amplitude, for each iteration amplitude value is being compared with the highest value got during previous iterations, so after the loop is finished, you get the highest amplitude.
While the fundamental frequency shown on the indicator is just the last recorded value, as it can be seen also from your screenshots.
To find the fundamental frequency corresponding to the highest amplitude you can write it also to a shift register, as the amplitude, but you should update the shift register value, only in case the maximum value of the amplitude was changed.
Thanks,
Arev
CTO | RAFA Solutions
03-19-2016 01:26 PM
@JersonJose wrote:Hi, I am able to get the maximum amplitude from a data but I also want to get its corresponding X-Axis value. How do I do that?
You are mixing waveform and dynamic data, which is a bit confusing.
After the transform, you'll have a new waveform where x is frequency instead of time, bu all you need is tap into the "max time" output of waveform min&max to get the generic x-value corresponding to the maximum amplitude. Convert it to DBL for a more intuitive value. Now keep track of it in a shift register, similar to the max value and replace it whenever a higher max is found.
03-21-2016 12:56 AM
@arevh wrote:To find the fundamental frequency corresponding to the highest amplitude you can write it also to a shift register, as the amplitude, but you should update the shift register value, only in case the maximum value of the amplitude was changed.
How do I update the shift register connected to the fundamental frequency when the highest amplitude is gathered? Am I going to use a specific block for this one?
03-21-2016 01:33 AM
Hi Jerson,
You can implement something like this.
Check if the highest value was updated, and if yes, write appropriate frequency to the shift register.
You can try also implementing solution suggested by crossrulz.
Thanks,
Arev
CTO | RAFA Solutions
03-21-2016 10:21 AM
Hi arevhamb,
I tried what you suggested and it is working perfectly! Thank you very much for your help and inputs.
03-21-2016 02:51 PM
@JersonJose wrote:
I tried what you suggested and it is working perfectly! Thank you very much for your help and inputs.
One flaw is the fact that several frequencies could have the same amplitude, so this code give the highest frequency that matches that amplitude. If you want e.g. the lowest frequency with that amplitude, you would need to rearrange the code a little bit.
(Yes, comparisons with DBL are quite unlikely to produce an equal, especially after fancy transforms, but the theoretical possibility exists. The current code is not bulletproof.)
It is also a really bad habit to initialize the shift register with zeroes here, because it makes the code too specialized and it cannot ber re-used for seemingly similar, but slightly different problems. For example if you try to re-use the code for a case where all amplitudes are negative, the uninteresting zero would always be the largest. You should initialize the upper shift register with -inf and the lower with NaN, for example. The current code is not universal.