1
$\begingroup$

I have a signal that I have recorded from a AirSpyHF and want to remove a unwanted narrow signal with a notch filter (see figure).

The spike in the image below appears to be a center spike, however it is 5knhz above the center freq (Fc), and follows Fc around if I move Fc. Apparently this is normal behaviour for AirspyHF.

A PSD plot of the signal looks like:

enter image description here

Signal Details:

Fc : 160400000 Hz

Fsamp : 912000 Hz

F_unwanted : 160405343

from scipy.io import wavfile
from scipy import signal
import numpy as np
from matplotlib import pyplot as plt

samples = np.fromfile('../data/test_160400.fc32', dtype=np.complex64)
sample_rate = 912000
center_freq = 160400000

x = samples
fs = 768000.0
f0 = 500.0
Q = 10.0
b, a = signal.iirnotch(f0, Q, fs )

x = signal.lfilter(b, a, x)

# PLOT THE PSD
fft_freqs = np.linspace(sample_rate / -2, sample_rate / 2, 1024) + center_freq
plt.figure(figsize=(45,12))

psd = plt.psd(x, NFFT=1024, Fs=912000, Fc=160400000)
peaks = signal.find_peaks(psd[0], prominence=0.00000000001)
for peak, prominence in zip(peaks[0], peaks[1]["prominences"]):
    peak_freq =  ((peak/1024)*sample_rate) + (center_freq-(sample_rate/2))
    plt.annotate(peak_freq, xy=( peak_freq , 10 * np.log10(prominence)))
plt.show()

The Scipy documentation on this iirnotch is not making sense when I try to come up with values for f0 and Q.

I unable to enter the actual frequency I want to remove 160405343. I note the documentation says *"Frequency to remove from a signal.

If fs is specified, this is in the same units as fs. By default, it is a normalized scalar that must satisfy 0 < w0 < 1, with w0 = 1 corresponding to half of the sampling frequency.

From this are the valid values for f0 (i.e. w0) between 0-912000/2 ?

And if so how do I remove a frequency which is higher than the sampling rate?

In summary what values should be plugged into this filter to remove the unwanted signal?

$\endgroup$
1
  • $\begingroup$ Welcome to SE.SP! :-) $\endgroup$
    – Peter K.
    Commented May 30 at 13:35

1 Answer 1

3
$\begingroup$

I suspect the waveform is already down-converted to be a complex baseband signal, yet the plot has the carrier frequency arbitrarily added.

Instead of doing the following:

fft_freqs = np.linspace(sample_rate / -2, sample_rate / 2, 1024) + center_freq

Consider the frequency axis for the filter as:

fft_freqs = np.linspace(sample_rate / -2, sample_rate / 2, 1024) 

This will result in the normalized frequency range properly extending from $-0.5$ to $+0.5$ cycles/sample.

The function iirnotch is a real filter and thus will notch the same frequency from $f=0$ to $f=+0.5$ as $f=0$ to $f=-0.5$ cycles/sample, with $f=0.5$ cycles per sample corresponding to $w0=1$ for use in the iirnotch function. What you may actually have with the complex baseband signals is the need to notch individual frequencies which may not be complex conjugate symmetric, in which case a filter with complex coefficients is used, which can notch individual tones above or below the center frequency of the signal.

Please see DSP.SE #31028 for further details on implementing IIR notch filters. For an intuitive explanation on notch filters aimed toward those less familiar with signal processing, this YouTube interview may be of interest: https://www.youtube.com/watch?v=Aq_SOvR1Sxs&t=86s .

$\endgroup$
4
  • $\begingroup$ Is the value for f0 twice to the samp rate, OR relative to 160400000? $\endgroup$
    – Al Grant
    Commented May 28 at 4:01
  • $\begingroup$ fft_freqs is never used, so not sure how this helps? And fft_freqs comes after the notchfilter is applied $\endgroup$
    – Al Grant
    Commented May 28 at 7:42
  • $\begingroup$ Use the frequency derived from fft_freqs to determine which frequency the notch should be applied to. Evaluate what your spectrum looks like before applying the notch and from that (and the correct frequency scale) you can apply your notch filter. $\endgroup$ Commented May 28 at 11:50
  • $\begingroup$ Once sampled, the only unique frequency range extends from $-f_s/2$ to $+f_s/2$, every higher frequency range is a periodic repetition of this same band- here $f_s$ is the sampling rate. The notch will be some frequency less than half the sampling rate and that frequency is given by the spectrum with the frequency range as I suggest. $\endgroup$ Commented May 28 at 11:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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