Created
May 20, 2018 15:59
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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