I saw similar questions partially solved but in matlab ref1, ref2, but I'm working with python. I am new processing signals and I am trying to remove harmonics from the following signals.
These are radio observations (at 3 and 7 THz). So first, I'd like to obtain the frequency of the predominant oscilation (visually, the period is about 1.78 s, so f=1/T), the four following enhancements are only tests and are not oscilations. Data resolution is 0.25 s (i.e. 4 points per second). I was trying to use
np.fft.fft
to find the predominant frequency but I can't figure out the way. So I was checking for 'Filtering' in scipy.signal but there are many filters.
- Which filter would be more appropriate for this case and how can I used?
- Is it necessary find the predominant frequency to eliminate it?
- Is it necessary decompose the signal to extract the harmonics?
I'll keep checking the documentation but it would be helpful some lights!
Here my try
from scipy import fftpack
d_step = 0.250
#Sampling para 3 THz
sample_freq_3T = fftpack.fftfreq(prosolar3.temp.size, d=d_step)
sig_fft_3T = fftpack.fft(prosolar3.temp)
#Sampling para 7 THz
sample_freq_7T = fftpack.fftfreq(prosolar7.temp.size, d=d_step)
sig_fft_7T = fftpack.fft(prosolar7.temp)
pidxs_3T = np.where(sample_freq_3T > 0)
freqs_3T = sample_freq_3T[pidxs_3T]
power_3T = np.abs(sig_fft_3T)[pidxs_3T]
pidxs_7T = np.where(sample_freq_7T > 0)
freqs_7T = sample_freq_7T[pidxs_7T]
power_7T = np.abs(sig_fft_7T)[pidxs_7T]
I'm trying to block the harmonics in the signal centered at 0.34 Hz (3 THz signal) and 0.64 Hz (7 THz signal)
I tried doing a passband, in order to substract from the original signal, but actually it does work
sig_fft_3T[np.abs(sample_freq_3T) < 0.24] = 0
sig_fft_3T[np.abs(sample_freq_3T) > 0.40] = 0
sig_fft_7T[np.abs(sample_freq_7T) < 0.57] = 0
sig_fft_7T[np.abs(sample_freq_7T) > 0.71] = 0
main_sig_3T = fftpack.ifft(sig_fft_3T)
main_sig_7T = fftpack.ifft(sig_fft_7T)
So, when ploting main_sig vs time and compare with the original signal, I get
So, which filter can I use? Remembering that I want to remove the harmonics at 0.34 and 0.64 Hz from signal.
Is the better option to use a FFT? Are there another options?
Here the data