%% BPSK
% Tomas Krejci, 11.4.2015

clc 
close all
clear all
      
data = [1 1 0 1 0 0 0 1 1 1];
% = randi([0 1], n_data, 1)

%% BPSK

fs = 100E6;  
Ts = 10E-6; % interval symbolu

n_data = length(data);
Tr = n_data * Ts; % delka celeho signalu
nn = fs*Ts; % pocet vzorku v symbolovem intervalu
t = 0 : 1/fs :  Tr - 1/fs; 

y_c = zeros(1, nn * n_data);
y_s = zeros(1, nn * n_data);

for ii = 1 : n_data
    
    if data(ii) == 0
        y_c((ii-1)*nn+1 : ii*nn ) = 1;
        y_s((ii-1)*nn+1 : ii*nn ) = 1;
    else
        y_c((ii-1)*nn+1 : ii*nn ) = -1;
        y_s((ii-1)*nn+1 : ii*nn ) = -1;
    end
    
end
f = 1E6; % frekvence nosne
s = y_c .* cos(2*pi*f*t) + y_s .* sin(2*pi*f*t); % vysledny signal

S= 10*log10((abs(fftshift(fft(s)))).^2);% energetické spektrum signálu 
fx = fs/2 * linspace(-1,1,length(s)); 

figure;
subplot(2,1,1); plot(t,s); title('BPSK'); xlabel('t [s]'); ylabel('A [V]');
subplot(2,1,2); plot(fx,S); title('Spektrum');xlabel('f [Hz]'); ylabel('Se [dB]');
            ylim([-20 max(S)*1.2 ]); xlim([-3E6 3E6]);




