An optical dynamic spectral encoding code division multiple access (CDMA) communication system is proposed. In this system, an electrically controlled tunable optical filter (TOF) is used to encode the modulated broadband light source. The code depends on the function set to the controller. Two-dimensional code, named functional code, is also proposed based on a shifted sine function. The function defines the dynamic coding pattern of the central wavelength of the transmitted narrowband optical signal. Thus, the system will allow for an easy reconfiguration of the transmitter without the need for a sophisticated encoder. At the receiver, a synchronized TOF with the same function is used as a decoder. The system is modeled and analyzed taking into account the multiple access interference, phase-induced intensity noise (PIIN), and thermal noise. The performance of this system is shown to be better compared with a fast frequency hopping (FFH) system and a spectral amplitude coding (SAC) system that uses either a Hadamard code, a modified quadratic congruence (MQC) code, or a modified frequency hopping (MFH) code.