# defining parameters for the signal
A1 = 5 # Amplitude of the first cosine wave
f1 = 2000 # Frequency of the first cosine wave in Hz
A2 = 2 # Amplitude of the second cosine wave
f2 = 1000 # Frequency of the second cosine wave in Hz
fs = 8000 # Sampling frequency in Hz
N = 128 # Number of samples, chosen as 2^7 for convenient FFT computation
# Generating the discrete time signal x by summing two cosine waves
x = A1*cos(2*pi*f1*t) + A2*cos(2*pi*f2*t)
I am getting the fft of the signal and plotting it, why does it only work perfectly when Fs = 8kHz, anything less or more distorts it a little even if it meets nyquist
Here is the plot with 8kHz sampling frequency
Here it is with 9kHz

