A cross-correlation technique is adopted and applied to the real-time signal filtering of a one-dimensional (1D) grating position-encoded signal scanned by a micro- or nano-probe. The position-encoded signal is used for both real-time displacement measurement and grating pitch measurement. The filtering technique applied is based on the 1D grating position-encoded signal which is passed over by a half period of sinusoidal waveform sequence as the template and is cross-correlated with it. Mathematical analysis and simulation experiment are performed not only to optimize the parameters of the template but also to prove the accuracy and credibility of real-time filtering when the template period is approximately equal to that of the 1D grating position-encoded signal. As an application, the motion displacements of a piezoelectric scanning stage are measured when it is controlled to move by a computer through its built-in capacitance sensor in open- and closed-loop modes respectively at different moving speeds.