You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
Finding a suitable Direction Finder Alogrithm
10 views (last 30 days)
Show older comments
Hi, am doing a radio direction finder project and i used parasatic monopole antenna array to switch the radiation beam in each direction. am using hackrf to capture the data and then i matlab i used this code:
function y = loadFile(filename)
% fid = fopen(filename,'rb'); y = fread(fid,'uint8=>double'); y = y-127.5; y = y(1:2:end) + i*y(2:2:end);
compass(y)
but i seem to be getting only one reading which gives me only one direction all the time. can you help me out please and is there a better way for me to process the captured file.
17 Comments
Walter Roberson
on 21 Jun 2018
If I remove the comment mark, then it works with the random data I created.
data = randi([0 255], [1 50],'uint8');
filename = 'test.bin';
fid = fopen(filename,'w');
fwrite(fid,data,'uint8');
fclose(fid);
fid = fopen(filename,'rb'); y = fread(fid,'uint8=>double'); y = y-127.5; y = y(1:2:end) + i*y(2:2:end);
compass(y)
Ahmed Siddig
on 21 Jun 2018
Sorry about the comment mark i forgot it. So when i tried the code above with a different filename i got this error : Error using fwrite Invalid file identifier. Use fopen to generate a valid file identifier.
Error in Untitled (line 4) fwrite(fid,data,'uint8');
Ahmed Siddig
on 21 Jun 2018
Edited: Walter Roberson
on 21 Jun 2018
For example i have this file inside it is a .bin file which i captured using the hackrf one with a sampling rate of 2000000 & a number of samples of 10 & a gain of 32 and when i try this code:
fid = fopen(ahm.bin,'rb');
y = fread(fid,'uint8=>double');
y = y-127.5;
y = max(y(1:2:end) + i*y(2:2:end));compass(y)
I end up with the direction in the middle between 90 and 180 (i believe it's 135) knowing that i captured it in the 0 direction.
thanks.
Walter Roberson
on 21 Jun 2018
Note that max() applied to a complex number ignores the imaginary part.
When I look in the file, I see that the odd-numbered components are 6 or 5, and that the event components are in the range of 248 to 251. There is no way I can see that you could get an angle near 0 from that. I can manipulate it to get angles of 135.117265041982 or of 307.694240466689 but not near 0.
Ahmed Siddig
on 21 Jun 2018
Ok about the max() can't i use any other function to display the highest reading. And let's say we want 307.69 how did you get that? thanks.
Walter Roberson
on 21 Jun 2018
fid = fopen('ahm.bin','rb');
y = fread(fid, 'int8=>double');
fclose(fid);
t = mean(y(1:2:end)) + 1i * mean(y(2:2:end));
ang = angle(t) * 180/pi;
"highest reading" does not have a clear meaning for complex numbers.
Ahmed Siddig
on 21 Jun 2018
Sorry but apparently am getting no where it still plots the same direction no matter what i tried. don't you know any way to display the direction of arrival. thanks again.
Walter Roberson
on 21 Jun 2018
What do the values represent? For example if the adjusted values represent signal strength in decibels then you should probably not be doing plain vector addition on them. One plausible interpretation would be
mean(10.^(y(1:2:end) + 1i*y(2:2:end)))
angle(ans) * 180/pi
ans =
35.0483889088682
but also plausible would be
>> mean(10.^y(1:2:end) + 1i*10.^y(2:2:end))
ans =
190000 + 1.351e-06i
>> angle(ans) * 180/pi
ans =
4.07403148011443e-10
Ahmed Siddig
on 21 Jun 2018
There are IQ data but the problem is that i have to plot the result in compass().
Walter Roberson
on 21 Jun 2018
When I check around, I find that it is signed values, not unsigned like you used. It needs to be demodulated though.
Quadrature signals are deliberately phase encoded, so you cannot use the information as a direction finder.
Ahmed Siddig
on 21 Jun 2018
Edited: Walter Roberson
on 21 Jun 2018
OK sorry to ask but any idea how to deal with it in the same manner. For the record i added one of your codes above:
fid = fopen('ahm.bin','rb');
y = fread(fid,'uint8=>double');
fclose(fid)
y=mean(10.^(y(1:2:end) + 1i*y(2:2:end)))
compass(y);
actually it went well most of them started moving and some of them were right so that's a start how can i improve it thanks.
Walter Roberson
on 21 Jun 2018
You need
y = fread(fid,'int8=>double');
I do not think the 10^ version is appropriate now that I have read more about the data. I consistently found people saying it was 8 bit signed complex data. As such, -128 is the minimum and 127 is the maximum, so my original thought that you could perhaps read them as degrees turned out to be incorrect.
With a sufficiently long signal you should be able to plot the quadrature constellations in order to determine how many states are being encoded.
The phase is manipulated deliberately as part of the signal, so you cannot use the phase information to locate direction -- at least not on a sample by sample basis.
Ahmed Siddig
on 21 Jun 2018
Oh that's an issue i'll keep looking and notify you of any updates. thanks a lot Mr.Roberson
Ahmed Siddig
on 21 Jun 2018
You know i tried the RTL-SDR with the original code and it was good most of them were right so i guess we'll just have for figure out a way to either convert the signed value to unsigned value or modify the code to deal with singed values.
Ahmed Siddig
on 22 Jun 2018
Hi, so as i said using the RTL-SDR, the arrow started moving with every reading but i can't get it to point to the right position so how can i manipulate the reading to get it fixed? and if possible how to improve it? I attached some readings that i recorded E,N,W,S indicates the direction where i took the reading from. Thanks.
Answers (0)
See Also
Categories
Find more on Phased Array Design and Analysis in Help Center and File Exchange
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)