Selaa lähdekoodia

meukmeukmeuk

master
Wouter Horlings 8 vuotta sitten
vanhempi
commit
99e8b0338f
11 muutettua tiedostoa jossa 58 lisäystä ja 5 poistoa
  1. BIN
      OOequipment/Bodeplot.mlx
  2. BIN
      OOequipment/RC_TransferFunction.mlx
  3. BIN
      OOequipment/RLC_TransferFunction.mlx
  4. BIN
      OOequipment/Waveform.mlx
  5. +24
    -0
      OOequipment/subfiles/Bodeplot_script.m
  6. +15
    -0
      OOequipment/subfiles/Oscilloscope.m
  7. +1
    -1
      OOequipment/subfiles/RC_TransferFunction_script.m
  8. +1
    -1
      OOequipment/subfiles/RLC_TransferFunction_script.m
  9. +6
    -0
      OOequipment/subfiles/Waveform_script.m
  10. +1
    -1
      OOequipment/subfiles/phamag.m
  11. +10
    -2
      OOequipment/subfiles/transferFunction.m

BIN
OOequipment/Bodeplot.mlx Näytä tiedosto


BIN
OOequipment/RC_TransferFunction.mlx Näytä tiedosto


BIN
OOequipment/RLC_TransferFunction.mlx Näytä tiedosto


BIN
OOequipment/Waveform.mlx Näytä tiedosto


+ 24
- 0
OOequipment/subfiles/Bodeplot_script.m Näytä tiedosto

@@ -0,0 +1,24 @@
tic
data = transferFunction(oscilloscope,functiongenerator,f_start,f_stop,amplitude,n_steps);
toc
figure
ax(1)=subplot(2,1,1);
semilogx(data.frequency,20*log10(data.magnitude));
legend('Magnitude')
ylabel('Magnitude [dB]')
xlabel('Frequency [Hz]')
ax(2)=subplot(2,1,2);
semilogx(data.frequency,data.phase);
legend('Phase')
ylabel('Phase [rad]')
xlabel('Frequency [Hz]')
linkaxes(ax,'x')
arrayfun(@(x) set(x,{'TickLabelInterpreter','XGrid','YGrid','fontsize'},{'latex','on','on',12}),ax)
%%limit in quarter pi
yscale = 4;
ymax = 4;
ymin = -4;
ystep = 1;
numberticks = (ymin:ystep:ymax)*(pi/yscale);
latexticks = {'$-\pi$','$-\frac{3}{4}\pi$','$-\frac{1}{2}\pi$','$-\frac{1}{4}\pi$','$0$','$\frac{1}{4}\pi$','$\frac{1}{2}\pi$','$\frac{3}{4}\pi$','$\pi$'};
set(ax(2), {'YLim','YTick','YTickLabel'},{[-pi,pi],numberticks,latexticks});

+ 15
- 0
OOequipment/subfiles/Oscilloscope.m Näytä tiedosto

@@ -26,6 +26,12 @@ classdef Oscilloscope < Equipment
end
end
function clear(sc)
sc.messageclose;
sc.write_unsafe('*cls');
flushinput(sc.tcp);
end
function s = get.acquisition(sc)
s = sc.query('ACQ:STAT?');
end
@@ -120,6 +126,15 @@ classdef Oscilloscope < Equipment
data.length = wave.length;
end
function message(sc,msg)
sc.messageclose;
sc.write(['DISP:DIAL:MESS ''',msg,''''])
end
function messageclose(sc)
sc.write('DISP:DIAL:CLOS');
end
% function data = waveform(ch,cha)
% ch.scope.clear;


+ 1
- 1
OOequipment/subfiles/RC_TransferFunction_script.m Näytä tiedosto

@@ -22,7 +22,7 @@ linkaxes([ax1,ax2],'x')

%% Run the measurements
if theory_only == false
data = transferFunction(oscilloscope,functiongenerator,f_start,f_stop,amplitude,n_steps,n_measurements);
data = transferFunction(oscilloscope,functiongenerator,f_start,f_stop,amplitude,n_steps,n_measurements,'samp');
%% Plotting
%% Process the data
A_mean = mean(data.magnitude,1);


+ 1
- 1
OOequipment/subfiles/RLC_TransferFunction_script.m Näytä tiedosto

@@ -22,7 +22,7 @@ linkaxes([ax1,ax2],'x')

%% Run the measurements
if theory_only == false
data = transferFunction(oscilloscope,functiongenerator,f_start,f_stop,amplitude,n_steps,n_measurements);
data = transferFunction(oscilloscope,functiongenerator,f_start,f_stop,amplitude,n_steps,n_measurements,'samp');
%% Plotting
%% Process the data
A_mean = mean(data.magnitude,1);


+ 6
- 0
OOequipment/subfiles/Waveform_script.m Näytä tiedosto

@@ -0,0 +1,6 @@
oscilloscope.run;
functiongenerator.frequency = frequency;
functiongenerator.voltage = amplitude;
oscilloscope.auto;
wave = oscilloscope.waveform;


+ 1
- 1
OOequipment/subfiles/phamag.m Näytä tiedosto

@@ -7,7 +7,7 @@ Fs = 1/T;
n = 2^nextpow2(length);
X = fft(wave,n,2)/n;
idx = ceil(frequency*n/Fs);
phase = mod(angle(mean(X(2,idx)))-angle(mean(X(1,idx))),pi);
phase = mod(angle(mean(X(2,idx)))-angle(mean(X(1,idx)))+pi,2*pi)-pi;
magnitude = abs(X(2,idx))/abs(X(1,idx));
end


+ 10
- 2
OOequipment/subfiles/transferFunction.m Näytä tiedosto

@@ -1,6 +1,12 @@
function data = transferFunction(oscilloscope,functiongenerator,f_start,f_stop,amplitude,n_steps,n_measurements)
function data = transferFunction(oscilloscope,functiongenerator,f_start,f_stop,amplitude,n_steps,n_measurements,type)
%TRANSFERFUNCTION Summary of this function goes here
% Detailed explanation goes here
if nargin < 8
type = 'HRES';
if nargin < 7
n_measurements = 1;
end
end

f_array = 10.^linspace(log10(f_start),log10(f_stop),n_steps);
functiongenerator.voltage = amplitude;
@@ -13,12 +19,14 @@ function data = transferFunction(oscilloscope,functiongenerator,f_start,f_stop,a
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.message(['Run: ' num2str(j) '/' num2str(n_measurements) ' - Step: ' num2str(i) '/' num2str(n_steps)])
oscilloscope.run;
oscilloscope.auto;
wavedata = oscilloscope.waveform(1:2,'DEF','SAMP');
wavedata = oscilloscope.waveform(1:2,'DEF',type);
[data.phase(j,i),data.magnitude(j,i)] = phamag(wavedata.ch1,wavedata.ch2,wavedata.length,f_array(i),wavedata.sampletime);
end
end
oscilloscope.message('Measurement Finished!');
%bodePlot(data.magnitude,data.phase,data.frequency)
end


Loading…
Peruuta
Tallenna