I want to make a bandpass filter for an IQ signal recorded from an Software Defined Radio with center frequency "Fc" & sampling frequency "Fs". For futhur analysis I wanted to focus upon signal received between a fixed frequency range & filter out rest frequencies.
I generated "sinc" funtion using Python Scipy firwin then I convoluted it with my signal using Python fftconvolve. But as you see in the plots amplitude of the frequency bins outside the pass band of my are still not attenuated.
Approach
- Read the data,convert it from uint8 & strore it as complex notation.
- Generate a "sinc" function of width half of difference of cutoff frequencies eg. for 20MHz to 40MHz width of filter will be 10MHz. Since "sinc" is symmetric it will filter frequencies from -10MHz to +10MHz.
- Move the centre of filter to mean of cutoff frequencies using frequency shift property.
- Convolve the filter with the data.
Relevant Code
data_raw=signal.flatten()
data_raw=data_raw-127.5
data = np.empty(data_raw.shape[0]//2, dtype=np.complex128)
data.real = data_raw[::2]
data.imag = data_raw[1::2]
nyq = 0.5 * fs
# Normalized frequency to be used for frequency shift
centre=(highcut+lowcut)/2-fc
width=np.ceil((highcut-lowcut)/2)
h = firwin(513,width,nyq=nyq,window='hanning')
h = np.append(h,np.zeros(1024-len(h)))
t=np.arange(len(h))
h=h*(np.exp(1j*2*np.pi*t*(centre/fs)))
filtered_data = fftconvolve(data, h)
Details:
- Fcentre = 137.65 MHz
- Fsample = 2 MHz
- Lowcut = 137.65 MHz
- Hightcut = 138.15 MHz
Plots: