You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: ResidScan.m
    path of file: ./repos/CanlabCore/CanlabCore/HRF_Est_Toolbox2/Old_stuff/More_recent_old_stuff
    
    the code of the file until where you have to start completion: function [p sres sres_ns] = ResidScan(res, FWHM)
% function [p sres sres_ns] = ResidScan(res, FWHM)
%
% Calculates P(M>=t) where M is the max value of the smoothed residuals.
% In this implementation the residuals are smoothed using a Gaussian
% kernel.
% 
% INPUT:
%
% res - residual time course
% FWHM - Full Width Half Maximum (in time units)

    
function [p sres sres_ns] = ResidScan(res, FWHM)
% function [p sres sres_ns] = ResidScan(res, FWHM)
%
% Calculates P(M>=t) where M is the max value of the smoothed residuals.
% In this implementation the residuals are smoothed using a Gaussian
% kernel.
% 
% INPUT:
%
% res - residual time course
% FWHM - Full Width Half Maximum (in time units)
%
% OUTPUT:
%
% p - pvalues
% sres - smoothed residuals
% sres_ns - smoothed residuals (non standardized) 
%
% By Martin Lindquist & Ji-Meng Loh, July 2007
%
% Edited by ML on 10/02/09

res_ns = res;
res = res./std(res);
len = length(res);

% Create Gaussian Kernel
sig = ceil(FWHM/(2*sqrt(2*log(2))));    
klen = 3*sig;
kern = normpdf((-klen:klen),0,sig); 
kern = kern./sqrt(sum(kern.^2));

% Convolve
x = conv(res,kern);
sres = x((klen + 1):(end