0
# 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

enter image description here

Here it is with 9kHz

enter image description here

  • I believe you should add more information to your question. What kind of distortion do you see? How do you quantify it? Did you have any (different) expectations, and if yes what and why? This information will help people to better understand your problem and help you in an appropriate way. – ZaellixA Mar 12 '24 at 18:45
  • I added the plots if that helps – giraffe123 Mar 12 '24 at 18:51
  • Ah… this is the leakage effect you see there… Have you tried looking for other questions about it here on Signal Processing SE? I believe you’ll be able to find something. – ZaellixA Mar 12 '24 at 18:53
  • @ZaellixA i see thank you :) – giraffe123 Mar 12 '24 at 19:15
  • 1
    Welcome to SE.SP! As @ZaellixA suggests, this is because of spectral leakage. I've closed this question as a duplicate of a highly rated one with a good answer and explanation from Dan B. to go through exactly what you're asking about. If this doesn't answer your question, please edit your question with more details about your doubts, ping me, and I can reopen it. – Peter K. Mar 12 '24 at 19:38

0 Answers0