Hi Sourya,
ha! nice one, this will require you to take a piece of graph paper and make a drawing:
horizontal axis: t, make it run from 0 to 1 ms over say 10cm
vertical axis: sin(2\pi ft), so from -1 to +1
you know the sine is 0 for t=0, and it's again after one period, and there's another 0 in
the middle. So, since in 1 ms, there's 10 periods of a 10 kHz sine, distribute your 20
zero-crossing evenly between t=0 and t=1ms on the horizontal axis (make a green dot there).
Then, make another green dot at vertical +1 in the middle between t=0 and the first
zero-crossing after. That's the position of the first maximum of the sine.
Then make a green dot at -1 in the middle between the first and second zero crossing after
t=0. That's the position of the first minimum of the sine.
Hope you're still with me, we're just making a drawing of the 10 kHz sine!
So, it's alternating dots at +1 and -1 in the (horizontal) middle between the zero-crossings.
In the end, connect them with a somewhat smooth curve. Precision really doesn't matter,
the only thing important is that you can look at it and go "ok, that's periods of a sine
wave!".
Now, take a different color. Red, or so. Make a fat circle around the value the sine wave
has at t=0 (that should be sin(0) = 0, right).
These red circles are our samples. Your sampling rate is 2 kHz, so the next circle appears
at 1/(2 kHz) = 0.5 ms, and the next another 0.5 ms later.
Where did you put all your circles?
That's what *Nyquist rate* is all about. You can only properly reconstruct sine waves
where you get more than 2 points per period, meaning that your sample rate needs to
fulfill a condition relative to the signal frequency.
Hope this helps!
Marcus
On 11.03.24 19:02, Sourya Saha wrote:
> Hi marcus,
> I corrected my typo and did everything as you said. I still do not have any
> output.
> Following is my 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, phase=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 = freq
> self.phase = 0
>
>
> def work(self, input_items, output_items):
> #out = output_items[0]
>
> t = np.arange(0, len(output_items[0]),
> len(output_items[0])/self.sample_rate)
>
> s = np.sin(2*np.pi*self.freq*t + self.phase)
> self.phase += 2 * np.pi * self.freq / self.sample_rate
>
> # <+signal processing here+>
> output_items[0][:] = s
> return len(output_items[0])
>
> Attached is a screenshot of the flowgraph.
> How do i get a sine wave just like the signal source?
>
> Regards,
> Sourya Saha
>
No comments:
Post a Comment