Difference between revisions of "Spring 2012:Leanna Morinishi Lab 1"

From Course Wiki
Jump to: navigation, search
(Code)
(Code)
Line 18: Line 18:
 
If you measured DNA tethers, provide estimates of the persistence and contour lengths. (This will require a calibration with .97 micron polystyrene microspheres.) If you haven't done much curve fitting or you would like some help understanding the theory, stop by during lab open hours and Prof. Nagle or I will get you pointed in the right direction.
 
If you measured DNA tethers, provide estimates of the persistence and contour lengths. (This will require a calibration with .97 micron polystyrene microspheres.) If you haven't done much curve fitting or you would like some help understanding the theory, stop by during lab open hours and Prof. Nagle or I will get you pointed in the right direction.
  
function pushbuttonDNATetherCenter_Callback(hObject, eventdata, handles)
+
<nowiki>function pushbuttonDNATetherCenter_Callback(hObject, eventdata, handles)
% hObject    handle to pushbuttonDNATetherCenter (see GCBO)
+
% eventdata  reserved - to be defined in a future version of MATLAB
+
% handles    structure with handles and user data (see GUIDATA)
+
 
     dnaTetherCentering(handles, uiSettings)
 
     dnaTetherCentering(handles, uiSettings)
  
Line 121: Line 118:
 
             accuracy = accuracy +1;
 
             accuracy = accuracy +1;
 
             ycenter = false;
 
             ycenter = false;
         end
+
         end</nowiki>

Revision as of 03:31, 28 February 2012

Lab 1: Optical Trapping

What I wanted to accomplish

  • Complete a button that takes in data from a tethered microbead and adjusts the stage position to center it on the tether
    • Try to get nicer calibration data
    • Function that finds the center
    • Feed in recorded data in a simulation
  • Look at the properties of the tether, to calculate the persistence and contour lengths

How I did it

  • Typing?

Code

If you measured DNA tethers, provide estimates of the persistence and contour lengths. (This will require a calibration with .97 micron polystyrene microspheres.) If you haven't done much curve fitting or you would like some help understanding the theory, stop by during lab open hours and Prof. Nagle or I will get you pointed in the right direction.

function pushbuttonDNATetherCenter_Callback(hObject, eventdata, handles)
    dnaTetherCentering(handles, uiSettings)

function DNATetherCentering(handles, uiSettings)
    accuracy = 1;
    accuracyY = 1;
    setParams = false;
    xcenter = false;
    ycenter = false;
    while accuracy < 4;
        if ~setParams
            xaxisPiezoDriver = handles.PiezoDriverDescriptorList{1};
            yaxisPiezoDriver = handles.PiezoDriverDescriptorList{2};
            handles.SamplesToSave = uiSettings.numberofSeconds*uiSettings.sampleRate;

            Amplitude = uiSettings.stageOscillationAmplitude;
            waveformFreq = round(uiSettings.sampleRate / uiSettings.stageOscillationFrequency);
            time = linspace(0:length(numberOfSamples)-1,numberOfSamples);
            centeringcycle = Amplitude*sin(2*pi*waveformFreq * time)';
            waveform = [centeringcycle zeros(length(centeringcycle),1)]; 
            numberOfSamples = sampleRate * duration; %set sampleRate and duration;

            set(handles.DaqInput.ObjectHandle,'SampleRate',400);
            set(handles.DaqInput.ObjectHandle,'Trigger','Manual');
            set(handles.DaqInput.ObjectHandle,'SamplesPerTrigger',numberOfSamples);

            set(handles.DaqOutput.ObjectHandle,'Trigger','Manual');
            set(handles.DaqOutput.ObjectHandle,'RepeatOutput',3);
    % 
            setParams = true;
        end
        start(handles.DaqInput.ObjectHandle);
        data = getdata(handles.DaqInputHandle);
        Trigger(handles.DaqInput.Output.ObjectHandle);
        putdata(handles.DaqOutput.ObjectHandle,waveform);
        start(handles.DaqOutput.ObjectHandle);
        Trigger(handles.DaqOutput.ObjectHandle);
        waveform = findCenter(data, xcenter, ycenter, waveform);
        stop(handles.DaqInput.ObjectHandle);
        stop(handles.DaqOutput.ObjectHandle);
    end
        
        
    function waveform = findCenter(data, xcenter, ycenter, waveform)

        [quantizedXAxisx BinnedDatax StandardDeviationx Countx] = BinData( ...
         data, 'XColumn', 3, 'YColumn', 1);
        [quantizedXAxisy BinnedDatay StandardDeviationy County] = BinData( ...
         data, 'XColumn', 4, 'YColumn', 2);
        data = [BinnedDatax' BinnedDatay' quantizedXAxisx' quantizedXAxisy']; % qpdx qpdy piezx piezy

        centeredPosition = (positionOfMaxVoltage + positionOfMinVoltage)/2;
        fprintf('The position of the stage is %d',centeredPosition);

        if ~xcenter && ~ycenter
            [MaxValue MaxVoltageIndex] = max(data(:,1));
            positionOfMaxVoltage = centeringcycle(MaxVoltageIndex(1));
            [MinValue MinVoltageIndex] = min(data(:,1));
            positionOfMinVoltage = centeringcycle(MinVoltageIndex(1));
            centeredPosition = (positionOfMaxVoltage + positionOfMinVoltage)/2;
            invoke(handles.PiezoDriverDescriptorList{1}.DriverActiveXControl,...
             'SetPosOutput', 0, centeredPosition);
            xcenter = true;
            waveform = [zeros(length(centeringcycle),1) centeringcycle ]; 

        elseif xcenter && ~ycenter
            [MaxValue MaxVoltageIndex] = max(data(:,2));
            positionOfMaxVoltage = centeringcycle(MaxVoltageIndex(1));
            [MinValue MinVoltageIndex] = min(data(:,2));
            positionOfMinVoltage = centeringcycle(MinVoltageIndex(1));
            centeredPosition = (positionOfMaxVoltage + positionOfMinVoltage)/2;
            invoke(handles.PiezoDriverDescriptorList{2}.DriverActiveXControl,...
             'SetPosOutput', 0, centeredPosition);
            fprintf('The position of the stage is %d',centeredPosition);
            waveform = [ centeringcycle zeros(length(centeringcycle),1)]; 
            if accuracyY == 4;
               centeredPosition = mean(CheckaccuracyYposition);
               invoke(handles.PiezoDriverDescriptorList{2}.DriverActiveXControl,...
                'SetPosOutput', 0, centeredPosition);
            end
            CheckaccuracyYposition(accuracyY) = centeredPosition;
            accuracyY = accuracyY + 1;
            ycenter = true;

        elseif xcenter && ycenter 
            [MaxValue MaxVoltageIndex] = max(data(:,1));
            positionOfMaxVoltage = centeringcycle(MaxVoltageIndex(1));
            [MinValue MinVoltageIndex] = min(data(:,1));
            positionOfMinVoltage = centeringcycle(MinVoltageIndex(1));
            centeredPosition = (positionOfMaxVoltage + positionOfMinVoltage)/2;
            CheckaccuracyXposition(accuracy) = centeredPosition;
            waveform = [ centeringcycle zeros(length(centeringcycle),1)];
            % center to mean value of all checkaccuracyXposition
            if accuracy == 4;
               centeredPosition = mean(CheckaccuracyXposition);
               invoke(handles.PiezoDriverDescriptorList{1}.DriverActiveXControl,...
                'SetPosOutput', 0, centeredPosition);
            end
            accuracy = accuracy +1;
            ycenter = false;
        end