Chris
Chris

Reputation: 115

Creating a 1D Second derivative of gaussian Window

In MATLAB I need to generate a second derivative of a gaussian window to apply to a vector representing the height of a curve. I need the second derivative in order to determine the locations of the inflection points and maxima along the curve. The vector representing the curve may be quite noise hence the use of the gaussian window. What is the best way to generate this window? Is it best to use the gausswin function to generate the gaussian window then take the second derivative of that? Or to generate the window manually using the equation for the second derivative of the gaussian? Or even is it best to apply the gaussian window to the data, then take the second derivative of it all? (I know these last two are mathematically the same, however with the discrete data points I do not know which will be more accurate)

The maximum length of the height vector is going to be around 100-200 elements.

Thanks Chris

Upvotes: 1

Views: 1558

Answers (1)

stevejpurves
stevejpurves

Reputation: 933

I would create a linear filter composed of the weights generated by the second derivative of a Gaussian function and convolve this with your vector.

The weights of a second derivative of a Gaussian are given by:

Second Derivative of a Gaussian

Where:

  • Tau is the time shift for the filter. If you are generating weights for a discrete filter of length T with an odd number of samples, set tau to zero and allow t to vary from [-T/2,T/2]
  • sigma - varies the scale of your operator. Set sigma to a value somewhere between T/6. If you are concerned about long filter length then this can be reduced to T/4
  • C is the normalising factor. This can be derived algebraically but in practice I always do this numerically after calculating the filter weights. For unity gain when smoothing periodic signals, I will set C = 1 / sum(G'').

In terms of your comment on the equivalence of smoothing first and taking a derivative later, I would say it is more involved than that. As which derivative operator would you use in the second step? A simple central difference would not yield the same results.

You can get an equivalent (but approximate) response to a second derivative of a Gaussian by filtering the data with two Gaussians of different scales and then taking the point-wise differences between the two resulting vectors. See Difference of Gaussians for that approach.

Upvotes: 1

Related Questions