Gaussian vector filter in Matlab

I have an n-dimensional vector (1xn dataset, and this is not image data), and I want to apply a Gaussian filter to it. I have an Image Processing Toolkit and several others (ask if you need a list).

Presumably, I can make the hsizefunction parameter fspecialsomething like [1 n]. Can I use imfilterto apply it to my vector as the next step, or do I need to use something else?

I have seen quite a few examples of how to apply a Gaussian filter to two-dimensional image data in Matlab, but I'm still relatively new to Matlab as a platform, so the example will be really good.

Note. I can’t just now try and see what happens (not currently on the machine with Matlab installed), otherwise I would try it first and just ask if I ran into problems using fspecialand imfilter.

+5
source share
1 answer

Why not create a Gaussian filter yourself? You can see the formula in fspecial(or any other Gaussian definition):

sigma = 5;
sz = 30;    % length of gaussFilter vector
x = linspace(-sz / 2, sz / 2, sz);
gaussFilter = exp(-x .^ 2 / (2 * sigma ^ 2));
gaussFilter = gaussFilter / sum (gaussFilter); % normalize

and to use it you can use filter:

y = rand(500,1);
yfilt = filter (gaussFilter,1, y);

, , , . , conv filter same:

yfilt = conv (y, gaussFilter, 'same');
+15

All Articles