%% Ozan Erturk - 2022
% PMN-PT RF S11 plot with different Radii

clear; clc;
k=1; %indexing
for i=[20 30 40 50 60 75]
data_name=['Device_r_',num2str(i),'um.s1p'];
temp_data = sparameters(data_name);
data=squeeze(temp_data.Parameters);
freq=temp_data.Frequencies;
Y11dB=20*log10(abs((1-data)./(1+data)./50));
S11dB=20*log10(abs(data));
plot(1e-6*freq,S11dB,'Linewidth',1);hold on
xlabel('MHz'); ylabel('S_{11} dB')
%Due to extra resistive losses, the S11 curve for r=75um device has minimum
%at higher frequncies s.t. the data is sliced
    if i>70
        [value, index]= min(S11dB(1:0.1*length(S11dB)));
        dip_freq(k)=freq(index)*1e-6;
        dip_value(k)=value;
        k=k+1;
    elseif i<70
[value, index]= min(S11dB(1:0.5*length(S11dB)));
dip_freq(k)=freq(index)*1e-6;
dip_value(k)=value;
k=k+1;
    end
    
end
% title('Radius Variation')
% legend(names(i))
hold off
figure(1); hold on
xlabel('MHz'); ylabel('S_{11} dB')
axis([2 55 -5 0 ])
%Plot circles on experimental n=2 WGM dip 
plot(dip_freq(1),dip_value(1),'o','Color',[0 0.4470 0.7410],'LineWidth',3);
plot(dip_freq(2),dip_value(2),'o','Color',[0.8500 0.3250 0.0980],'LineWidth',3);
plot(dip_freq(3),dip_value(3),'o','Color',[0.9290 0.6940 0.1250],'LineWidth',3);
plot(dip_freq(4),dip_value(4),'o','Color',[0.4940 0.1840 0.5560],'LineWidth',3);
plot(dip_freq(5),dip_value(5),'o','Color',[0.4660 0.6740 0.1880],'LineWidth',3);
plot(dip_freq(6),dip_value(6),'o','Color',[0.3010 0.7450 0.9330],'LineWidth',3);
	
legend('r=20 \mum','r=30 \mum','r=40 \mum','r=50 \mum','r=60 \mum','r=75 \mum','Orientation','Horizontal','NumColumns',3,'Location','SouthEast')
grid on

%% Radius vs WG Analytical Experiemntal COMSOL
r=15:2:85;
f=461.21./r; %Analytical equation from "M. Abdelmoneum, “Stemless wine-glass-mode disk micromechanical resonators,” Proc. IEEE Micro Electro Mech. Syst., pp. 698–701, 2003, doi: 10.1109/memsys.2003.1189845."

r_list=[20 30 40 50 60 75 ];
wg_COMSOL=[25.45 16.81 12.53 9.98 8.31 6.96];

plot(r_list,dip_freq, 'sr','MarkerFaceColor','w','LineWidth',4); hold on
plot(r_list,wg_COMSOL, '*b','MarkerFaceColor','w','LineWidth',2); hold on
plot(r,f,'--k','LineWidth',2); grid on

xlabel('Radius [\mum]'); ylabel ('Resonance Frequency [MHz]');
legend ('Experimental','COMSOL','Analytical')


