Question 1 - How do you use a Savitzky-Golay filter and not lose points at the ends of the data
The Savitzky-Golay algorithm is a convolution algorithm, so it will reduce the number of points available by the width of the filter. However, there are two good options for dealing with this, one trivial, the other difficult.
- Trivial - take more data than you need and toss the extra points when you are finished with the convolution. This is what I have always done. If you use the code I posted, it will take a 5 to 19 point filter width (less to more filtering). You will need to toss (n-1)/2 points from each end, where n is the filter width.
- Difficult - If you have no control over the number of points and you need to preserve it, you will need to generate several Savitzky-Golay filters (requires coding the Savitzky-Golay algorithm - code I posted is a look-up table). The Savitzky-Golay filter is the mathematical equivalent of taking the points in the filter width, calculating a least-squares polynomial fit to them, then using the fit to calculate the value of the point of interest in the curve. Normally, the point of interest is the center point in the filter. To fill in the edges, you need to calculate the Savitzky-Golay coefficients for a point not in the center of the filter width. Of course, since you are only using these filters once, it would probably be more efficient to use a standard polynomial least squares fit. The results will be identical (barring weird algorithm round-off error issues).
Take home message. Use
S-G Operation.vi to filter your data. If you can, take more data than you need and toss the ends after the filter. If you can't take more data, use
General Polynomial Fit.vi to calculate the quadradic or cubic fits then back calculate the value using standard formulae for each of the end points. I have not looked at the Sciware code. It may already do this for you.
Question 2 - How do you get a Y-axis graph on both sides of a LabVIEW graph
These instructions are for LabVIEW 7.1. I have not checked them for other versions.
- Pop up on the existing Y-axis scale and select Duplicate Scale. You should now have two scales on the left of your graph.
- Pop up on the newly created scale and select Swap Sides. You will now have a scale on both ends of your graph.
However, there is a caveat. Data in a LabVIEW graph is associated with one and only one scale. As such, the new scale will not autoscale with data, since it is not associated with any data. If you want this behavior, it is easiest to turn autoscale off both axes and do the scaling yourself. Alternately, you can write data to the graph, read the autoscaled values from one scale (use graph property node) and write them to the other. I have not tried this. You may need a delay between the data write and the read of the autoscaled axes parameters to allow the autoscale to occur.