%%%%%%%%%%%%%% Data Loading and Some Array Operations %%%%%%%%%%%%%%
AArr = myData.Trace_3_GetMeasurement_Pk_Pk_1__V;
BArr = myData.Trace_3_GetMeasurement_Pk_Pk_2__V;
omega = myData.Trace_2_SweepChannel1_Frequency_Hz*2*pi;
angleHw = myData.Trace_3_GetMeasurement_Phase_2_1_;
%%%%%%%%%%%%%%%%%%%%%%% Obtaining Asked Values %%%%%%%%%%%%%%%%%%%%%%%
[wCResponse cutoffIdx] = findClosest(absHw, max(absHw)/sqrt(2)); %find closest point
immersiveFinder(omega, absHw, wC/5)
immersiveFinder(omega, absHw, wC)
immersiveFinder(omega, absHw, wC*5)
immersiveFinder(omega, angleHw, wC/5)
immersiveFinder(omega, angleHw, wC)
immersiveFinder(omega, angleHw, wC*5)
%%%%%%%%%%%%%%%%%%%%%%%%%% Plotting Graphs %%%%%%%%%%%%%%%%%%%%%%%%%%
plot(wC, wCResponse,'r.','MarkerSize',20)
legend('Experimental Response Curve', 'Experimental \omega_c', 'Theoratical Response Curve', 'Theoratical \omega_c')
plot(wC, angleHw(cutoffIdx),'r.','MarkerSize',20)
legend('Experimental Response Curve', 'Experimental \omega_c', 'Theoratical Response Curve', 'Theoratical \omega_c')
saveas(gcf,'1b.emf') % Save the graph to the local drive
%%%%%%%%%%%%%% Data Loading and Some Array Operations %%%%%%%%%%%%%%
AArr = myData.Trace_3_GetMeasurement_Pk_Pk_1__V;
BArr = myData.Trace_3_GetMeasurement_Pk_Pk_2__V;
omega = myData.Trace_2_SweepChannel1_Frequency_Hz*2*pi;
angleHw = myData.Trace_3_GetMeasurement_Phase_2_1_;
%%%%%%%%%%%%%%%%%%%%%%% Obtaining Asked Values %%%%%%%%%%%%%%%%%%%%%%%
[wCResponse cutoffIdx] = findClosest(absHw, max(absHw)/sqrt(2)); %find closest point
immersiveFinder(omega, absHw, wC/5)
immersiveFinder(omega, absHw, wC)
immersiveFinder(omega, absHw, wC*5)
immersiveFinder(omega, angleHw, wC/5)
immersiveFinder(omega, angleHw, wC)
immersiveFinder(omega, angleHw, wC*5)
%%%%%%%%%%%%%%%%%%%%%%%%%% Plotting Graphs %%%%%%%%%%%%%%%%%%%%%%%%%%
plot(wC, wCResponse,'r.','MarkerSize',20)
legend('Experimental Response Curve', 'Experimental \omega_c', 'Theoratical Response Curve', 'Theoratical \omega_c')
plot(wC, angleHw(cutoffIdx),'r.','MarkerSize',20)
legend('Experimental Response Curve', 'Experimental \omega_c', 'Theoratical Response Curve', 'Theoratical \omega_c')
saveas(gcf,'2a.emf') % Save the graph to the local drive
%%%%%%%%%%%%%% Data Loading and Some Array Operations %%%%%%%%%%%%%%
myData = load('2bi.mat');
AArr = myData.Trace_3_GetMeasurement_Pk_Pk_1__V;
BArr = myData.Trace_3_GetMeasurement_Pk_Pk_2__V;
omega = myData.Trace_2_SweepChannel1_Frequency_Hz*2*pi;
angleHw = myData.Trace_3_GetMeasurement_Phase_2_1_;
%%%%%%%%%%%%%%%%%%%%%%% Obtaining Asked Values %%%%%%%%%%%%%%%%%%%%%%%
[wC1 w0 wC2 wC1Idx w0Index wC2Idx wC1y w0Response wC2y qF]...
= handleBandpass(omega, absHw)
wC1 = 2.6389e+03
w0 = 8.4446e+03
wC2 = 3.1139e+04
wC1Idx = 5
w0Index = 16
wC2Idx = 59
wC1y = 0.6244
w0Response = 0.8788
wC2y = 0.6219
qF = 0.2963
wc1Phase = immersiveFinder(omega, angleHw, wC1)
w0Phase = immersiveFinder(omega, angleHw, w0)
wc2Phase = immersiveFinder(omega, angleHw, wC2)
%%%%%%%%%%%%%%%%%%%%%%%%%% Plotting Graphs %%%%%%%%%%%%%%%%%%%%%%%%%%
%subplot(2,1,1); % when it is activated, legend blocks the graph. Even if I
% tried to overcome this with my handcrafted function wideSP(), it caused
% more problems: the "hold on" seems ineffective with this approach. So I
plot(w0, w0Response,'r.','MarkerSize',20)
plot(wC1, wC1y,'rx','MarkerSize',10)
plot(wC2, wC2y,'r*','MarkerSize',10)
legend('Experimental Response Curve', 'Experimental \omega_0', 'Experimental \omega_{c1}', 'Experimental \omega_{c2}',...
'Theoratical Response Curve', 'Theoratical \omega_0', 'Theoratical \omega_{c1}', 'Theoratical \omega_{c2}')
saveas(gcf,'2b-i-magnitude.emf') % Save the graph to the local drive % Save the graph to the local drive
plot(w0, angleHw(w0Index),'r.','MarkerSize',20)
plot(wC1, angleHw(wC1Idx),'rx','MarkerSize',10)
plot(wC2, angleHw(wC2Idx),'r*','MarkerSize',10)
legend('Experimental Response Curve', 'Experimental \omega_0', 'Experimental \omega_{c1}', 'Experimental \omega_{c2}',...
'Theoratical Response Curve', 'Theoratical \omega_0', 'Theoratical \omega_{c1}', 'Theoratical \omega_{c2}')
saveas(gcf,'2b-i-phase.emf') % Save the graph to the local drive % Save the graph to the local drive
%%%%%%%%%%%%%% Data Loading and Some Array Operations %%%%%%%%%%%%%%
AArr = myData.Trace_3_GetMeasurement_Pk_Pk_1__V;
BArr = myData.Trace_3_GetMeasurement_Pk_Pk_2__V;
omega = myData.Trace_2_SweepChannel1_Frequency_Hz*2*pi;
angleHw = myData.Trace_3_GetMeasurement_Phase_2_1_;
%%%%%%%%%%%%%%%%%%%%%%% Obtaining Asked Values %%%%%%%%%%%%%%%%%%%%%%%
[wC1 w0 wC2 wC1Idx w0Index wC2Idx wC1y w0Response wC2y qF]...
= handleBandpass(omega, absHw)
wC1 = 8.6708e+03
w0 = 9.2991e+03
wC2 = 1.0556e+04
wC1Idx = 23
w0Index = 25
wC2Idx = 29
wC1y = 0.3950
w0Response = 0.5920
wC2y = 0.4179
qF = 4.9333
wc1Phase = immersiveFinder(omega, angleHw, wC1)
w0Phase = immersiveFinder(omega, angleHw, w0)
wc2Phase = immersiveFinder(omega, angleHw, wC2)
%%%%%%%%%%%%%%%%%%%%%%%%%% Plotting Graphs %%%%%%%%%%%%%%%%%%%%%%%%%%
plot(w0, w0Response,'r.','MarkerSize',20)
plot(wC1, wC1y,'rx','MarkerSize',10)
plot(wC2, wC2y,'r*','MarkerSize',10)
legend('Experimental Response Curve', 'Experimental \omega_0', 'Experimental \omega_{c1}', 'Experimental \omega_{c2}',...
'Theoratical Response Curve', 'Theoratical \omega_0', 'Theoratical \omega_{c1}', 'Theoratical \omega_{c2}')
saveas(gcf,'3a-magnitude.emf') % Save the graph to the local drive % Save the graph to the local drive
plot(w0, angleHw(w0Index),'r.','MarkerSize',20)
plot(wC1, angleHw(wC1Idx),'rx','MarkerSize',10)
plot(wC2, angleHw(wC2Idx),'r*','MarkerSize',10)
legend('Experimental Response Curve', 'Experimental \omega_0', 'Experimental \omega_{c1}', 'Experimental \omega_{c2}',...
'Theoratical Response Curve', 'Theoratical \omega_0', 'Theoratical \omega_{c1}', 'Theoratical \omega_{c2}')
saveas(gcf,'3a-phase.emf') % Save the graph to the local drive % Save the graph to the local drive
function [wC1 w0 wC2 wC1Idx w0Idx wC2Idx wC1y w0y wC2y qF] = handleBandpass(xArray, yArray)
% handle values about resonant frequency
[w0y w0Idx] = max(yArray);
%slice arrays from peak point
xLeft = xArray(1:w0Idx-1);
xRight = xArray(w0Idx+1:end);
yLeft = yArray(1:w0Idx-1);
yRight = yArray(w0Idx+1:end);
% handle values about first cutoff frequency
[wC1y wC1Idx] = findClosest(yLeft, w0y/sqrt(2)); %find closest point
% handle values about second cutoff frequency
[wC2y wC2Idx] = findClosest(yRight, w0y/sqrt(2)); %find closest point
% due to silicing, right indices are defective, fix it here:
wC2Idx = wC2Idx + 1 + length(xLeft);
function plotPre1(mode, omg, omgc, H)
plot(omg,abs(H(omg)),'k--');
plot(omgc, 1/sqrt(2),'g.','MarkerSize',20);
xlabel('\omega (rad/s)'); ylabel('|H(j\omega)|');
title("Magnitude Response")
plot(omg, rad2deg(angle(H(omg))),'k--');
plot(omgc, rad2deg(angle(H(omgc))),'g.','MarkerSize',20);
xlabel('\omega (rad/s)');
ylabel('\angle H(j\omega) (\circ)');
function plotPre2(mode, omg, H)
[wC1 w0 wC2 wC1Idx w0Idx wC2Idx wC1y w0y wC2y qF] = handleBandpass(omg, abs(H(omg)));
plot(omg,abs(H(omg)),'k--');
plot(w0, w0y,'g.','MarkerSize',20)
plot(wC1, wC1y,'gx','MarkerSize',10)
plot(wC2, wC2y,'g*','MarkerSize',10)
xlabel('\omega (rad/s)'); ylabel('|H(j\omega)|');
title("Magnitude Response")
angleHw = rad2deg(angle(H(omg)));
plot(omg, angleHw,'k--');
plot(w0, angleHw(w0Idx),'g.','MarkerSize',20)
plot(wC1, angleHw(wC1Idx),'gx','MarkerSize',10)
plot(wC2, angleHw(wC2Idx),'g*','MarkerSize',10)
xlabel('\omega (rad/s)');
ylabel('\angle H(j\omega) (\circ)');