From: fdfs tank on 10 Feb 2010 15:46 Hello, I need to smooth a 1-D vector. In the smoothing I need to have an option to choose the width of the smoothing function (number of cells). Does anyone know of a gaussian smoothing function? If not, do you know a matlab code I can use to solve this? Thank you.
From: ImageAnalyst on 10 Feb 2010 16:44 conv() can do it. Just convolve your array with your Gaussian window, of whatever length you want, and you're done.
From: fdfs tank on 10 Feb 2010 22:25 How exactly do you this? Sorry, but I have never done such smoothing before. Can you please give me an example code of how this can be done? Thank you.
From: ImageAnalyst on 10 Feb 2010 22:57 "fdfs tank" % Generate sample data. vector = 5*(1+cosd(1:3:180)) + 2 * rand(1, 60); plot(vector, 'r-', 'linewidth', 3); set(gcf, 'Position', get(0,'Screensize')); % Maximize figure. % Construct blurring window. windowWidth = int16(5); halfWidth = windowWidth / 2 gaussFilter = gausswin(5) gaussFilter = gaussFilter / sum(gaussFilter); % Normalize. % Do the blur. smoothedVector = conv(vector, gaussFilter) % plot it. hold on; plot(smoothedVector(halfWidth:end-halfWidth), 'b-', 'linewidth', 3);
From: fdfs tank on 10 Feb 2010 23:11
Great, it works! thank you, A couple of questions: What is int16? why do you need it here instead of just writing the window width as a regular scalar? and why do you plot only the second half of the smoothed vector? smoothedVector(halfWidth:end-halfWidth) thank you very very much :) |