function sampleAndPlot(sampleFreq)
%Cleanup
global figHandle
global AI

% Init
if nargin < 1
    sampleFreq = 48e3;
end
if isempty(AI)
    AI = analoginput('nidaq','Dev1');
    addchannel(AI,0);
    set(AI,'samplespertrigger',sampleFreq);
    set(AI,'samplerate',sampleFreq);
else 
    set(AI,'samplespertrigger',sampleFreq);
    set(AI,'samplerate',sampleFreq);
end


% Sample
start(AI);
wait(AI,2);
data=getdata(AI);

% Calc

% Fourier transform
xdata1 = ((1:length(data))-length(data)/2)/length(data)*sampleFreq-1;
theFFT=fftshift((fft(data-mean(data))));
theAngles=angle(theFFT);
theFFT = abs(theFFT);
theFFT=theFFT/max(theFFT);
ydata1 = theFFT;


% Plot
if isempty(figHandle)
    figHandle = figure();
else
    figure(figHandle)
end
% Plot Fourier transform
subplot(2,1,1)
h2 = plot(xdata1,ydata1);
title('Fourier transform')
grid on;
axis([0 200 0 1]);
xlabel('f [Hz]')
ylabel('FFT Relative ampliude [-]') 

% Plot raw-data
subplot(2,1,2)
h3 = plot(((1:length(data))-1)/sampleFreq,data);
xlabel('Time [s]')
ylabel('Electrical potential [V]')
title('Raw data in Volts')
grid on;


