function zz=RS_TrMean1D(in_signal,N,r,s); %***************************************************************** %* * %* THIS IS THE MATLAB IMPLEMENTATION OF THE (r,s)-TRIMMED MEAN * %* FILTER FOR 1 DIMANSIONAL SIGNALS. * %* * %*===============================================================* %* * %* SINTAX: RS_TrMean1D(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 * %* eliminated from left side of the * %* ordered input vector (r<=(N-1)/2); * %* -'s' - is the number of coefficients that are * %* eliminated 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 out(i)=mean(xsort((r+1):(N-s)));%AVERAGE THE MIDDLE SAMPLES %(ELIMINATE r SAMPLES FROM LEFT SIDE %AND s SAMPLES FROM RIGHT SIDE %OF 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;