Recently I found my old code to transform sine wave from time domain to frequency domain. Below I post simplified version of it.
from math import sin, pi from matplotlib.pyplot import * from pylab import zeros, fft fs = 500 duration = 2 * pi amplitude = 2 frequency = 25 values_in_time_domain =  for t in range(int(duration * fs)): values_in_time_domain.append(amplitude * sin(frequency * t / fs)) subplot(2, 1, 1) title('Sinus from 0 to 2 pi in time domain; A = 2, f = 25, fs = 500') plot(values_in_time_domain) transform = fft(values_in_time_domain) transform_abs = [abs(x) for x in transform] values_in_freq_domain = [transform_abs[f] / fs / pi for f in range(int(fs / 2)+1)] subplot(2, 1, 2) title('Above sinus in frequency domain') plot(values_in_freq_domain) show()
Why do I have to divide every element from
pi in the following:
transform_abs[f] / fs / pi?
I noticed I need to do it in order to have properly scaled $O_y$ axis.