In order to understand the behaviour of the butterworth (lowpass) filter I generated a "spectrum" consisting of 1's. I then went to time domain (ifft
), applied the filter and transformed back (fft
). I chose the window (maximum) frequency to be one. So i expected that the windowed spectrum should be equal to the actual spectrum of ones.
Instead I got almost the spectrum, but at some point I got a huge line (I expect it to be spectral leakage?!). Also, the values are slightly moved up... Unfortunately I haven't understood how to solve this problem.
Here a sample source code from which I started:
from scipy import signal
import numpy as np
import matplotlib.pyplot as plt
wavelength = range(10000)
spectrum = [1]*len(wavelength)
filter_order = 3 #2
Wn = 1
inter = np.fft.ifft(spectrum)
b,a = signal.butter(filter_order, Wn, btype='low', analog=False)
inter_w = signal.filtfilt(b, a, inter, method='gust') # filtered
spec_w = np.fft.fft(inter_w) # filtered spectrum
plt.plot(wavelength, spectrum, label='spec')
plt.plot(wavelength, spec_w, label='spec_w')
plt.legend()
plt.show()
And here a small plot. As stated I don't understand, why "spec_w" is (i) bigger than one and (ii) there is a peak that shouldn't be there.
Filter_order 3:
Filter_order 2: