%% init
clc;
clear all;
close all;

fvz = 8.82e6;
fs = 44100;
fc = 1e6;
Uc = 0.5;

fm = 10e3;
Um = 0.2;

testam = wavread('audio_test.wav');
kanaldsb = interp(testam(1:40000,1),200);
clear testam;

%% modulate harmonic
t = (0:(1/fvz):(length(kanaldsb)/fvz)-1/fvz);
carier = Uc* cos(2*pi*fc*t);
modulating = Um*cos(2*pi*fm*t);
dsb = modulating.*carier;

figure(1);
subplot(3,1,1);
plot (t(1000:3000),carier(1000:3000));
subplot(3,1,2);
plot (t(1000:3000),modulating(1000:3000));
subplot(3,1,3);
plot (t(1000:3000),dsb(1000:3000));

figure(2);
Sdsb = (abs(fft(dsb)));
frekv = (0:(fvz/length(t)):(fvz-fvz/length(t)));
plot (frekv,Sdsb);


%% modulate real
t = (0:(1/fvz):(length(kanaldsb)/fvz)-1/fvz);
carier = Uc* cos(2*pi*fc*t);
dsb_test = kanaldsb .* carier';

figure(3);
subplot(3,1,1);
plot (t,carier');
subplot(3,1,2);
plot (t,kanaldsb);
subplot(3,1,3);
plot (t,dsb_test);

figure(4);
Sdsbtest = (abs(fft(dsb_test)));
frekv = (0:(fvz/length(t)):(fvz-fvz/length(t)));
plot (frekv,Sdsbtest);

%% write data
% csvwrite('dsb.csv',dsb);
% csvwrite('dsb_test.csv',dsb_test);
% csvwrite('modulate_dsb.csv',modulating);
% csvwrite('carier.csv',carier);
