function [m, s] = trim5(x, w);
%v2 - ispravljen problem kad je k2=0, tada postaje 1
if nargin<2
	w = ones(size(x));
end
if size(x,1)==1
	x=x';
	w=w';
end
[v,f]=freq(x,w);
k = size(v,1);
if v(k)==NaN
	v(k)=[];
	f(k)=[];
	k=k-1;
end
if k<2
	m = v(1);
	s = 0;
else
	W = msum(f);
	tc = 0.05 * W;
	cf = ccum(f);
	
	indx = find(tc<=cf);
	k1 = size(indx,1);
	if k1
		k1 = indx(1)-1;
	end

	indx = find(tc<=(W-cf));
	k2 = size(indx,1);
	if k2
		k2 = indx(k2)+1;
	else
		k2 = 1;
	end

	if k1+1==k2
		m = v(k2);
		s = 0;
	else
		k1=k1+1;
		m = (cf(k1)-tc)*v(k1) + (W - cf(k2-1)-tc)*v(k2);
		if k1+1<=k2-1 
			m = m + msum(v(k1+1:k2-1).*f(k1+1:k2-1));
		end
		m = m / (0.9 * W);
		
		s = (cf(k1)-tc)*v(k1)^2 + (W - cf(k2-1)-tc)*v(k2)^2;
		if k1+1<=k2-1 
			s = s + msum(v(k1+1:k2-1).^2.*f(k1+1:k2-1));
		end
		s = sqrt(s / (0.9 * W) - m^2);
	end
end
end
