LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

What is an effective way to logarithmically bin data with a constant number of points per decade?

Solved!
Go to solution

Hello everyone,

 

I'd like to clean up a log-log plot of Power Spectral Density by binning and averaging so that I have a constant number of points per decade (say 10, just for the sake of argument). Generally, the simplest and cleanest way I can think of getting this done is by searching the incoming array for all points between frequencies A and B, averaging those points, and assigning a frequency (A+B)/2 to the new, averaged bin. However, I'm having trouble figuring out how to access the frequency information I'd need in order to accomplish this. To be more clear, I can imagine if I had two arrays, one which held the calculated frequencies of my incoming data stream, and the other which held and amplitude for each corresponding frequency, that I could search the indices in the frequency array with values between A and B, then average the values in the amplitude array that are between the returned indices, putting them into a new array with a new corresponding frequency array. The process is a little more general that just averaging every ten points, say, because the number of points per decade keeps growing. My main hurdle at the moment, though, is that the voltage amplitudes are an array of values that get fed through the PSD operation, while the frequency part of the waveform seems to be a single-valued continuous DBL. Hopefully I've explained that well enough for someone to shed a little light on my problem. Also, if anybody has a suggestion for a better way to approach the problem please let me know--there must be a fairly simple answer out there, but it's eluding me at the moment. Thanks in advance for the help.

 

-Alex

0 Kudos
Message 1 of 4
(3,106 Views)
Solution
Accepted by topic author atrevely

hi,

 

if I get you right; you have:

an array with the frequencies

an array with the corresponding amplitude values

Next you want to merge parts of the data by averaging on specific frequency ranges. I think there is no 1 VI solution, you will have to write this on your own (:

 

I would start getting min/max of the frequencies and then interpolate a scale fitting your needs (like logarythmic) with the amount of bins you want. This should be an array again.

Next step is to look through the frequency array, check (the first and) the last value within the wanted bin (stop the loop, return the index). This should end you up with an array of indexes. [I guess this is where you can save the most computation time by doing it smart]

Finally, use these indexes to iterate through the amplitude values and do your averaging. Should return an array of the length of your bins array.

Plot in fancy colors and enjoy.

 

Is this about what you plan to do?

0 Kudos
Message 2 of 4
(3,086 Views)

Thanks for the reply. Essentially, yes, that is what I'd like to do. The output of the PSD in the "Spectral Measurements" block gives a cluster of 3 elements, f0, df, and magnitude. f0 is simply a double, like I'd expect, and magnitude is an array of doubles, also like I'd expect. My problem, however, is that df is also simply a double, not an array, and it thus becomes much less clear to me how I'd go about finding the corresponding indices for which magnitudes correspond to which frequencies. Hopefully that makes sense and illuminates my problem a little bit more.

0 Kudos
Message 3 of 4
(3,074 Views)

Hi,

 

so, the cluster works comparable to the waveform cluster (your input). it contains:

a frequency offset, f0 (t0)

the difference between two datapoints of your measurement df (dt)

and the values for the y-axis, in this case the magnitude (data)

Here is an example (I hope I do not show up in the rube goldberg thread with this one) how you can create a linear axis from this:

PSD x-axis.jpg

Maybe it is worth the time to browse through your graph functions, I as logarithmic plotting is already possible:

http://forums.ni.com/t5/LabVIEW/programmatically-change-x-and-Y-axis-to-log-scale/td-p/268337

I guess you need it for some further data manipulation then?

0 Kudos
Message 4 of 4
(3,045 Views)