function data = transferFunction(oscilloscope,functiongenerator,f_start,f_stop,amplitude,n_steps,n_measurements)
%TRANSFERFUNCTION Summary of this function goes here
%   Detailed explanation goes here

    f_array = 10.^linspace(log10(f_start),log10(f_stop),n_steps);
    functiongenerator.voltage = amplitude;
    functiongenerator.waveform = 'SINUSOID';
    oscilloscope.enable_channels;
    oscilloscope.trigger.source = 'CH1';
    emptydata = zeros(n_measurements,n_steps);
    data = struct('magnitude',emptydata,'phase',emptydata,'frequency',f_array);
    for j = 1:n_measurements
        for i = 1:n_steps
%             fprintf('Measurement %i of %i - Frequency: %.2f Hertz\n',i,n_steps,f_array(i));
            functiongenerator.frequency = f_array(i);
            oscilloscope.auto;
            wavedata = oscilloscope.waveform(1:2,'DEF','SAMP');
            [data.phase(j,i),data.magnitude(j,i)] = phamag(wavedata.ch1,wavedata.ch2,wavedata.length,f_array(i),wavedata.sampletime);
        end
    end
    %bodePlot(data.magnitude,data.phase,data.frequency)
end

