A novel photonic functional device, a rectangle variable optical filter using dynamic grating in Er doped fiber (EDF) controlled by synthesis of optical coherence function, is proposed and analyzed. Due to the gain saturation of EDF, a periodic bleaching of the gain (dynamic grating) is generated, when an intensity standing wave is produced by interference of two laser beams traveling in EDF with opposite directions. When the frequency of the laser is modulated with an appropriate waveform, shape of the optical coherence function can be synthesized. It can be used to control the interferometric pattern in the EDF, and then the dynamic grating can also be controlled. Thus, the shape and bandwidth of the reflection spectrum of the dynamic grating becomes controllable. Simulations indicate that the spectrum of the filter can be controlled by synthesis of optical coherence function. Preliminary experiment confirmed the principle.