discuss-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Generating a chirp pulse, non-even transfers


From: U L
Subject: Re: Generating a chirp pulse, non-even transfers
Date: Wed, 4 Oct 2023 07:52:26 -0600

Hey Tom,
You can count individual samples by looking at the length of the output_items arrays in the work function. Currently it looks like you're only counting the number of work calls. Gr blocks operate on groups of samples for efficiency and the number of samples per call can vary. So you'd have to check the length of the stats every call.

Alternatively you could prob use the existing vector source and a multiply block to get the effect you're looking for. The vector source repeats an array of samples. Your array could be ONpulsecount 1s followed by OFFpulsecount 0s. Since the vector source is compiled it would also be much faster than the Python block.

Jared.


On Mon, Oct 2, 2023, 12:47 PM tom sutherland <alphatozeta@yahoo.com> wrote:
I want to generate a chirp signal. My idea was to have a sawtooth signal feed a VCO. The generated chirp repeats, so I was going to blank off the signal after the first chirp. I wanted to count the number of samples in the chirp with a python block and output the VCO chirp only when the blanking pulse was high. It sort of works but the python code doesn't count the regularly. It seems to count in random length blocks, so I get some "chirps output" that have 20 chirps and some have 50, not the one chirp I want. I have attached my code.  Thanks...Tom

My Python Block's Code:
"""
Embedded Python Blocks:

Each time this file is saved, GRC will instantiate the first class it finds
to get ports and parameters of your block. The arguments to __init__  will
be the parameters. All of them are required to have default values!
"""

import numpy as np
from gnuradio import gr


class blk(gr.sync_block):  # other base classes are basic_block, decim_block, interp_block
    """Embedded Python Block example - a simple multiply const"""

    def __init__(self, ONpulsecount=1000,OFFpulsecount=10000,threshold = 0.5):  # only default arguments here
        """arguments to this function show up as parameters in GRC"""
        gr.sync_block.__init__(
            self,
            name='pulseshaper',   # will show up in GRC
            in_sig=[np.complex64,np.float32],
            out_sig=[np.complex64,np.float32]
        )
        # if an attribute with the same name as a parameter is found,
        # a callback is registered (properties work, too).
        self.ONpulsecount = ONpulsecount
        self.OFFpulsecount = OFFpulsecount
        self.threshold = threshold
        self.count=0
        self.pulseblanker = 1.0

    def work(self, input_items, output_items):
        """example: multiply with constant"""
   
        self.count = self.count + 1

        if self.count < self.ONpulsecount:
            self.pulseblanker = 1.0
        elif self.count < self.OFFpulsecount:
            self.pulseblanker = 0.0
        else:
            self.count = 0    

        output_items[0][:] = input_items[0][:] * self.pulseblanker
        output_items[1][:] = self.pulseblanker
       
        return len(output_items[0])


Inline image



JPEG image

JPEG image


reply via email to

[Prev in Thread] Current Thread [Next in Thread]