Skip to content

Instantly share code, notes, and snippets.

@zulonas
Created November 14, 2020 21:29
Show Gist options
  • Save zulonas/7352ce6d32a25c711f86ee16d294cca7 to your computer and use it in GitHub Desktop.
Save zulonas/7352ce6d32a25c711f86ee16d294cca7 to your computer and use it in GitHub Desktop.
DSSS modulation
clearvars;
init_seq = [0, 1, 0, 1, 0, 0, 1, 0];
bit_sample = 8; % bit sample size
% Expanding bit sequence with by bit_sample size
bit_seq = zeros(1, bit_sample .* length(init_seq));
k = 1;
for i=1:length(init_seq)
for j=1:bit_sample
bit_seq(k) = init_seq(i);
k = k + 1;
end
end
figure;
stairs(bit_seq,'linewidth',2);
axis([0 length(bit_seq) -0.5 1.5]);
title('ORIGINAL BIT SEQUENCE b(t)');
% Generating the pseudo random bit pattern
rand_sig = round(rand(1,length(bit_seq)));
figure;
stairs(rand_sig, 'linewidth', 2);
axis([-1 length(rand_sig) -.5 1.5]);
title('PSEUDORANDOM BIT SEQUENCE rand(t)');
% XORing the pattern with the spread signal
hopped_sig = xor(bit_seq, rand_sig);
figure;
stairs(hopped_sig,'linewidth',2);
axis([0 length(hopped_sig) -.5 1.5]);
title('MULTIPLIER OUTPUT SEQUENCE: b(t) XOR rand(t)');
% Modulating the hopped signal
dsss_sig = [];
fc = 1/10;
time_axis = 0:fc:2 * pi;
c1 = cos(time_axis);
c2 = cos(time_axis + pi);
for k=1:length(bit_seq)
if hopped_sig(1, k) == 0
dsss_sig = [dsss_sig c1];
else
dsss_sig = [dsss_sig c2];
end
end
figure;
stairs(dsss_sig, 'linewidth', 2);
% axis([0 (length(time_axis) * 10) -1.5 1.5]);
axis([0 length(dsss_sig) -1.5 1.5]);
title('DSSS SIGNAL');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment