% %% % 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','LineWidth',2.5) grid on ax = gca; ax.XAxis.FontSize = 18; % numeri asse x più grandi ax.YAxis.FontSize = 18; % numeri asse y xlabel('Tempo (s)','FontSize',18) ylabel('v(t)','FontSize',18) title('Segnale da campionare','FontSize',18) %% 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,':','LineWidth',2.5) grid on ax = gca; ax.XAxis.FontSize = 18; ax.YAxis.FontSize = 18; xlabel('Tempo (s)','FontSize',18) ylabel('v(k)','FontSize',18) title('Segnale campionato','FontSize',18) %% Segnali sovrapposti figure, plot(t,v,'r','LineWidth',2.5), hold on grid on ax = gca; ax.XAxis.FontSize = 18; ax.YAxis.FontSize = 18; stem(ts2,vs2,':b','LineWidth',2.5) grid on ax = gca; ax.XAxis.FontSize = 18; ax.YAxis.FontSize = 18; xlabel('Tempo (s)','FontSize',18) ylabel('v(t) e v_k','FontSize',18) title('Segnale da campionare v(t) e campioni v_k','FontSize',18) legend('Segnale da campionare','campioni','FontSize',18) %% Comparison of signals (by plotting zoh type signals) figure subplot(211), stem(ts2,vs2,':','LineWidth',2.5) grid on ax = gca; ax.XAxis.FontSize = 18; ax.YAxis.FontSize = 18; xlabel('Tempo (s)','FontSize',18) ylabel('v(k)','FontSize',18) title('Segnale campionato','FontSize',18) subplot(212), stem(ts2,vs2,':','LineWidth',2.5), hold on grid on ax = gca; ax.XAxis.FontSize = 18; ax.YAxis.FontSize = 18; stairs(ts2,vs2,'r','LineWidth',2.5) grid on ax = gca; ax.XAxis.FontSize = 18; ax.YAxis.FontSize = 18; xlabel('Tempo (s)','FontSize',18) ylabel('v_r(t)','FontSize',18) title('Segnale in uscita da ZOH','FontSize',18) legend('Campioni','Segnale da ZOH','FontSize',18) return