OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

np.fft.rfft outputs confusing result of a frequency-mixed AM wave

  • Thread starter Thread starter Little_Ye233
  • Start date Start date
L

Little_Ye233

Guest
I am new to signal processing and trying to generate an AM wave, followed by a frequency mixer, and want to get its FFT result. I have the code like below:

Code:
import numpy as np
import matplotlib.pyplot as plt

# AM
fc = lambda t: np.sin(2 * np.pi * 10e6 * t)
fm = lambda t: 0.5 * np.sin(2 * np.pi * 3e3 * t)
f = lambda t: (1 + fm(t)) * fc(t)

# Frequency mix
fmix = lambda t: np.sin(2 * np.pi * 10e6 * t) # same to fc
f0 = lambda t: f(t) * fmix(t) + 1.5

N = 1024
FS = 2e4
T = (1.0 / FS) * N

t = np.linspace(0, T, N)
y = f0(t)
Y = np.fft.rfft(y)
Y_amp = abs(Y)
Y_amp_norm = Y_amp / N
freq = np.fft.rfftfreq(N, T / N)
idx = np.argsort(freq)

plt.plot(freq[idx], Y_amp_norm[idx])
plt.show()

I think the output figure should have peaks at frequency 3e3 Hz and 0 Hz respectively. But the actual figure is like below:

enter image description here

The second peak is at about 400 Hz. Even adding a low-pass filter before FFT also outputs the same figure. What's wrong in the whole procedure?
<p>I am new to signal processing and trying to generate an AM wave, followed by a frequency mixer, and want to get its FFT result. I have the code like below:</p>
<pre class="lang-py prettyprint-override"><code>import numpy as np
import matplotlib.pyplot as plt

# AM
fc = lambda t: np.sin(2 * np.pi * 10e6 * t)
fm = lambda t: 0.5 * np.sin(2 * np.pi * 3e3 * t)
f = lambda t: (1 + fm(t)) * fc(t)

# Frequency mix
fmix = lambda t: np.sin(2 * np.pi * 10e6 * t) # same to fc
f0 = lambda t: f(t) * fmix(t) + 1.5

N = 1024
FS = 2e4
T = (1.0 / FS) * N

t = np.linspace(0, T, N)
y = f0(t)
Y = np.fft.rfft(y)
Y_amp = abs(Y)
Y_amp_norm = Y_amp / N
freq = np.fft.rfftfreq(N, T / N)
idx = np.argsort(freq)

plt.plot(freq[idx], Y_amp_norm[idx])
plt.show()
</code></pre>
<p>I think the output figure should have peaks at frequency 3e3 Hz and 0 Hz respectively. But the actual figure is like below:</p>
<p><a href="https://i.sstatic.net/eAqGBAov.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/eAqGBAov.png" alt="enter image description here" /></a></p>
<p>The second peak is at about 400 Hz. Even adding a low-pass filter before FFT also outputs the same figure. What's wrong in the whole procedure?</p>
 

Latest posts

Top