%% init
clc;
clear all;
close all;

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

fm = 10e3;
Um = 0.2;
m = 0.3;

testam = wavread('audio_test.wav');
kanalam1 = testam(1:30000);
kanalam = interp(testam(1:30000,1),200);
kanalam = 10*kanalam;
clear testam;

%% modulate harmonic
t = (0:(1/fvz):(200/fm-1/fvz));
carier = Uc* cos(2*pi*fc*t);
modulating = Um*cos(2*pi*fm*t);
am =(1+m*cos(2*pi*fm*t)).*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),am(1000:3000));

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

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

figure(3);
subplot(3,1,1);
plot (t,carier');
subplot(3,1,2);
plot (t,kanalam);
subplot(3,1,3);
plot (t,amtest);

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

figure(5);
Samtest = (abs(fft(kanalam1)));
frekv = (0:(fs/length(Samtest)):(fs-fs/length(Samtest)));
plot (frekv,Samtest);

%% write data
% csvwrite('am_signal.csv',am);
% csvwrite('am_signal_test.csv',amtest);
% csvwrite('modulate.csv',modulating);
% csvwrite('carier.csv',carier);