Synthetic aperture (SA) techniques have been frequently used to reduce the volume and complexity of the imaging systems. A useful tool for designing synthetic aperture configurations is the coarray. This is the virtual aperture that produces in one way the same beam pattern as the SA system in emission and reception. In this correspondence, we propose a new algorithm, based on the polynomial decomposition, that allows to obtain any wanted coarray on a linear array using whatever synthetic aperture configuration. With this fast and simple algorithm, the desired coarray is decomposed into a set of sub-apertures, whose length is determined by the requirements and resources of the system. The result is the set of weights that have to be applied on the sub-apertures to get the desired coarray, and consequently, the wanted beam pattern.