Skip to content. | Skip to navigation

Personal tools
Log in
Sections
You are here: Home Resources Behavior Matlab functions smooth2_function

smooth2_function

The function performs 2-D smoothing of a matrix using Hanning window of user-specified size: window_x=columns; window_y=rows

smooth2_function.m — Objective-C source code, 1 kB (1186 bytes)

File contents

%smooth2_function

% Written by Primoz Ravbar Sep 2011; 

% The function performs 2-D smoothing of a matrix using Hanning window of
% user-specified size: window_x=columns; window_y=rows; if window_x or window_y equlas 1
% no smoothing will be performed;
% inputs: matrix of data to be smothened -- 's_tot'; 
% size of Hanning window for x axis -- 'window_x'
% size of Hanning window for y axis -- 'window_y'

% output: smoothened matrix

function [smooth_matrix]=smooth2_function(s_tot, window_x, window_y); 


clear slice_smooth_x
clear slice_smooth_y

window_hanning_x=window_y;
window_hanning_y=window_x;

a=size(s_tot);

smooth_y=1;
smooth_x=1;

if smooth_y==1;

index=1;

for s=1:a(1);
    smoothed_y=conv(s_tot(s,:),hanning(window_hanning_y));
    slice_smooth_y(index,:)=smoothed_y(window_hanning_y/2:end-window_hanning_y/2);
    index=index+1;
    index
end

end

if smooth_x==1;

index=1;

for s=1:a(2);
    smoothed_x=conv(slice_smooth_y(:,s),hanning(window_hanning_x));
    slice_smooth_x(:,index)=smoothed_x(window_hanning_x/2:end-window_hanning_x/2);
    index=index+1;
    index
end

end

smooth_matrix=slice_smooth_x;