function dft(signal,Fs,ref)
if~exist('ref','var')
SPL = false;
ref = 1;
else
SPL = true;    
end
s = fft(signal); %translate signal from time domain to frequency domain
N = length(s); %calculate the amount of samples of the signal
s_half = s(1:N/2); % only use half of the signal, because the other half is the same, but negative frequency
f = Fs*(0:(N/2)-1)/N; % change sample frequency to real frequency using samplerate
magn = abs(s_half/(N/2)); % magnitude of the signal
magn_dB = calculate_db(magn,ref.*ones(length(magn),1),SPL); % magnitude of signal in dB
p = plot(f,magn_dB); %plot the result
set(gca,'TickLabelInterpreter','latex')
set(gca,"FontSize",21)
ax=gca;
ax.XAxis.Exponent=3;
p.LineWidth = 1.5;
title('FFT Spectrum','Interpreter','latex')
xlabel('Frequency (Hz)','Interpreter','latex');
if (SPL == true)
ylabel('Magnitude dB(SPL)','Interpreter','latex');
else
ylabel('Magnitude (dBFS)','Interpreter','latex');
end
xlim([0 20E3])
xticks(0:1000:20000)
grid on
end
%Measuring directional characteristics of sound sources
%Made by Benjamin Nimmerrichter 2022/23 for BUT

