function zz=RS_WinMean1D(in_signal,N,r,s); %***************************************************************** %* * %* THIS IS THE MATLAB IMPLEMENTATION OF THE (r,s)-WINSORIZED * %* TRIMMED MEAN FILTER FOR 1 DIMANSIONAL SIGNALS. * %* * %*===============================================================* %* * %* SINTAX: RS_WinMean1D(in_signal,N,r,s); * %* * %* -'in_signal' - is the input signal to be filtered; It * %* should be a row vector; * %* -'N' - is the length of the filter. It should * %* be an odd number; * %* -'r' - is the number of coefficients that are * %* replaced from left side of the ordered * %* input vector (r<=(N-1)/2); * %* -'s' - is the number of coefficients that are * %* replaced from right side of the ordered* %* input vector (s<=(N-1)/2); * %* * %*---------------------------------------------------------------* %* * %* AUTHOR: Radu Ciprian Bilcu * %* bilcu@cs.tut.fi * %* Tampere University of Technology * %* Signal Processing Laboratory * %* * %***************************************************************** iter=length(in_signal);%COMPUTE THE LENGTH OF THE INPUT SIGNAL for i=(N+1)/2:(iter-(N-1)/2)%START FILTERING THE SIGNAL xin=in_signal((i-(N-1)/2):(i+(N-1)/2));%STORE THE N SAMPLES FROM THE SIGNAL IN THE VECTOR xin xsort=sort(xin);%SORT THE INPUT SAMPLES xsort(1:r+1)=xsort(r+1).*ones(1,r+1);%REPLACE THE FIRST r SAMPLES %FROM THE BEGINNING OF THE INPUT VECTOR xsort(N-s:N)=xsort(N-s).*ones(1,s+1);%REPLACE THE LAST s SAMPLES %FROM THE END OF THE INPUT VECTOR out(i)=mean(xsort);%AVERAGE THE SAMPLES FROM THE INPUT VECTOR end figure%PLOT THE INPUT SIGNAL plot(in_signal); title('The input signal'); grid; figure%PLOT THE FILTERED SIGNAL plot(out); title('The filtered signal'); grid;