Sort satellites in Satellite Communication Toolbox

I take satellite information from TLE file, which contains information about 500+ satellites.
Can I show in satelliteScenarioViewer only satellites with Orbital Position > 50?
How can I do it?

 Accepted Answer

Hi @Dl,
I understand that you seek guidance in shortlisting the satellites based on a particular condition i.e. orbital inclination greater than 20 degrees. To display only these satellites in the Satellite Scenario Viewer, it requires parsing the TLE file to extract orbital parameters, identify the satellites that satisfy the inclination criteria, and then selectively visualize those specific satellites in the scenario viewer.
Following Step 2, where I have applied filters to isolate satellites that meet the specific criteria, I proceed to Step 4. In this step, I process each of the shortlisted satellites. For each one, I determine its precise location within the input file (`file.txt`), then proceed to record not only the satellite's name but also the subsequent two lines of data into the output file (`filteredSatellites.txt`). This output file is then passed on to the "scenarioViewer" function for visualiztion purpose.
Here is a MATLAB code snippet that demonstrates the process
% Step 1: read the TLE file and parse it
tleData = tleread('file.txt');
% Step 2: filter satellites based on inclination
selectedSatellites = {};
for i = 1:length(tleData)
inclination = tleData(i).Inclination;
if inclination > 20
selectedSatellites{end+1} = tleData(i);
end
end
% Step 3: create a satellite scenario
startTime = datetime(2023, 1, 1, 0, 0, 0);
stopTime = startTime + days(1);
sampleTime = 60; % in seconds
sc = satelliteScenario(startTime, stopTime, sampleTime);
% Step 4: write selected satellites to a txt file
outputFile = "filteredSatellites.txt";
out = fopen(outputFile, 'w');
for i = 1:length(selectedSatellites)
% extract name for the satellite
satelliteName = selectedSatellites{i}.Name;
% writeNextTwoLines locates the position of selectedSatellite
% within the input file 'file.txt'
writeNextTwoLines = false;
linesToWrite = 2;
f = fopen('file.txt', 'r');
while ~feof(f)
currLine = fgets(f);
if contains(currLine, satelliteName)
fprintf(out, '%s\n', satelliteName);
writeNextTwoLines = true;
continue
end
% selected satellite is found then, and the next two
% lines are written to the output file
if writeNextTwoLines & linesToWrite
fprintf(out, '%s', currLine);
linesToWrite = linesToWrite - 1;
end
end
fclose(f);
end
fclose(out);
sat = satellite(sc, 'filteredSatellites.txt');
% Step 5: visualization
viewer = satelliteScenarioViewer(sc);
Have a look at the following references for a better understanding
I hope this helps.

10 Comments

Dl
Dl on 10 Jan 2024
Edited: Dl on 10 Jan 2024
What is TLELines?
My file is .txt, is it a problem?
tleData = tleread("tle.txt");
Error using tleread
Unable to create Two-Line Element (TLE) structure because the file 'tle.txt' was not found.
selectedSatellites = {};
for i = 1:length(tleData)
year = tleData(i).Epoch.Year - 2000;
frac_day = tleData(i).Epoch.Day + days(duration(tleData(i).Epoch.Hour,tleData(i).Epoch.Minute,tleData(i).Epoch.Second));
julian_date = 2451544.5 + 365 * year + floor(0.25 * year) + floor(0.01 * year) + floor(0.0025 * year) + frac_day;
julian_centuries = (julian_date - 2451545) / 36525;
earth_rotation_angle = mod(2 * pi * (0.779057273264 + 0.00273781191135448 * julian_centuries * 36525 + (mod(julian_centuries * 36525,1))), 2 * pi);
if earth_rotation_angle < 0
earth_rotation_angle = 2 * pi + earth_rotation_angle;
end
gmst = mod((earth_rotation_angle + (0.014506 + 4612.15739966 * julian_centuries + 1.39667721 * julian_centuries * 10e2 - 0.00009344 * julian_centuries* 10e3 + 0.00001882 * julian_centuries * 10e4) / 60 / 60 * pi / 180) ,(2 *pi));
if gmst < 0
gmst = 2 * pi + gmst;
end
vernal_equinox = -gmst * 180 / pi;
orb_pos = round(mod(tleData(i).RightAscensionOfAscendingNode + tleData(i).ArgumentOfPeriapsis + tleData(i).MeanAnomaly + vernal_equinox, 360));
if orb_pos > 180
orb_pos = orb_pos - 360
else
orb_pos
end
if orb_pos > 175
selectedSatellites{end+1} = tleData(i);
end
end
sc = satelliteScenario();
for i = 1:length(selectedSatellites)
satn = satellite(sc, selectedSatellites{i}.TLELines);
end
satelliteScenarioViewer(sc);
This is my code and it doesn't work :(
Hi @Dl, could you please help me with the "tle.txt" file, it will allow me to reproduce the issue at my end and address the problem you are facing.
Hi
It's just really .txt file with text like this
It contains more satellites but looks exactly the same way
TDRS 5
1 21639U 91054B 24010.68729772 .00000098 00000+0 00000+0 0 9990
2 21639 14.1828 0.2823 0025271 355.3430 194.2333 1.00273517118799
IUS R/B(1)
1 21640U 91054C 24010.66407335 .00014000 00000+0 29686-2 0 9990
2 21640 26.3989 148.1621 6726049 148.4213 280.2536 3.00852110312745
IUS R/B(2)
1 21641U 91054D 24010.09670545 .00000106 00000+0 00000+0 0 9991
2 21641 14.7247 340.3842 0034282 326.2724 55.5420 1.00175445 38458
Hi @Dl,
Based on the details you have provided, I have refined the method to process a TXT file and extract specific satellite data according to the set criteria. Concerning the error mentioned in your comments, it appears that the file you are trying to read cannot be located at the specified path. To resolve this, please double-check the file name and confirm that the path is correctly specified when using the `tleread` function.
I have successfully applied the revised technique to the TXT file you supplied. I have included comments within the code to aid your understanding of the approach. Should you encounter any difficulties or require further clarification on the procedure, please let me know.
Wow, it literally should work but it gives me this mistake in the end of the code.
Error using feof
Invalid file identifier. Use fopen to generate a valid file identifier.
But everything is right according to MathHelp...
Could you please verify the file's location that you are re attempting to access? The error you are encountering typically occurs when the specified file cannot be located, or the file name has been incorrectly entered. Make sure the file path is correct and that the file name is spelled accurately.
I get f = -1, but
If I change
f = fopen('file.txt', 'r');
to
f = fopen('filteredSatellites.txt', 'r');
so I get f = 25, but then I get a mistake in
currLine = fgets(f);
currLine = -1 here
This will be your 'file.txt'. Whatever is the name at your side for this file, do replace it and proceed with the approach.
TDRS 5
1 21639U 91054B 24010.68729772 .00000098 00000+0 00000+0 0 9990
2 21639 14.1828 0.2823 0025271 355.3430 194.2333 1.00273517118799
IUS R/B(1)
1 21640U 91054C 24010.66407335 .00014000 00000+0 29686-2 0 9990
2 21640 26.3989 148.1621 6726049 148.4213 280.2536 3.00852110312745
IUS R/B(2)
1 21641U 91054D 24010.09670545 .00000106 00000+0 00000+0 0 9991
2 21641 14.7247 340.3842 0034282 326.2724 55.5420 1.00175445 38458
Thank You so much!
Now it works!
I'm really new in MatLab and didn't do any studies before, it was so unexpected
You helped me very very much!

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2023b

Asked:

Dl
on 9 Jan 2024

Commented:

Dl
on 11 Jan 2024

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!