2
votes

I've written a simple 1D gaussian filter that I'm convolving with some signal data to produce a smooth trace. The only problem is that when I convolve the data I get major drop near the start and end points of my smoothed signal data. When I plot the data it just warps my graph because it's trying to plot signal values that are like 10 at the start and end, when all my other data is like 10,000-13,000.

Anyone know of any ways to circumvent this/ prevent zero padding of the convolution?

Heres my code:

smooth_signal = conv2(signal_full, 1d_gaus,'same');

Where my input signal_full is a 1055x1 double matrix.

1
Normally you'd take just the 1055 samples from the center of the output. - Ben Voigt
Why conv2 and not conv? What is 1d_gaus? seems that this variable effects the results, try to adjust it. And, I think that "zero padding" is not the term, or i didn't get your question. - Adiel
@BenVoigt I think that the same propety should do it automatically - Adiel
True. Have you seen the other option 'valid' Returns only those parts of the convolution that are computed without the zero-padded edges. - Ben Voigt
Ok so 1d_gaus is just the output of a 1D gaussian function, based on an x of -20:20 and a sigma of 5, so a 41x1 double matrix. Basically what I have at the moment is some noisy signal data that needs to be smoothed and plotted against some time data that starts at 0 seconds and ends at 1000s. Just tried the 'valid' option of the conv function (Adiel is quite right, I don't need to do the conv2 function) However this outputs only a 990 x 1 signal matrix, how would I adjust my time data so it matches up with my new 990 element smoothed signal? - user3168953

1 Answers

1
votes

Use nanconv.m instead (File Exchange link), with the 'edge' input argument. This handles timepoints beyond the boundaries as missing values instead of zeros, hence eliminating edge effects.