40m QIL Cryo_Lab CTN SUS_Lab TCS_Lab OMC_Lab CRIME_Lab FEA ENG_Labs OptContFac Mariner WBEEShop
  40m Log  Not logged in ELOG logo
Message ID: 359     Entry time: Wed Mar 5 12:35:09 2008
Author: John 
Type: Summary 
Category: Computer Scripts / Programs 
Subject: Plot photodiode responses in MatLab 
A matlab function to plot the responses of photodiodes. There's still plenty of room for improvement but it should work for all our diodes without any changes. You may want to adjust which points are used in the fit to remove time delay.




% Plot data from diode response measurements
function out = diodeplot(f_Hz,mag_dB,phase_deg,f_beat_MHz)

% $$$ clear all
% $$$ close all
% $$$ clc
% $$$
% $$$
% $$$ mag = dlmread('D:\40m\PD6\M7.txt','\t', 15, 0);
% $$$ phase = dlmread('D:\40m\PD6\P7.txt','\t', 15, 0);
% $$$
% $$$ % Frequency i.e. x-axis
% $$$ f = mag(:,1);
% $$$
% $$$ % Magnitude in dB
% $$$ mag_dB = mag(:,2);
% $$$
% $$$ % Phase in degrees
% $$$ phase_deg = phase(:,2);
% $$$
% $$$ % Frequencies of interest
% $$$ f_beat_MHz = [33 133 166 199]*1e6;
% $$$
% $$$ diodeplot(f, mag_dB, phase_deg, f_beat_MHz)

% x axis limits
xmin = 10e6;
xmax = 500e6;

% Unwrap phase
phase_deg = (180/pi)*unwrap((pi/180)*phase_deg);

%Find values at our freqeuncies of interest
Mag_f_beat = interp1(f_Hz,mag_dB,f_beat_MHz);

% Remove the time delay from the phase data
% (May want to adjust which points are selected here)

straight = @(a, x) a(1) * x + a(2);

xdata = f_Hz;
ydata = phase_deg;

aguess = [10 0.1];
a = lsqcurvefit(straight,aguess,xdata,ydata);
fit = straight(a,xdata);

phase_deg = phase_deg-fit;

figure(1)
ha = axes('units','normalized','position',[0 0 1 1]);
uistack(ha,'bottom');
I=imread('PDbw.jpg');
hi = imagesc(I);
colormap gray
set(ha,'handlevisibility','off', ...
'visible','off')
plot(xdata,ydata,'r')
hold on
plot(xdata,fit,'k')
plot(xdata,phase_deg,'b')
hold off
ylabel('Phase/ degrees', 'FontSize',12)
xlabel('Frequency/ Hz', 'FontSize',12)
title('Removing the time delay','FontSize',16)
legend('data','fit','data-fit',0)
set(hi,'alphadata',.35)
set(gca,'Color','None')
box off




figure(2)
set(gcf,'Color', [1 1 1])
subplot(4,1,[1 3])

semilogx(f_Hz,mag_dB,'k','LineWidth',2.5)
title('Response of PD6','FontSize',16)
ylabel('Magnitude/ dB', 'FontSize',12)
xlim([xmin xmax])
grid

MagLayout = get(gca, 'Position');
YLimits = get(gca, 'YLim') ;
LabelExt = [];

for ivar = 1:length(f_beat_MHz);

a = text(f_beat_MHz(ivar),1.05 * min(Mag_f_beat),...
sprintf('%2.1fdB @ %dMHz', Mag_f_beat(ivar),f_beat_MHz(ivar)/1e6),...
'FontSize',10,'FontWeight','Bold','HorizontalAlignment','right',...
'VerticalAlignment','top','BackgroundColor',[.7 .9 .7],...
'Margin',0.5, 'Rotation',90);
LabelExt = [LabelExt; get(a,'Extent')];
LabelPos = get(a,'Position');

end

% Change YLim so that it is around the bottom of the labels
% There must be a better way
set(gca, 'YLim', [min(LabelExt(:,2)) YLimits(2)])

% Remove the last tick mark so that it doesn't overlap with the
% +180 of the phase plot
YTickLabelNew = str2num(get(gca, 'YTickLabel'));
YTickNew =[[] YTickLabelNew(2:end) ];
set(gca,'XTickLabel', [], 'YTick', YTickNew)

% Add lines now we know what the YLims are
for ivar = 1:length(f_beat_MHz);
line([f_beat_MHz(ivar) f_beat_MHz(ivar)], get(gca, 'YLim'))
end

subplot(4,1,4)
semilogx(f_Hz,phase_deg,'r','LineWidth',2.5)
xlim([xmin xmax])
ylabel('Phase/ degrees', 'FontSize',12)
xlabel('Frequency/ Hz', 'FontSize',16)
grid
PhaseLayout = get(gca, 'Position');
PhaseLayout(4) = MagLayout(2)-PhaseLayout(2);

% Make the top of the phase plot align to the bottom of the
% magnitude plot
set(gca, 'Color', 'None', 'Position',PhaseLayout, 'YTick',[-180:45: ...
180])
set(gcf,'units','normalized','outerposition',[0 0 1 1]);
Attachment 3: PDbw.jpg  25 kB  | Hide | Hide all
PDbw.jpg
ELOG V3.1.3-