Hi Sourya,
multiple things:
1. You return 1 in work. That literally tells GNU Radio that you only produced a single
sample! I think we explain what work does in our tutorials on
https://tutorials.gnuradio.org , so you might want to go back and read them a bit more
carefully!
2. you assume you have self.duration * self.sample_rate in space in the output buffer.
That is wrong. You get as much space in the output buffer as you get; you need to check
len(output_items[0]) !
3. you assume the phase at the beginning of your work function is always 0; that is
probably a result of the previous mistake. That's not the case! You need to save your last
sample's phase for the next time "work" is called
4. You assign the output "output_items[0] = s", but that's wrong (and not like our
examples at all): you need to do output_items[0][:] = s, because you need to replace the
values, not just the reference to the vector. You need to solve 1.–3. first though!
Best regards,
Marcus
On 09.03.24 16:14, Sourya Saha wrote:
> Hi.
> I am trying to create a custom wave through an OOT module. To do that, I
> tried replicating the sine wave of the signal source block. I have used the
> following Python code:
>
> import numpy as np
>
> from gnuradio import gr
>
> class sine(gr.sync_block):
>
> """
>
> docstring for block sine
>
> """
>
> def __init__(self, sample_rate, duration=1000, freq=0):
>
> gr.sync_block.__init__(self,
>
> name="sine",
>
> in_sig=None,
>
> out_sig=[np.float32, ])
>
> self.sample_rate = sample_rate
>
> self.duration = duration
>
> self.freq = 0
>
>
> def work(self, input_items, output_items):
>
> #out = output_items[0]
>
>
>
> t = np.arange(0, self.duration, 1/self.sample_rate)
>
>
>
> s = np.sin(2*np.pi*self.freq*t)
>
>
>
> # <+signal processing here+>
>
> output_items[0] = s
> return 1 #len(output_items[0])
>
>
>
>
> However, I do not get any output from the output line. Could you suggest
> what could have gone wrong?
>
No comments:
Post a Comment