Hm, are you 100% sure that you really received as many samples as you
ordered before?


On Sun, 2019-05-12 at 12:41 +0300, Ivan Zahartchuk wrote:
> Good morning. Thanks for your answers, I fixed the record in the data
> array. But it did not help me. But I noticed that everything works
> for me when I add a cycle
>   while samps:
>                  samps = self.streamer_rx.recv (self.recv_buff,
> self.metadata_rx)
> after
> self.stream_cmd = lib.types.stream_cmd
> (lib.types.stream_mode.stop_cont)
>              self.streamer_rx.issue_stream_cmd (self.stream_cmd).
> I don’t fully understand why this cycle after closing reads and
> besides it very much slows down the work of the program, which for me
> is a critical moment.
> 
> 
> def test_reciev_2(self, freq, bandwich):
>     complex_buffs = np.empty((len([0]), self.samples * len(freq)))
>     buffs = np.empty((len([0]), self.samples * len(freq)))
>     result = np.empty((len([0]), self.samples), dtype=np.complex64)
> 
>     for i, freqq in enumerate(freq):
> 
>         recv_samps = 0
>         # self.usrp.set_rx_rate(bandwich[i])
>         k = uhd.types.TuneRequest(freqq)
>         # k.args(uhd.types.device_addr("mode_n=integer"))
>         self.usrp.set_rx_freq(k)
>         self.stream_cmd =
> uhd.types.StreamCMD(uhd.types.StreamMode.start_cont)
>         self.stream_cmd.stream_now = True
>         self.streamer_rx.issue_stream_cmd(self.stream_cmd)
>         while self.usrp.get_rx_sensor("lo_locked").to_bool() != True:
>             continue
> 
>         samps = np.array([], dtype=np.complex64)
>         while recv_samps < self.samples:
> 
>             samps = self.streamer_rx.recv(self.recv_buff,
> self.metadata_rx)
>             if self.metadata_rx.error_code !=
> lib.types.rx_metadata_error_code.none:
>                 print(self.metadata_rx.strerror())
>             if samps:
>                 real_samps = min(self.samples - recv_samps, samps)
>                 result[:, recv_samps:recv_samps + real_samps] =
> self.recv_buff[:, 0:real_samps]
>                 recv_samps += real_samps
>         # print (self.usrp.get_rx_sensor('rssi'))
>         # print(self.streamer_rx.get_max_num_samps())
> 
>         # self.stream_cmd.time_spec = lib.types.time_spec(0)
>         self.stream_cmd =
> lib.types.stream_cmd(lib.types.stream_mode.stop_cont)
>         self.streamer_rx.issue_stream_cmd(self.stream_cmd)
> 
>         while samps:
>             samps = self.streamer_rx.recv(self.recv_buff,
> self.metadata_rx)
> 
>         #complex_buffs = np.append(complex_buffs, result).ravel()
>         # correct_result=result
>         #correct_result_1 = result - (np.mean(result.real) +
> np.mean(result.imag) * 1j)
>         # correct_result.real=result.real-np.mean(result.real)
>         # correct_result.imag = result.imag - np.mean(result.imag)
> 
>         PSD = self.fft_test(result)
> 
>         # PSD[8188:8202]=np.mean(PSD[8180:8188])
> 
>         buffs[:, i * value.samples:value.samples * i + value.samples]
> = PSD[:, 0:value.samples]
> 
>     return complex_buffs, buffs.ravel()
> 
> вс, 12 мая 2019 г. в 02:35, Marcus Müller <marcus.muel...@ettus.com>:
> > Ah, I see you think that this burst can't be too hard on your
> > computer,
> > because it arrives "at once"? That's not the case.
> > On Sun, 2019-05-12 at 01:18 +0200, Marcus Müller wrote:
> > > Um, sorry, I don't understand your sentence. Of course we have to
> > > care
> > > about these samples. Otherwise, we get an overflow. That is
> > literally
> > > what overflow means: Samples not getting received by the program
> > > using
> > > UHD in time before a buffer overflows.
> > > 
> > > On Sat, 2019-05-11 at 22:29 +0300, Ivan Zahartchuk wrote:
> > > > No, I meant that all system performance is enabled only when we
> > > > make
> > > > a request and not all the time. And we no longer care what we
> > do
> > > > next
> > > > with these samples, they are just an array and the board does
> > not
> > > > require constant reading.
> > > > 
> > > > вс, 12 мая 2019 г. в 01:03, Marcus Müller <
> > marcus.muel...@ettus.com
> > > > >:
> > > > > I'm not quite sure how you come to the conclusion that we
> > > > > wouldn't
> > > > > be
> > > > > tied to system performance in that case: that number of
> > samples
> > > > > still
> > > > > needs to be received by the software running on the computer.
> > > > > 
> > > > > Best regards,
> > > > > Marcus
> > > > > 
> > > > > On Sat, 2019-05-11 at 20:39 +0300, Ivan Zahartchuk wrote:
> > > > > > Thanks for the help. I will try to fix everything tomorrow
> > and
> > > > > see
> > > > > > the result. But tell me, maybe I don’t fully understand how
> > > > > > num_sams_and_done works. If I understand correctly, this
> > method
> > > > > does
> > > > > > not send a continuous stream of data but simply gives a
> > certain
> > > > > > number of samples upon request. And in this case, we are
> > not
> > > > > > tied
> > > > > to
> > > > > > system performance. Maybe I do not understand this. Could
> > you
> > > > > clarify
> > > > > > this?
> > > > > > 
> > > > > > сб, 11 мая 2019 г. в 23:19, Marcus Müller <
> > > > > marcus.muel...@ettus.com>:
> > > > > > > Dear Ivan,
> > > > > > > 
> > > > > > > On Sat, 2019-05-11 at 20:00 +0300, Ivan Zahartchuk wrote:
> > > > > > > > Sorry I did not specify. When working with the
> > start_cont
> > > > > mode
> > > > > > > with a
> > > > > > > > frequency of more than 5 MHz, I have an overflow
> > error. 
> > > > > > > 
> > > > > > > Which probably happens due to the inefficient way you
> > handle
> > > > > the
> > > > > > > data;
> > > > > > > your program simply is too slow.
> > > > > > > 
> > > > > > > > That leads to a chaotic change in the spectrum. I agree
> > > > > > > > about
> > > > > the
> > > > > > > > wrong allocation of memory, but I created my own data
> > array
> > > > > and
> > > > > > > ran
> > > > > > > > it through the whole chain of changes and additions and
> > had
> > > > > what
> > > > > > > I
> > > > > > > > expected at the output. 
> > > > > > > 
> > > > > > > Huh? When using offline data, your computationally load
> > > > > > > doesn't
> > > > > > > matter;
> > > > > > > I'm not sure I'm understanding you correctly here! 
> > > > > > > 
> > > > > > > > Moreover, the data array was much more than what I get
> > from
> > > > > the
> > > > > > > > board. In this regard, I decided that the matter is in
> > the
> > > > > > > reading
> > > > > > > > from the board.
> > > > > > > 
> > > > > > > I'll allow myself to doubt that: Again, the fact that
> > your
> > > > > > > data
> > > > > > > array
> > > > > > > runs through smoothly is no indication for your software
> > > > > > > being
> > > > > fast
> > > > > > > enough to keep up with the torrent of samples UHD will
> > give
> > > > > you!
> > > > > > > When
> > > > > > > it doesn't keep up, you see exactly what you're
> > describing:
> > > > > > > UHD
> > > > > > > reporting overflows due to your software not fetching
> > samples
> > > > > fast
> > > > > > > enough. Overflows aren't UHD bugs, they are problems in
> > the
> > > > > > > way
> > > > > you
> > > > > > > use
> > > > > > > UHD!
> > > > > > > 
> > > > > > > >  I have seen examples, but start_cont mode is used
> > there
> > > > > > > > and
> > > > > > > there
> > > > > > > > are not so many frequency adjustments. Therefore, I
> > decided
> > > > > to
> > > > > > > use
> > > > > > > > the num_sams_and_done mode, but there is also a problem
> > > > > > > > with
> > > > > it
> > > > > > > which
> > > > > > > > is described in the previous message. If you have more
> > > > > > > suggestions, I
> > > > > > > > will be very grateful to you.
> > > > > > > 
> > > > > > > Well, exactly what I wrote in my previous mail: you need
> > to
> > > > > make
> > > > > > > your
> > > > > > > software fast enough. Preallocate the buffer; don't
> > append to
> > > > > its
> > > > > > > end.
> > > > > > > 
> > > > > > > Aside from that, do some profiling. Under linux, `perf
> > top
> > > > > > > -ag
> > > > > > > python
> > > > > > > yourscript.py` is your friend to figure out where your
> > > > > > > program
> > > > > > > spends
> > > > > > > its CPU cycles.
> > > > > > > 
> > > > > > > Best regards,
> > > > > > > Marcus
> > > > > > > 
> > > > > > > > сб, 11 мая 2019 г. в 22:27, Marcus Müller <
> > > > > > > marcus.muel...@ettus.com>:
> > > > > > > > > Dear Ivan,
> > > > > > > > > 
> > > > > > > > > it's not clear what you've modified. I'm not aware of
> > any
> > > > > UHD
> > > > > > > > > function
> > > > > > > > > that restricts any frequency to 5 MHz.
> > > > > > > > > Could you elaborate on which code you're basing this
> > on?
> > > > > > > > > 
> > > > > > > > > Also, while I really like the Python interface, if
> > you're
> > > > > > > really
> > > > > > > > > after
> > > > > > > > > high-rate sampling, it might simply not be the
> > optimal
> > > > > thing to
> > > > > > > > > use:
> > > > > > > > > You'd have to be very careful in Pythonland to not
> > run
> > > > > > > > > into
> > > > > > > > > performance
> > > > > > > > > problems once you've gotten the samples from UHD:
> > > > > > > > > 
> > > > > > > > >       
> > > > >  complex_buffs=np.append(complex_buffs,result).ravel()
> > > > > > > > > A very bad idea. You're constantly re-allocating
> > buffers
> > > > > here.
> > > > > > > > > Don't do
> > > > > > > > > that. No matter in which programming language you'd
> > do
> > > > > this,
> > > > > > > you'd
> > > > > > > > > make
> > > > > > > > > sure that the buffer is large enough for your data
> > > > > collection
> > > > > > > to
> > > > > > > > > begin
> > > > > > > > > with and then tell the UHD library to fill the
> > > > > > > > > appropriate
> > > > > part
> > > > > > > in
> > > > > > > > > that
> > > > > > > > > buffer to avoid a) having to ask for a larger buffer
> > > > > regularly
> > > > > > > and
> > > > > > > > > b)
> > > > > > > > > avoid copying data.
> > > > > > > > > Asking for an appended version of your last buffer
> > means
> > > > > that
> > > > > > > > > something
> > > > > > > > > has to allocate a larger buffer – which comes at very
> > > > > > > > > large
> > > > > > > cost!
> > > > > > > > > Best regards,
> > > > > > > > > Marcus 
> > > > > > > > > 
> > > > > > > > > On Sat, 2019-05-11 at 21:31 +0300, Ivan Zahartchuk
> > via
> > > > > USRP-
> > > > > > > users
> > > > > > > > > wrote:
> > > > > > > > > > Hello. My task is to make a broadband spectrum
> > analyzer
> > > > > on
> > > > > > > the
> > > > > > > > > usrp
> > > > > > > > > > b200 board. For this, the standard functions for
> > > > > > > > > > reading
> > > > > > > samples
> > > > > > > > > in
> > > > > > > > > > python are not suitable for me. Therefore, I edited
> > > > > > > > > > them.
> > > > > > > When
> > > > > > > > > > reading samples using the start_con method, I
> > cannot
> > > > > specify
> > > > > > > a
> > > > > > > > > band
> > > > > > > > > > greater than 5 MHz. Therefore, I use the
> > > > > num_sams_and_done
> > > > > > > > > method.
> > > > > > > > > > But I have problems with him. The fact is that my
> > > > > frequency
> > > > > > > which
> > > > > > > > > I
> > > > > > > > > > know appears in the wrong place. For example, I
> > > > > > > > > > generate
> > > > > a
> > > > > > > > > frequency
> > > > > > > > > > of 910 MHz and it appears at 930 MHz (with a
> > bandwidth
> > > > > > > > > > of
> > > > > 20
> > > > > > > > > MHz). I
> > > > > > > > > > can not understand what caused it. Here are my
> > reading
> > > > > > > functions
> > > > > > > > > in
> > > > > > > > > > two ways. I would be extremely grateful for the
> > help.
> > > > > > > > > > 
> > > > > > > > > > 
> > > > > > > > > > 
> > > > > > > > > > 
> > > > > > > > > > def test_reciev(self,freq,bandwich):
> > > > > > > > > >     complex_buffs=np.array([])
> > > > > > > > > >     buffs = np.array([])
> > > > > > > > > >     result = np.empty((len([0]), self.samples),
> > > > > > > > > dtype=np.complex64)
> > > > > > > > > >     for i, freqq in enumerate(freq):
> > > > > > > > > > 
> > > > > > > > > >         recv_samps = 0
> > > > > > > > > >         #self.usrp.set_rx_rate(bandwich[i])
> > > > > > > > > >         k=uhd.types.TuneRequest(freqq)
> > > > > > > > > >       
> >  #k.args(uhd.types.device_addr("mode_n=integer")
> > > > > > > > > > )
> > > > > > > > > >         self.usrp.set_rx_freq(k)
> > > > > > > > > >         self.stream_cmd =
> > > > > > > > > >
> > uhd.types.StreamCMD(uhd.types.StreamMode.start_cont)
> > > > > > > > > >         self.stream_cmd.stream_now = True
> > > > > > > > > >       
> > > > >  self.streamer_rx.issue_stream_cmd(self.stream_cmd)
> > > > > > > > > >         while
> > > > > self.usrp.get_rx_sensor("lo_locked").to_bool()
> > > > > > > !=
> > > > > > > > > True:
> > > > > > > > > >             continue
> > > > > > > > > > 
> > > > > > > > > >         samps = np.array([], dtype=np.complex64)
> > > > > > > > > >         while recv_samps < self.samples:
> > > > > > > > > > 
> > > > > > > > > >             samps =
> > > > > > > > > > self.streamer_rx.recv(self.recv_buff,
> > > > > > > > > > self.metadata_rx)
> > > > > > > > > >             if self.metadata_rx.error_code !=
> > > > > > > > > > lib.types.rx_metadata_error_code.none:
> > > > > > > > > >                 print(self.metadata_rx.strerror())
> > > > > > > > > >             if samps:
> > > > > > > > > >                 real_samps = min(self.samples -
> > > > > recv_samps,
> > > > > > > > > samps)
> > > > > > > > > >                 result[:, recv_samps:recv_samps +
> > > > > real_samps]
> > > > > > > =
> > > > > > > > > > self.recv_buff[:, 0:real_samps]
> > > > > > > > > >                 recv_samps += real_samps
> > > > > > > > > >         #print (self.usrp.get_rx_sensor('rssi'))
> > > > > > > > > >       
> >  #print(self.streamer_rx.get_max_num_samps())
> > > > > > > > > >         #while samps:
> > > > > > > > > >         #    samps =
> > > > > self.streamer_rx.recv(self.recv_buff,
> > > > > > > > > > self.metadata_rx)
> > > > > > > > > > 
> > > > > > > > > > 
> > > > > > > > > >         #self.stream_cmd.time_spec =
> > > > > lib.types.time_spec(0)
> > > > > > > > > >         self.stream_cmd =
> > > > > > > > > >
> > lib.types.stream_cmd(lib.types.stream_mode.stop_cont)
> > > > > > > > > >       
> > > > >  self.streamer_rx.issue_stream_cmd(self.stream_cmd)
> > > > > > > > > >       
> > > > >  complex_buffs=np.append(complex_buffs,result).ravel()
> > > > > > > > > >         #correct_result=result
> > > > > > > > > >         correct_result_1=result-
> > > > > > > > > > (np.mean(result.real)+np.mean(result.imag)*1j)
> > > > > > > > > >         #correct_result.real=result.real-
> > > > > np.mean(result.real)
> > > > > > > > > >         #correct_result.imag = result.imag -
> > > > > > > np.mean(result.imag)
> > > > > > > > > >         PSD =  self.fft_test(result)
> > > > > > > > > > 
> > > > > > > > > > 
> > > > > > > > > >         #PSD[8188:8202]=np.mean(PSD[8180:8188])
> > > > > > > > > > 
> > > > > > > > > > 
> > > > > > > > > >         buffs = np.append(buffs,PSD)
> > > > > > > > > > 
> > > > > > > > > > 
> > > > > > > > > > 
> > > > > > > > > >     return complex_buffs,
> > > > > > > > > > 
> > > > > buffs#np.append(buffs[value.samples:],buffs[:value.samples])
> > > > > > > > > > 
> > > > > > > > > > 
> > > > > > > > > > def test_reciev(self,freq,bandwich):
> > > > > > > > > >     complex_buffs=np.array([])
> > > > > > > > > >     buffs = np.array([])
> > > > > > > > > >     result = np.empty((len([0]), self.samples),
> > > > > > > > > dtype=np.complex64)
> > > > > > > > > >     for i, freqq in enumerate(freq):
> > > > > > > > > > 
> > > > > > > > > >         recv_samps = 0
> > > > > > > > > >         #self.usrp.set_rx_rate(bandwich[i])
> > > > > > > > > >         k=uhd.types.TuneRequest(freqq)
> > > > > > > > > >       
> >  #k.args(uhd.types.device_addr("mode_n=integer")
> > > > > > > > > > )
> > > > > > > > > >         self.usrp.set_rx_freq(k)
> > > > > > > > > > 
> > > > > > > > > >         while
> > > > > self.usrp.get_rx_sensor("lo_locked").to_bool()
> > > > > > > !=
> > > > > > > > > True:
> > > > > > > > > >             continue
> > > > > > > > > > 
> > > > > > > > > >        
> > > > > > > > > >         while recv_samps < self.samples:
> > > > > > > > > > 
> > > > > > > > > >             samps =
> > > > > > > > > > self.streamer_rx.recv(self.recv_buff,
> > > > > > > > > > self.metadata_rx)
> > > > > > > > > >             if self.metadata_rx.error_code !=
> > > > > > > > > > lib.types.rx_metadata_error_code.none:
> > > > > > > > > >                 print(self.metadata_rx.strerror())
> > > > > > > > > >             if samps:
> > > > > > > > > >                 real_samps = min(self.samples -
> > > > > recv_samps,
> > > > > > > > > samps)
> > > > > > > > > >                 result[:, recv_samps:recv_samps +
> > > > > real_samps]
> > > > > > > =
> > > > > > > > > > self.recv_buff[:, 0:real_samps]
> > > > > > > > > >                 recv_samps += real_samps
> > > > > > > > > >         #print (self.usrp.get_rx_sensor('rssi'))
> > > > > > > > > > 
> > > > > > > > > > 
> > > > > > > > > >         self.stream_cmd.time_spec =
> > > > > lib.types.time_spec(0)
> > > > > > > > > >       
> > > > >  self.streamer_rx.issue_stream_cmd(self.stream_cmd)
> > > > > > > > > >       
> > > > >  complex_buffs=np.append(complex_buffs,result).ravel()
> > > > > > > > > >         correct_result=result
> > > > > > > > > >         correct_result_1=result-
> > > > > > > > > > (np.mean(result.real)+np.mean(result.imag)*1j)
> > > > > > > > > >         correct_result.real=result.real-
> > > > > np.mean(result.real)
> > > > > > > > > >         correct_result.imag = result.imag -
> > > > > > > np.mean(result.imag)
> > > > > > > > > >         PSD =  self.fft_test(result)
> > > > > > > > > > 
> > > > > > > > > > 
> > > > > > > > > >         #PSD[8188:8202]=np.mean(PSD[8180:8188])
> > > > > > > > > > 
> > > > > > > > > > 
> > > > > > > > > >         buffs = np.append(buffs,PSD)
> > > > > > > > > > 
> > > > > > > > > > 
> > > > > > > > > > 
> > > > > > > > > >     return complex_buffs,
> > > > > > > > > > 
> > > > > buffs#np.append(buffs[value.samples:],buffs[:value.samples])
> > > > > > > > > > 
> > > > > > > > > > 
> > > > > > > > > > 
> > > > > > > > > > 
> > > > > > > > > > 
> > > > > > > > > > 
> > > > > > > > > > 
> > > > > > > > > > _______________________________________________
> > > > > > > > > > USRP-users mailing list
> > > > > > > > > > USRP-users@lists.ettus.com
> > > > > > > > > > 
> > > > > 
> > http://lists.ettus.com/mailman/listinfo/usrp-users_lists.ettus.com
> > 


_______________________________________________
USRP-users mailing list
USRP-users@lists.ettus.com
http://lists.ettus.com/mailman/listinfo/usrp-users_lists.ettus.com

Reply via email to