import numpy as np
import matplotlib.pyplot as plt
Def. Dot product on two arrays $y1[x]$ and $y2[x]$ is defined as
$y1[0]*y2[0] + y1[1]*y2[1] + y1[2]*y2[2] + ... + y1[N-1]*y2[N-1]$
in other words, it's the sum of element-wise products between two parallel arrays
$y1.y2 = \sum_{x = 0}^{N-1} y1[x]*y2[x]$
dotprod = 0
for i in range(len(y1)): # Assuming len(y1) = len(y2)
dotproduct += y1[i]*y2[i]
dotprod = np.sum(y1*y2)
n_samples = 100
t = np.linspace(0, 1, n_samples+1)[0:n_samples]
y1 = np.cos(2*np.pi*3*t + np.pi/4)
y2 = np.sin(2*np.pi*3*t)
prod = y1*y2
r = max(np.max(np.abs(prod)), np.max(np.abs(y1)), np.max(np.abs(y2)))
t = np.arange(t.size)
plt.figure(figsize=(12, 16))
plt.subplot(311)
plt.stem(t[y1 > 0], y1[y1 > 0], 'C1', markerfmt='C1o', use_line_collection=True)
plt.stem(t[y1 <= 0], y1[y1 <= 0], 'C0', markerfmt='C0o', use_line_collection=True)
plt.ylim([-1.1*r, 1.1*r])
plt.title("$y_1(t)$")
plt.subplot(312)
plt.stem(t[y2 > 0], y2[y2 > 0], 'C1', markerfmt='C1o', use_line_collection=True)
plt.stem(t[y2 <= 0], y2[y2 <= 0], 'C0', markerfmt='C0o', use_line_collection=True)
plt.ylim([-1.1*r, 1.1*r])
plt.title("$y_2(t)$")
plt.subplot(313)
if np.sum(prod > 0) > 0:
plt.stem(t[prod > 0], prod[prod > 0], 'C1', markerfmt='C1o', use_line_collection=True)
if np.sum(prod <= 0) > 0:
plt.stem(t[prod <= 0], prod[prod <= 0], 'C0', markerfmt='C0o', use_line_collection=True)
plt.ylim([-1.1*r, 1.1*r])
plt.title("$y_1(t)y_2(t), sum = %.3g$"%np.sum(prod))
Given two arrays $y1$ and $y2$ of length $N$, each of which holds samples of a pure sine or a pure cosine that goes through an integer number of periods > 0, then
Suppose we want to evaluate the integral
$\int_{0}^1 \cos(2 \pi f_1 t) \cos(2 \pi f_2t) dt$
$f_1$ and $f_2$ are both integers $>0$, $f_1 \neq f_2$
Recall:
When $f1 \neq f2$, this whole definite integral evalues to 0
Now examine
$f_1$ is an integer > 0
Corollary: If $y1$ is a sum of pure cosines/sines that each go through an integer number of periods, $y2$ is an individual pure cosine/sine that goes through an integer number of periods, then
If you want to know if a sinusoid at a particular frequency $f$ exists in your array, then check both the pure cosine and the pure sine at that frequency