clear all;
close all;
clc;

fs = 50e6;
fc = 3e6;
threshold = 0.01;
t = (1/fs:1/fs:120/fc);
carier = 0.5*cos(2*pi*fc*t-pi/2);
data = [ 1 0 1 1 0 1 0 1 0 1 1 0 1 0 1 0 1 ];
cw_signal (1:1600) = 0;

for n = 1:1600
    ind = uint16(n/100);
    if (data(ind+1)==1)
        cw_signal(n) = carier(n-100*(ind-1)+1);
    else
        cw_signal(n) = 0;
    end    
end    



figure(1)
subplot(2,1,1);
for n = 1:1600
    if (data(uint16(n/100)+1)>0)
        dataup(n) = 1;
    else
        dataup(n) = 0;
    end    
end  
plot(t(1:1600),dataup);
subplot(2,1,2);
plot(t(1:1600),cw_signal);

carrier_loc = 0.5*cos(2*pi*(fc+1e3)*t-pi/2);

figure(2);
subplot(3,1,1);
plot(t(1:1600),cw_signal);
subplot(3,1,2);
input = cw_signal.*carrier_loc(1:1600);  %.*cw_signal;
output = filter(lp,input);
plot(t(1:1600),output);



for n = 1:1600
    if (output(n)>threshold)
        out(n) = 1;
    else
        out(n) = 0;
    end    
end  

subplot(3,1,3);
plot(t(1:1600),out);

%%
figure(3);
plot(abs(fft(output)));

figure(4);
plot(abs(fft(input)));

