  We implement an algorithm based on the weighted stacking of astronomical
images that can combine different observations of the same region of the sky
removing the interfering signals. We develop a C++ code that takes as input a
set of spectral cubes and computes the local weights of the intensity for each
pixel of every channel. The weights are calculated as the inverse variance of
the nearby pixels and are used to compute the weighted merge of the input
files. Astronomical sources, present in all cubes, are preserved by the
weighted average. However, interfering signals, present in specific cubes and a
certain frequency range, are down-weighted in the average and removed from the
output spectral cube. We present the results obtained by analyzing simulated
spectral cubes containing astronomical sources, noise, and a random set of
interferences of different intensities and spectral occupations. The
performance of the algorithm is evaluated by comparing the output result with
the input sky model image. Finally, we present the results obtained by applying
the method to a set of real data consisting of observations of the Andromeda
galaxy, Messier 31 (M31), at 6.6 GHz obtained with the Sardinia Radio
Telescope.
