Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always similar graph output? Center freq. spike? #94

Closed
orhun opened this issue Jan 15, 2019 · 22 comments
Closed

Always similar graph output? Center freq. spike? #94

orhun opened this issue Jan 15, 2019 · 22 comments

Comments

@orhun
Copy link

orhun commented Jan 15, 2019

I'm trying to implement FFT and plot samples that I get from RTL-SDR device. But I'm always getting the similar output and a spike at the center of the graph even though I change the center frequency.
The code that I'm using is test.py which is provided at this repository. Is this problem related to my device?

screenshot from 2019-01-15 15-22-44

screenshot from 2019-01-15 15-24-05

@nocarryr
Copy link
Collaborator

@KeyLo99 This is common and expected behavior. Check out issue #84 for some discussion on the topic

@orhun
Copy link
Author

orhun commented Jan 15, 2019

@nocarryr yeah I've seen that issue but is there anything that I can do? (Programmatically)

@roger-
Copy link
Collaborator

roger- commented Jan 15, 2019

There are algorithms you can implement to estimate the error and then compensate. Not sure if Python implementations exist anywhere.

@itdaniher
Copy link
Contributor

https://gist.github.com/itdaniher/7ac96d5e6f477b3d0e4bb03f6df466dd

I don't have source for this excerpt, but had it saved in my "interesting bits of SDR code" folder. Might be of use here.

see also: https://wiki.analog.com/resources/eval/user-guides/ad-fmcomms1-ebz/iq_correction

@nocarryr
Copy link
Collaborator

@itdaniher that gist is quite interesting! I'll have to find some time to study it. I wonder though, because of this:

# scale Q to have unit amplitude (remember we're assuming a single input tone)

Is the input assumed to be mostly periodic? If the input were uncorrelated noise, would the result still be reasonable, at least for spectral estimation?

(I really regret not getting a college education)

@itdaniher
Copy link
Contributor

itdaniher commented Jan 15, 2019

There's also "a stochastic solver to optimize frequency dependent amplitude and phase imbalance"
at https://github.com/airspy/airspyhf/blob/master/libairspyhf/src/iqbalancer.c, but it's even less documented than my excerpt, and... I have had very unpleasant interactions with the Airspy team.

@nocarryr
Copy link
Collaborator

Wow, looks very adaptive. I wonder how the DcTimeConst value (5e-5f) was determined

@itdaniher
Copy link
Contributor

@nocarryr I wouldn't fret about the college edu - learned less relevant stuff from my ECE professors than I did from ie) https://dspguide.com/ / wikipedia.

I would like to think it works with uncorrelated / whitenoise, but I'm not willing to speak authoritatively as of yet. Fundamentally you're just trying to solve for the... 2x2 offset/rotation matrix - also expressible as phase/amplitude error. It varies at least a little bit with regards to time, temperature, frequency, etc (all the things ADCs can vary with, and then some!), which is maybe / probably why some folks use iterative approaches.

two pdfs to call out

@nocarryr
Copy link
Collaborator

Thanks! I'll add those to my library give them a read

@orhun
Copy link
Author

orhun commented Jan 15, 2019

Thanks for the awesome gist and explanatory sources. But I'm wondering, do you have the same "IQ balancer" implementation in C? Later I might change my mind from Python to C. If you don't have it or don't know any sources, I will rewrite :)

@nocarryr
Copy link
Collaborator

I imagine it would be fairly straightforward to create a wrapper for airspy so that you can use it in python.

There are a few approaches

  1. ctypes which is in python's standard library. A good example would be this project itself
  2. CFFI even though I haven't used it much, its designed to minimize the amount of work involved with translating header code
  3. Cython my favorite these days, I don't use it much for wrapping C/C++ libs, but for the performance gains (generating C from typed python)

@itdaniher
Copy link
Contributor

@KeyLo99 I don't have any closed-form implementations of IQ balancing in C handy, definitely easier to do with numpy IMHO.

@orhun
Copy link
Author

orhun commented Jan 16, 2019

@itdaniher I have to implement IQ Correction algorithm in C because I'm using librtlsdr [C]. Another reason is I didn't find any good C implementation except the non-documented and complex ones. So I want to write a clean and simple code that handles IQ Correction and other stuff.
Would you tell me what algorithm you used in that Python gist? Or leave some links, PDFs, etc.

@itdaniher
Copy link
Contributor

@KeyLo99 found it the source at https://www.reddit.com/r/RTLSDR/comments/uje3q/sample_python_code_and_results_for_iq_correction/

I don't think "clean and simple" + "DSP in C" is a semantically valid construct.... liquid-dsp might save you some pain, but that's not likely to result in an implementation that could be upstreamed into librtlsdr.

@roger-
Copy link
Collaborator

roger- commented Jan 18, 2019

Knew that code looked familiar 😂

@nocarryr
Copy link
Collaborator

Hahaha, I didn't notice that at first @roger-

@orhun
Copy link
Author

orhun commented Jan 18, 2019

Okay, I kinda solved the problem with playing with the antenna and cables, changing the receiver position. Central peak disappeared but it looks like I/Q data that I get from device still needs some fixing and balance. I will try to apply any filter/algorithm to my raw I/Q and FFT [out] data to fix this imbalance issue. I'm open to your suggestions :)

@orhun
Copy link
Author

orhun commented Jan 18, 2019

  • And this is the latest graph I'm getting right now:

screenshot from 2019-01-19 04-23-45

@itdaniher
Copy link
Contributor

time-average that some, but it looks okay to me!

Seems like you're seeing the 200KHz BW WBFM signal around... 99.9FM?

@orhun
Copy link
Author

orhun commented Jan 19, 2019

Yeah looks like so...
I'm gonna make this code public for SDR researchers/enthusiasts when I'm done fixing issues about efficiency. I hope you guys will tell me the points that I don't get and I should fix :)

@itdaniher
Copy link
Contributor

Please do!

@orhun
Copy link
Author

orhun commented Jan 27, 2019

Alright, there you go: https://github.com/KeyLo99/rtl_map

Waiting for feedbacks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants