In order to understand filtering, you must understand the theory behind capacitors. They are actually very simple devices. Two metal plates are spaced very close together, separated by an insulator about as thick as a sheet of paper. Wires are attached to the plates. Electricity is fed to the plates, and an electrical charge is built up and stored in between the plates. Eventually, the charge is built up to a saturation level, and the capacitor discharges.
A clean signal should have a steady voltage. Noise is peaks and valleys in the voltage. For example, a clean signal is a steady 10 volts. A noisy signal peaks to 12 volts, and drops, or valleys, down to eight volts. A capacitor is wired into the circuit; in the process of charging and discharging, a filtering action takes place. A capacitor absorbs the peaks, and discharges on the valleys. The end result is the wavy electrical signal is smoothed out, so a flat signal comes out of the capacitor.
Filtering capacitors (also called by-pass capacitors) should be wired in at the power source. DC voltage has a positive, called "Vcc," and a negative, or ground. One terminal of a bypass capacitor should be wired to Vcc, and the other terminal to the ground. This configuration will absorb errant AC noise signals, and allow only clean DC electricity to flow. The exact size of the capacitor has to be calculated out, depending on the voltage you are using. An electronics technician can help you with the sizing of the capacitor.
To reduce line noise in small hobby motors, Michael Simpson of Kronos Robotics and Electronics, recommends wiring capacitors directly across motor terminals. A small electric motor has two terminals. Solder in a capacitor across the leads, and this will absorb noise. Conversely, leads of two capacitors can be attached to the motor case, and the other two leads soldered to the terminals. Another acceptable method is to combine the two methods, so three capacitors are used.