LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Want to create a gaussian smoothing function in LabView

Hello all,

 

I want to smooth a signal in real-time using Gaussian smoothing and convolution functions. First I did it in MATLAB as a post-processing for smoothing the data, but whenever I try to implement it in Mathscript or the formula node of Labview for realtime processing it continuously gives error and does not working. For reference, I have attached the MATLAB code.

 

Any help will be appreciated.

 

Regards,

Ronak

 

sigma = 10; % Standard deviation of the Gaussian
sz = 100; % Size of the Gaussian kernel
% Generate the Gaussian kernel
x = linspace(-sz / 2, sz / 2, sz);
gaussian_kernel = exp(-x.^2 / (2 * sigma^2)) / sqrt(2 * pi * sigma^2);
% Normalize the Gaussian kernel
gaussian_kernel = gaussian_kernel / sum(gaussian_kernel);
% Convolve the signal with the Gaussian kernel
smoothed_signal = conv(signal, gaussian_kernel, 'same');
0 Kudos
Message 1 of 9
(656 Views)

Hi Ronak,

 


ronakvyas971@gmail.com wrote:

whenever I try to implement it in Mathscript or the formula node of Labview for realtime processing it continuously gives error and does not working.


Why do you try to use MathScript or the formula node?

Which errors do you get?

 

Why not use "real" LabVIEW?

(Please check for correct execution, my Matlab is a bit rusty… Accidently set sigma to 100 instead of 10.)

 

Hint: There also is a convolution function in the SignalOperations functions palette!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 9
(630 Views)

Hey,

 

Thanks, for the quick response. I saw your LabView code and will try to implement it in my VI. The reason for utilizing math script is that I never utilized the Gaussian Function in Labview. So, I went for Mathscript or Formulanode. The main reason behind doing this process is I have my force signal and want to convert that into the smooth exponential signal with smooth increase and decrease signal that corresponds to my original signal with the same amplitude. So, to perform that I choose mathscript. I have also attached my force signal (original) and the required signal (smooth) picture, which did in Matlab. 

However, the VI you made, there is not have any information about convolution.

 

It would be great if you could help me to get over this.

 

 

ronakvyas971gmailcom_1-1702883741770.png

 

 

 

0 Kudos
Message 3 of 9
(619 Views)

There is a Convolution.vi already implemented in LabVIEW, you might want to try that.

 

https://www.ni.com/docs/en-US/bundle/labview-api-ref/page/vi-lib/analysis/2dsp-llb/convolution-vi.ht...

0 Kudos
Message 4 of 9
(596 Views)

ronakvyas971@gmail.com wrote:

I want to smooth a signal in real-time using Gaussian smoothing and convolution functions.


First you need to define your use of the word "real-time", because it can have very specific meaning.

 

If your data arrives one point at a time and you want to smooth, you need would need to use the ptbypt convolution function (I have not tried it). If it is just about getting rid of noise, there are plenty of other ptbypt filters you could try.

 

A very lightweight filter for realtime data is an exponential filter, which often works great.

0 Kudos
Message 5 of 9
(547 Views)

ronakvyas971@gmail.com wrote:

 

It would be great if you could help me to get over this.

 

 

ronakvyas971gmailcom_1-1702883741770.png


Obviously, you cannot get that red result in "realtime" because the red curve requires future data (e.g. it rises before the blue curve rises!), so this kind of analysis can only be done with a significant time delay (or in post processing).

 

As a first step, explain the experiment and how much data you get as a function of time and what you want to see during acquisition.

 

It would be easiest to attach a Vi containing some sample data.

0 Kudos
Message 6 of 9
(544 Views)

Hey, 

 

Thank you for looking into this. For your reference, I have attached the sample data file in that DFP column data will come in real-time, which is a force signal coming from the motor and is not in proper form like a bell-shaped curve. From that signal, I have to control some devices for that the force signal needs to be in proper form like bell shape curve or smooth. But the signal that I'm getting is in a kind of square signal with sudden increase and decrease, but I want to smooth it. For the first, I went for that gaussian function with kernel, and I'm still trying to fit it in LabView. However, all these operations will need to be performed in real-time.  For your reference, I have attached the some sample data. The VI is same as I mentioned for the first time, and I wrote that whole Matlab code in the math script of Labview. Hope to hear soon.

0 Kudos
Message 7 of 9
(535 Views)

@GerdW wrote: 

 


Also note that that entire division business (and sqrt, time pi, etc)  is completely pointless if we later divide by the sum, of course. (not blaming Gerd here, it's just a literal translation of the original text code). Also, the "negate" should be done on the scalar, not on the array, of course)

0 Kudos
Message 8 of 9
(529 Views)

See if this can give you some ideas. Probably needs a few tweaks...

 

altenbach_0-1702923022964.png

 

 

Note that that size=x option is only available for 2D convolutions for some unknown reason reason)

0 Kudos
Message 9 of 9
(512 Views)