Assuming the convolution in the time domain produces a signal which spectrum is the product of individual spectrums, when the two convoluted signals are sinusoids with different frequencies, the DFT coefficients should be null. I'm trying to verify this property, but my spectrum (last column) is not null.
Assuming the code is correct, how to interpret the result?
import numpy as np
import scipy.fft as sf
import matplotlib.pyplot as plt
Sampling
Fs = 200
T = 0.5
t = np.arange(0, T, 1/Fs)
N = len(t)
Frequencies, Hz
f1 = 10
f2 = 50
Functions
w = lambda f: 2 * np.pi * f
dft = lambda s: sf.fftshift(sf.fft(s))
Time domain
x1 = 1 * np.cos(w(f1) * t)
x2 = 0.1 * np.cos(w(f2) * t)
ya = x1 + x2
yc = np.convolve(x1, x2, mode='same')
Frequency domain
ff = sf.fftshift(sf.fftfreq(N, 1/Fs))
X1, X2, Ya, Yc = [dft(s) for s in (x1, x2, ya, yc)]
Figure
mosaic = np.asarray([[f't{i}' for i in range(4)], [f'f{i}' for i in range(4)]])
nrows = len(mosaic)
ncols = len(mosaic[0])
fig_kw = dict(figsize=(ncols2.6, nrows1.5), layout='constrained')
fig, axs = plt.subplot_mosaic(mosaic=mosaic, **fig_kw)
for ax, title in zip(mosaic[0], ('x1(t)', 'x2(t)', 'Sum', 'Convolution')):
axis = axs[ax]
axis.set_title(title)
axis.set_xlabel('time (s)')
for ax in mosaic[1]: axs[ax].set_xlabel('Hz')
fig.text(0.5, 1.04, ha='center', size='large', weight='bold', s='Sum vs. convolution')
for ax, x in zip(mosaic[0], (x1, x2, ya, yc)): axs[ax].plot(t, x)
for ax, X in zip(mosaic[1], (X1, X2, Ya, Yc)): axs[ax].stem(ff, abs(X))

