% generovani komplex. exps pro 50 Hz:
t = 0:1e-4:20e-3; 
omega_1 = 2*pi / 20e-3;
e0 = ones(size(t)); 
e1 = exp (j * omega_1 * t); em1 = exp (-j * omega_1 * t); 
e2 = exp (2*j * omega_1 * t); em2 = exp (-j*2 * omega_1 * t); 
e3 = exp (3*j * omega_1 * t); em3 = exp (-j*3 * omega_1 * t); 
e4 = exp (4*j * omega_1 * t); em4 = exp (-j*4 * omega_1 * t); 
subplot(421); 
plot3 (t,real(e0), imag(e0)); xlabel('t'); ylabel('Re'); zlabel('Im'); axis tight; grid; 
subplot(423); 
plot3 (t,real(e1), imag(e1)); xlabel('t'); ylabel('Re'); zlabel('Im'); axis tight; grid; 
subplot(424); 
plot3 (t,real(em1), imag(em1)); xlabel('t'); ylabel('Re'); zlabel('Im'); axis tight; grid; 
subplot(423); 
plot3 (t,real(e1), imag(e1)); xlabel('t'); ylabel('Re'); zlabel('Im'); axis tight; grid; 
subplot(424); 
plot3 (t,real(em1), imag(em1)); xlabel('t'); ylabel('Re'); zlabel('Im'); axis tight; grid; 
subplot(425); 
plot3 (t,real(e2), imag(e2)); xlabel('t'); ylabel('Re'); zlabel('Im'); axis tight; grid; 
subplot(426); 
plot3 (t,real(em2), imag(em2)); xlabel('t'); ylabel('Re'); zlabel('Im'); axis tight; grid; 
subplot(427); 
plot3 (t,real(e3), imag(e3)); xlabel('t'); ylabel('Re'); zlabel('Im'); axis tight; grid; 
subplot(428); 
plot3 (t,real(em3), imag(em3)); xlabel('t'); ylabel('Re'); zlabel('Im'); axis tight; grid; 
slidify(1,2,1,10)
print -depsc FIG/harmexp.eps

%%%%%%%%%%%%%%%%%%%% skladani obdelnika %%%%%%%%%%%%%%%%%%%%%%%%%%%
D = 6; theta = 0.5e-6, T1 = 1e-6; omega1 = 2 * pi / T1; f1 = 1/T1; 
k = -13:13; gj0 = find (k==0);  
ck = D*theta / T1 * sinc (theta/2 * k * omega1 / pi); % pozor Matlab,
   % to pi je tam navic kvuli priblble definici ... 
   
subplot (211); stem (k*f1,abs(ck)); xlabel('f'); ylabel('|c_k|'); grid
subplot (212); stem (k*f1,angle(ck)); xlabel('f'); ylabel('arg c_k'); grid
slidify (1,2,1,10); print -depsc FIG/ck1mhz.eps 

% a skladame - od -1mikrosekunde do +1,
close all; 
t = -T1:T1/100:T1; 
ss = zeros(size(t)); 
% ss slozka:
subplot(4,3,1); obr = 1; ii=0;  
this = ck(gj0) * exp(j*ii*omega1*t); 
subplot(4,3,obr);  plot(t,this); 
ss = ss+this; obr = 3; subplot(4,3,obr);  plot(t,ss);
% a jedeme ! 
for ii=1:2:5, 
  obr = obr+1; 
  thisp = ck(gj0+ii) * exp(j*ii*omega1*t);
  thism = ck(gj0-ii) * exp(-j*ii*omega1*t);
  this = thisp + thism; 
  subplot(4,3,obr); plot3 (t,real(thisp), imag(thisp), t,real(thism), imag(thism)); axis([-1e-6 1e-6 -2 2 -2 2]); 
  obr = obr +1; subplot(4,3,obr); plot(t,this); grid; axis([-1e-6 1e-6 -5 5]);
  ss = ss+this; obr = obr+1; subplot(4,3,obr);  plot(t,ss); 
end 
print -depsc FIG/rozklad1.eps

% a dalsi obrazek  
obr = 0; 
for ii=7:2:13, 
  obr = obr+1; 
  thisp = ck(gj0+ii) * exp(j*ii*omega1*t);
  thism = ck(gj0-ii) * exp(-j*ii*omega1*t);
  this = thisp + thism; 
  subplot(4,3,obr); plot3 (t,real(thisp), imag(thisp), t,real(thism), imag(thism)); axis([-1e-6 1e-6 -2 2 -2 2]); 
  obr = obr +1; subplot(4,3,obr); plot(t,this); grid; axis([-1e-6 1e-6 -5 5]);
  ss = ss+this; obr = obr+1; subplot(4,3,obr);  plot(t,ss); 
end 
print -depsc FIG/rozklad2.eps

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ted nejaka rec - to bude teda humus ... 
s = readl16('a16.l16',0,inf); 
plot (s) 
% norm by 1.5 to be sure ... 
x = s(3668:3816); x = x/1.5/max(abs(x)); plot (x); N = length(x);  
xx = repmat (x,1,50); plot (xx) 
wavwrite(xx,16000,'xx.wav'); 

n = 0:(N-1); 
X = fft(x); ck = 1/N * X; 
k = 0:50; 
subplot (311); plot(n,x); 
subplot(312); stem (k,abs(ck(k+1)));  
subplot(313); stem (k,angle(ck(k+1)));  
print -depsc FIG/rec.eps

% zkusime to udelat po 5-ti ... 
close all 
om1 = 2*pi/N; 
y = zeros(size(n)); 
k=0; this0 = ones(size(n)) * ck(1); 
k=k+1; this1 = 2*abs(ck(k+1)) * cos(k* om1 * n + angle(ck(k+1)));  
k=k+1; this2 = 2*abs(ck(k+1)) * cos(k* om1 * n + angle(ck(k+1)));  
k=k+1; this3 = 2*abs(ck(k+1)) * cos(k* om1 * n + angle(ck(k+1)));  
k=k+1; this4 = 2*abs(ck(k+1)) * cos(k* om1 * n + angle(ck(k+1)));  
subplot(8,2,1); plot (n,this0,n,this1,n,this2,n,this3,n,this4);
y = y + this0 + this1+ this2+ this3+ this4; subplot(8,2,2); plot (y); 
yy = repmat (y,1,50); %plot (yy) 
wavwrite(yy,16000,'yytill4.wav'); 

obr = 2; 
for ii=1:7
  k=k+1; this0 = 2*abs(ck(k+1)) * cos(k* om1 * n + angle(ck(k+1)));  
  k=k+1; this1 = 2*abs(ck(k+1)) * cos(k* om1 * n + angle(ck(k+1)));  
  k=k+1; this2 = 2*abs(ck(k+1)) * cos(k* om1 * n + angle(ck(k+1)));  
  k=k+1; this3 = 2*abs(ck(k+1)) * cos(k* om1 * n + angle(ck(k+1)));  
  k=k+1; this4 = 2*abs(ck(k+1)) * cos(k* om1 * n + angle(ck(k+1)));  
  obr = obr+1; subplot(8,2,obr); 
  plot (n,this0,n,this1,n,this2,n,this3,n,this4); axis([0 150 -0.1 0.1]);
  y = y + this0 + this1+ this2+ this3+ this4; 
  obr = obr+1; subplot(8,2,obr); plot (y); %pause 
  yy = repmat (y,1,50); %plot (yy) 
  wavwrite(yy,16000,['yytill' num2str(k) '.wav']);
end
print -depsc FIG/recpo5ti.eps

  