0
$\begingroup$

I am trying to implement a custom signal source for FMCW in GNU Radio, but I am stuck. The idea is to generate a CW chirp signal using the formula

$ \text{chirp} = \exp\left(1j \cdot 2 \pi \left(f_0 \cdot \text{time_axis} + \frac{\alpha \cdot \text{time_axis}^2}{2}\right)\right) $

I have written the .py file and the .yaml file the init.py file I had to make some changes because I was getting error while importing the .py file. Below is the .py file

import numpy as np
from gnuradio import gr
from scipy import signal

class SignalSourceFMCW(gr.sync_block):

    def _init_(self, Bandwidth = 30000000, SampleRate = 45000000, PulseDuration = 0.00014):
        gr.sync_block._init_(self,
            name="SignalSourceFMCW",
            in_sig=None,
            out_sig=[np.complex64])
    
        self.SampleRate = SampleRate
        self.PulseDuration = PulseDuration
        self.Bandwidth = Bandwidth



    def work(self, input_items, output_items):
        num_samps = int(self.SampleRate * self.PulseDuration)
        if not num_samps % 1024:
            num_samps = 1024 * (num_samps // 1024)
        if num_samps == 0:
            num_samps = 1024

        time_axis = np.linspace(0, self.PulseDuration, num_samps)
        f0 = -self.Bandwidth / 2
        f1 = +self.Bandwidth / 2
        c = 3e8  # Speed of light
        alpha = self.Bandwidth / self.PulseDuration

        chirp = np.exp(1j * 2 * np.pi * (f0 * time_axis + (alpha * time_axis ** 2) / 2))

        tukey_window = signal.windows.tukey(len(chirp), alpha=0.05)

        output_items[0][:] = tukey_window * chirp

        return len(output_items[0])

Below is the init.py file

 #
 # Copyright 2008,2009 Free Software Foundation, Inc.
 #
 # SPDX-License-Identifier: GPL-3.0-or-later
 #

 # The presence of this file turns this directory into a Python package

'''
This is the GNU Radio RADAR module. Place your Python package
description here (python/_init_.py).
 '''
import os

 # import pybind11 generated symbols into the radar namespace
try:
    # this might fail if the module is python-only
    from .radar_python import *
except ModuleNotFoundError:
    pass

# import any pure python here
#from .SignalSourceFMCW import SignalSourceFMCW   ##This part was changed to solve the import issue


import sys
sys.path.append('/home/deadshot/gr-radar/python/radar')
from SignalSourceFMCW import SignalSourceFMCW

#

I get the result displayed in the below image enter image description here

enter image description here

Which does not look like a chrip. The parameters seen in the image are the ones used by me. Can anyone help me to figure out what is wrong?

$\endgroup$

1 Answer 1

1
$\begingroup$

Don't reinvent the wheel – just use a "Signal Source" configured to emit a sawtooth wave, use a "Multiply" block to multiply it with itself and thus square it, and use that as input the a phase modulator with the sensitivity you want. Done – linear frequency chirp.

Other than that, the fact that you're doing bad things like trying to include your source code to your python path indicates you're not installing this OOT module correctly (and at the point you're doing that it can't work); can't help you with that, you need to set the right CMAKE_INSTALL_PREFIX with cmake, and do the installation.

Regarding your custom block (aside from it being unnecessary):

You're doing the old rookie mistake of assuming work is always supplied with the same amount of output space, and you can just produce your output in one go. That's not the case; you need to remember where you were at the last sample of the last call to work, and need to continue from there, and you need to produce (at most) as many items as you have space in your output. You're just producing a lot of items and then act as if that's exactly the amount of space you have in the output. And then you return len(output_items[0]), which means you produced exactly the space in the output buffer, instead of returning the actual amount of items you've produced.

These things are all covered on https://tutorials.gnuradio.org, so maybe the most productive approach here is to actually go through these again.

$\endgroup$
6
  • $\begingroup$ I tried to use the VCO block to generate a sweep but that was not giving me the desired FFT, maybe I was doing something wrong but then there is no accurate information on how to determine the sensitivity of the VCO block, what should be the parameters that I should set in the signal source block. $\endgroup$
    – Raj Patil
    Apr 4 at 5:02
  • $\begingroup$ What is the "desired FFT" of a chirp? How do you know you're not dealing with the FFT of a chirp, from the complex values you get? That's a surprisingly hard to answer question. As said, squaring a ramp and using it as phase works; I've done it many times, and so did students I supervised. So, yes, maybe you did something wrong, I can't know that. Make sure that you're scaling the phase input accordingly for the phase modulator. For example, in your code, the alpha makes no sense, it's far too large – you need to normalize things to your sampling rate. $\endgroup$ Apr 4 at 10:05
  • $\begingroup$ I tried using the blocks in the way you suggested but using those blocks how do I get the desired base band frequency that is my main query, cause ultimately the generated samples will be fed to a SDR which will mix the LO with the samples. $\endgroup$
    – Raj Patil
    Apr 4 at 15:29
  • $\begingroup$ Can't know what the "desired base band frequency is", but the phase and frequency modulator blocks have extensive documentation that define their sensitivity. $\endgroup$ Apr 4 at 15:31
  • $\begingroup$ The baseband frequency will be defined by the bandwidth that I will finalize, as defined in the code for the baseband chirp generation f0 = -bandwidth/2 and f1 = +bandwidth/2 $\endgroup$
    – Raj Patil
    Apr 4 at 15:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .