% %% % Sample and hold: esempio % clear all, close all, clc %% Problema Vm1=20; % Voltage magnitude for v1 Vm2=10; % Voltage magnitude for v2 DOB=27; % Random parameter #1 MOB=11; % Random parameter #2 f1=MOB*10; % Frequency for v1 f2=DOB*10; % Frequency for v2 w1=2*pi*f1; % Frequency for v1 (rad/sec) w2=2*pi*f2; % Frequency for v2 (rad/sec) %0.04; % Simulation time t=0:0.00005:0.04; % Time for plotting signal v1=Vm1*sin(w1*t); % v1 v2=Vm2*sin(w2*t); % v2 v=v1+v2; % Combination figure, subplot(211), plot(t,v,'r') xlabel('Tempo (s)'), ylabel('v(t)') title('Segnale da campionare') %% Defining sampling periods fm=max(f1,f2); % Maximum frequency component fs1=2*fm; Ts1=1/fs1; % Just same fs2=3*fm; Ts2=1/fs2; % fs>2fm (satisfying sampling theorem) fs3=1*fm; Ts3=1/fs3; % fs<2fm (not satisfying sampling theorem) %% fs>2fm (satisfying sampling theorem) ts2=0:Ts2:0.04; v1s2=Vm1*sin(w1*ts2); v2s2=Vm2*sin(w2*ts2); vs2=v1s2+v2s2; subplot(212), stem(ts2,vs2,':') xlabel('Tempo (s)'), ylabel('v(k)') title('Segnale campionato') %% Segnali sovrapposti figure, plot(t,v,'r'), hold on stem(ts2,vs2,':b') xlabel('Tempo (s)'), ylabel('v(t) e v_k') title('Segnale da campionare v(t) e campioni v_k') legend('Segnale da campionare','campioni') %% Comparison of signals (by plotting zoh type signals) figure subplot(211), stem(ts2,vs2,':') xlabel('Tempo (s)'), ylabel('v(k)') title('Segnale campionato') subplot(212), stem(ts2,vs2,':'), hold on stairs(ts2,vs2,'r') xlabel('Tempo (s)'), ylabel('v_r(t)') title('Segnale in uscita da ZOH') legend('Campioni','Segnale da ZOH')