# How the noise in time domain affect the power in frequency domain after FFT?

I am new to signal processing. And I am puzzled when studying FFT. I create time series plus a random noise in Python:

 import numpy as np N=1000 x = np.linspace(-50,50,N) noise = np.random.random(N)*0.1 y = np.sin(2*np.pi*x/10) + noise 

Then perform FFT to the time series and get power spectrum. But I find the spectrum is totally different when I execute my script each time. I know it must be the random noise's effect, which are different in different execution. However, as you can see, the sine function is periodic, so we should see clearly a signal in the power spectrum. The puzzle is, the very strong periodic "signal" is submerged in the noise in frequency domain FOR SOMETIME.

I want to know how the noise in time domain affect the noise&signal in frequency domain.

Many thanks!

• Do you have any plots (of your generated sine wave as well as the combination of the signal + noise)? – dsp_user Dec 28 '17 at 10:04
• The broad answer is that since the FT is linear, the FT of the sum of two signals is the sum of their individual FTs. Thus, what you see is the sum of the sinusoids's FT and the noise's FT. If the noise is dominating the spectrum, then that's because it has much more power than the sinusoid. Either increase the amplitude of the sinusoid or decrease the amplitude of the noise. As for the specific effect of the noise, it all depends on the noise under consideration. Some noise is narrowband, some s broadband, some have (nearly) constant amplitude in the frequency domain, some don't. – AnonSubmitter85 Dec 28 '17 at 19:16
• So, conversely, if the signal and noise (data and its error in my case) are given, how to effectively find out (and optimize the S/N) the periodic signal if any? The errors are statistic/systematic derived in the experiments. – canon Dec 29 '17 at 5:28

## 1 Answer

You have problems in defining the noise and sampling frequency. Your noise is not zero mean and your sampling rate is not well defined. Following simple Python code computes the DFT magnitude of the sine plus noise example. (Note: I'm not a python user so please modify the code as necessary)

# -*- coding: utf-8 -*-

import numpy as np
import matplotlib.pyplot as plt
from scipy.fftpack import fft
import numpy.random as npr

N = 1000                # Set signal sample length

t1 = -5;                # Simulation begins at t1
t2 =  5;                # Simulation  ends  at t2
x = np.linspace(t1,t2,N);# Define the sampling grid as x[n]

Ts = (t2-t1)/N;         # Compute resulting sampling period
Fs = 1/Ts;              # Compute resulting sampling rate

noise = (npr.random(N)-0.5); # Generate ZERO MEAN uniform noise

fsin = 0.2*Fs;            # Sine Wave Frequency in [0:Fs/2]
y = np.sin(2*np.pi*fsin*x) + noise    # Generate SINE + Noise

# Take FFT and display its MAGNITUDE
w = np.linspace(0,2,N)
waves = fft(y,N)
plt.plot(w,abs(waves))


Where the resulting plot is: • I can not get the line "fsin = 0.2*Fs". What is the definition of the sine wave frequency, and why it need to be defined in [0:Fs/2]? Excuse my absence in this field..and, could you recommend some introductions that can tell a layman some basic profiles? – canon Dec 29 '17 at 5:15
• @Canon, please read up on the Nyquist frequency ( en.wikipedia.org/wiki/Nyquist_frequency) and then Fat32's answer should be clear to you. – dsp_user Dec 29 '17 at 8:26
• @canon the discrete time signal $x[n] = \cos( \omega_0 n) = \cos( 2 \pi f_0 n)$ , has a valid range of frequencies in $-\pi < \omega_0 < \pi$ or $-0.5 < f_0 <0.5$. And this condition is automatically satisfied when an analog sine wave, $x_c(t)= \cos(2\pi f_c t)$, is sampled without aliasing; i.e., $f_c$ < F_s/2 . Where $F_s$ is the sampling frequency and $F_s/2$ is the Nyquist frequency. – Fat32 Dec 29 '17 at 11:25