Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
arnauochoa committed Nov 18, 2020
0 parents commit 727a661
Show file tree
Hide file tree
Showing 8 changed files with 185 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.dat
21 changes: 21 additions & 0 deletions DataReader.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
function signal = DataReader(fileIn, duration)

%%% fileIN is the path to access the file that contains the data.
%%% Duration is the number of samples to read.

% Opening the file
fidIn = fopen(fileIn,'rb');

% Identifier file = -1 -> cant read the file
if (fidIn == -1)
error(sprintf('Erreur ouverture %s',fileIn));
end

[signal,nB] = fread(fidIn,duration,'bit2');

% if (nB ~= duration)
% error(sprintf('Erreur lecture %s',fileIn));
% end

% Closing the file
fclose(fidIn);
Empty file added README.md
Empty file.
78 changes: 78 additions & 0 deletions ca_code.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
function code = ca_code(prn)
% function code = ca_code(prn)
% This function returns the C/A code sequence (1023 bytes long,
% represented as 1023x1 vector of integers with values of +/- 1

% Error messages

if nargin~=1
error('insufficient number of input argumnets')
end
if prn<0 | prn > 37
error('invalid prn: must be between 1 and 37')
end

g2shift_vector=[5 6 7 8 17 18 139 140 141 251 252 254 255 256 257 258 ...
469 470 471 472 473 474 509 512 513 514 515 516 859 860 861 862 ...
863 950 947 948 950];

g2shift=g2shift_vector(prn);


%
% Generate G1 code
%

% load shift regeister

for i=1:10,
reg(i) = -1;
end

% Generate code

for i=1:1023,
g1(i) = reg(10);
save1 = reg(3)*reg(10);
for j=9:-1:1,
reg(j+1)=reg(j);
end
reg(1)=save1;
end

%
% Generate G2 code
%

% load shift regeister

for i=1:10,
reg(i) = -1;
end

% Generate code

for i=1:1023,
g2(i) = reg(10);
save2 = reg(2)*reg(3)*reg(6)*reg(8)*reg(9)*reg(10);
for j=9:-1:1,
reg(j+1)=reg(j);
end
reg(1)=save2;
end

% Shift the G2 code

for i=1:1023,
k = i+g2shift;
if k > 1023,
k = k-1023;
end
g2tmp(k) = g2(i);
end

g2 = g2tmp;

% Form the C/A code by multiplying G1 and G2

code = g1.*g2;
23 changes: 23 additions & 0 deletions create_code_samples.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
function code_samples = create_code_samples(code_sequence, time_vec)
%%% This function calculates the sampled version of the chosen ca_code_sequence
%%% code_sequence is the C/A PRN code sequence to be sampled
%%% time_vec is the time vector to be time vector for which to be sampled
% starting time of the sampling
% code doppler
%
% Output Parameters: Sampled Array
%
% Error : Error message generated if the number of inouts incorrect
% Date : 22 May, 2003
% Author : Sameet Deshpande
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

if nargin~=2
error('insufficient number of input arguments')
end

code_index = mod( ceil(time_vec), length(code_sequence) );

% Correct for 1023 mod 1023 which returns 0 but should be 1023
code_index( find(code_index == 0) ) = length(code_sequence);
code_samples = code_sequence(code_index);
57 changes: 57 additions & 0 deletions main.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
clear; close all; clc;

filepath = 'test_real_long.dat';

signal = DataReader(filepath, Inf);

load('subsignal.mat');

N = 2^20;
fIF = 4.348e6; %Hz
fs = 23.104e6; %Hz

s = signal5000(1:4096);

omega = linspace(-2*pi, 2*pi, 2*N);

figure
plot(s, 'o-');

figure;
histogram(s);
title('Quantized signal in time domain');
xlabel('k');

S = fft(s);

w = linspace(-2*pi,2*pi,length(s));
figure
plot(w, fftshift(abs(S)));
title('Quantized signal in frequency domain');
xlabel('w');

Rs = xcorr(s, 'biased');
Ss = fft(Rs, 2*N);

figure;
plot(fftshift(abs(Ss)));
title("Spectral density from autocorrelation");
xlabel('w');

[Ss, f] = periodogram(s, rectwin(length(s)), fs);
figure
plot(f, Ss);
title("Spectral density from autocorrelation");
xlabel('f (Hz)');

[Swelch, fwelch] = pwelch(s, [], [], [], fs);
figure
plot([-flip(fwelch) fwelch], [flip(Swelch) Swelch]);
xlabel('f (Hz)'); ylabel('PSD (dB/Hz)');
title('Welch periodogram');






5 changes: 5 additions & 0 deletions main.m~
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
clear; close all; clc;

filepath = 'test_real_long.dat';

signal = DataReader(filepath, );
Binary file added subsignal.mat
Binary file not shown.

0 comments on commit 727a661

Please sign in to comment.