Skip to content

Instantly share code, notes, and snippets.

@bencholmes
Created May 20, 2018 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bencholmes/19c0edaab1499162be45d9c274cee8e4 to your computer and use it in GitHub Desktop.
Save bencholmes/19c0edaab1499162be45d9c274cee8e4 to your computer and use it in GitHub Desktop.
Returns the FFT of a voltage signal (in volts) with the amplitude response units dBV.
function [Xmag, Xarg] = fftdBV(x)
%FFTDBV Returns the FFT of a voltage signal (in volts) with the amplitude response units dBV.
% Number of samples
N = length(x);
% Scaling factor is sqrt(2) except for at DC when it is 1.
k = [1, ones(1,N-1)*sqrt(2)];
% Calculate the scaled DFT.
X = fft(x)./N;
% Amplitude response must be scaled by RMS to peak ratio.
Xmag = 20*log10(k.*abs(X));
% Find the unwrapped phase of the fft.
Xarg = unwrap(angle(X));
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment