0
$\begingroup$

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

  1. Read the data,convert it from uint8 & strore it as complex notation.
  2. 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.
  3. Move the centre of filter to mean of cutoff frequencies using frequency shift property.
  4. 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:

Firwin filter linear plot

Firwin filter semilog plot

Output after applying filter

$\endgroup$
  • $\begingroup$ Could you clarify how the output differs from your expectation? It looks filtered to me. $\endgroup$ – hops Jun 5 '17 at 21:51
  • $\begingroup$ I deleted my answer since it is obviously not what you are looking for. I need more information. Where did this signal come from? What are you trying to do? You mentioned in a comment that you want to filter out the band between 137.65 MHz & 138.15 MHz, but this would leave only noise. Is this your desire? The more you can tell me, the more we can turn this into a real question and obtain a real answer. $\endgroup$ – hops Jun 6 '17 at 18:18
  • $\begingroup$ Are you attempting to isolate the signal between those frequencies? Are you asking how to design a filter that does this? For clarification, when I say "filter out" a signal, that means to reduce its amplitude to a negligible level. I suspect you don't want to filter out the signal between 137.65 MHz and 138.15 MHz but rather you want to filter everything else out. Am I incorrect in this assumption? $\endgroup$ – hops Jun 6 '17 at 18:22
  • $\begingroup$ @hops Your last comment is perfectly correct. I want to focus upon signals received which corresponds to particular frequency range. Hence I thought to apply a bandpass filter so as to filter out the rest of frequencies. Above 137.5MHz & 138.15 Mhz is my passband hence I was expecting my filter will attenuate the rest of frequency bins similar to what digital filters does. $\endgroup$ – Andre Smith Jun 7 '17 at 4:04
  • $\begingroup$ @hops I designed the filter as shown above, theoretically I think it should be working but it isn't I guess as frequency bins out of the passband of filter is not close to zero. I have updated the question to give more details. $\endgroup$ – Andre Smith Jun 7 '17 at 4:07
1
$\begingroup$

You seem to be aware of the Fourier Transform pair that relates a sinc function in the time domain to a rectangle function in the frequency domain, but you don't seem to be able to correctly apply this to your situation. I am going to take one more stab at answering you. Let me know if you have questions.

A sinc filter can be designed using the relationship \begin{equation} \DeclareMathOperator{sin}{sin} \DeclareMathOperator{sinc}{sinc} \DeclareMathOperator{rect}{rect} 2 B \sinc\left(2 B t\right) \iff \rect\left(\frac{f}{2 B}\right) \end{equation} where $\sinc(x) = \frac{\sin(\pi x)}{\pi x}$. This shows us that the desired low pass bandwidth $B$ must be used in our expression to generate the sinc samples. Note that a modulated sinc has a bandwidth equal to $2B$ whereas a sinc centered at DC has a bandwidth of $B$.

In your example, you define several quantities. I am going to give these quantities symbols so I can do some math on them.

Fcentre = 137.65 MHz

I'll call this $f_c$.

Fsample = 2 MHz

I'll call this $f_s$.

Lowcut = 137.65 MHz

I'll call this $f_l$.

Hightcut = 138.15 MHz

I'll call this $f_h$.

For you to generate the sinc with the correct bandwidth, you would sample the sinc function above with \begin{equation} B = \frac{f_h - f_l}{2}. \end{equation}

This means that your bandpass filter is given as \begin{equation} h[n] = \left(f_h - f_l\right) \sinc\left(\frac{f_h - f_l}{f_s} n\right) \exp\left(j \pi \frac{f_h + f_l - 2 f_c}{f_s} n \right) \end{equation} where I have ignored the required time shift to make the filter causal (implementable). The amount you shift it by will be determined by the length of the filter. The length of the filter will be determined by how much stopband attenuation you want.

Note that no finite length filter will yield zero gain in the stopband and all filters have a transition band (a band where the amplitude gradually goes from the desired passband value to the designed stopband value). You can't avoid this.

As a side note, you could have just as easily used the Remez Exchange algorithm (a.k.a. Parks-McClellan) to obtain an optimal filter. The window method is computationally simple, but it is in no sense optimal.

$\endgroup$
  • $\begingroup$ I have updated the question and plots. Plz have a look $\endgroup$ – Andre Smith Jun 5 '17 at 17:41
  • $\begingroup$ Perhaps it would help if you clarified the purpose of the filter? What are you trying to filter out? Your plots look exactly as I would expect. If I were you, I would use a narrower filter than that which you are currently using, but maybe I'm misunderstanding your intention. $\endgroup$ – hops Jun 5 '17 at 18:29
  • $\begingroup$ I want to filter out band between 137.65 MHz & 138.15 MHz. For that band it's totally fine but I am worried about at other frequencies amplitude though negative but not close to zero. Is it something I should worry about since you say my filter works perfectly fine ? $\endgroup$ – Andre Smith Jun 6 '17 at 5:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.