SoftGNSS/GNSS_SDR_IQ/GNSS_SDR_IQ.m

97 lines
3.5 KiB
Mathematica
Raw Normal View History

2025-10-22 16:08:12 +07:00
%--- Include folders with functions ---------------------------------------
addpath include % The software receiver functions
addpath geoFunctions % Position calculation related functions
%% Clean up the environment first =========================================
%%clc; close all; %
format ('compact');
format ('long', 'g');clc
%--- Include folders with functions ---------------------------------------
addpath include
fprintf('-------------------------------\n\n');
%% Initialize the setting
global settings;
settings = initSettings_IQ();
disp(' ');
fprintf('Probing data (%s)...\n', settings.fileName)
[fid, message] = fopen(settings.fileName, 'rb');
%% Acquisition ============================================================
fseek(fid, settings.skipNumberOfBytes, 'bof');
tmp = fread(fid, 2*11*settings.samplesPerCode, settings.dataType)';
%tmp=tmp-127.5;
data=tmp(1:2:end)+1i*tmp(2:2:end);
hist(tmp(1:2:end),20); grid on;
xlabel('Bin');
ylabel('Number in Bin');
%--- Do the acquisition -------------------------------------------
disp ('Acquiring satellites...');
acqResults = acquisitionIQ(data, settings);
%acqResults = acquisitionIQ_weak(data, settings);
plotAcquisition(acqResults);
% acqResults.carrFreq(1)=-1e3;
% acqResults.codePhase(1)=1;
% acqResults.peakMetric(1)=2;
% plotAcquisition(acqResults);
settings.numberOfChannels = min([settings.numberOfChannels, sum(acqResults.peakMetric > settings.acqThreshold)]);
if (any(acqResults.peakMetric > settings.acqThreshold))
channel = preRun(acqResults, settings);
% channel(1).PRN=1;
% channel(1).acquiredFreq=acqResults.carrFreq(1);
% channel(1).codePhase=acqResults.codePhase(1);
% channel(1).status='T';
% settings.numberOfChannels=1;
showChannelStatus(channel, settings);
else
% No satellites to track, exit
disp('No GNSS signals detected, signal processing finished.');
trackResults = [];
fclose(fid);
return;
end
%% Track the signal =======================================================
startTime = now;
disp ([' Tracking started at ', datestr(startTime)]);
for cidx=1:size(channel,2)
if channel(cidx).acquiredFreq >settings.samplingFreq/2;
channel(cidx).acquiredFreq=channel(cidx).acquiredFreq-settings.samplingFreq;
end;
end;
showChannelStatus(channel, settings);
%channel.codePhase=3351 ;
[trackResults, channel] = tracking_V0_IQ(fid, channel, settings);
% Close the data file
if fid>0
fclose(fid);
end;
disp([' Tracking is over (elapsed time ', ...
datestr(now - startTime, 13), ')'])
% Auto save the acquisition & tracking results to a file to allow
% running the positioning solution afterwards.
disp(' Saving Acq & Tracking results to file "trackingResults.mat"')
save('trackingResults', ...
'trackResults', 'settings', 'acqResults', 'channel');
%% Calculate navigation solutions =========================================
disp(' Calculating navigation solutions...');
navSolutions = postNavigation0(trackResults, settings);
%navSolutions = postNavigationSnapshot(trackResults, settings);
disp(' Processing is complete for this data block');
%% Plot all results ===================================================
disp (' Ploting results...');
if settings.plotTracking
plotTracking(1:settings.numberOfChannels, trackResults, settings);
end
plotNavigation(navSolutions, settings);
disp('Post processing of the signal is over.');