# Comparing Spectral Leakage in Sine and Cosine Functions

I am not from a signal processing background, kindly excuse me for my vocabulary.

When I compute the power spectrum of a periodic function, where the "real" space variables are generated by np.linspace, I can choose whether or not I want to include the last point. Over integer multiples of a cycle, excluding the last point produces samples for a periodic function and including it produces samples for an aperiodic function, giving rise to "spectral leaking" in the Fourier transform of the function (1).

In the plots of the power spectrum for first harmonic cosine and sine functions, one can notice that the cosine function has spectral leakage that confers the zero mode with a non-zero value, while this is not the case with the sine function. Why is this the case?

import numpy as np
import matplotlib.pyplot as plt

theta = np.linspace(0,2*np.pi,100, endpoint=False)
phi = np.linspace(0,2*np.pi,100, endpoint=True)

ct = np.cos(theta)
cp = np.cos(phi)

st = np.sin(theta)
sp = np.sin(phi)

fct = np.fft.fft(ct)
fcp = np.fft.fft(cp)
fst = np.fft.fft(st)
fsp = np.fft.fft(sp)

plt.plot(np.abs(fct), label='endpoint=False')
plt.plot(np.abs(fcp), label='endpoint=True')
plt.title('Cosine Power Spectrum')
plt.grid()
plt.legend()
plt.show()

plt.plot(np.abs(fst), label='endpoint=False')
plt.plot(np.abs(fsp), label='endpoint=True')
plt.title('Sine Power Spectrum')
plt.grid()
plt.legend()
plt.show()


At sample time $$n=100$$ we are duplicating a sample, which generates the leakage.