FFT of Large CSV File - Fundamental doesn't match data or simple sine test case
Afficher commentaires plus anciens
I'm trying to take the FFT of a very large .csv file from and oscilloscope, but the results do not correlate to what the oscilloscope says, nor a sample test case (included in the below script). I've checked my FFT script against several online examples and it seems to be correct. Any help is appreciated.
SampleInt = 0.00000004; % interval at which scope samples
ScopeFreq = 16.667; %[Hz] Reading from O-scope
% Spreadsheet Info:
spreadsheetname = 'tek0001ALL.csv'; %If it's in the current directory... need to conver to .xlsx file.
%Define Variables for Matlab
ScopeTime = csvread(spreadsheetname,475298,0,[475298,0,1974610,0]);
disp('Scope Time Imported, Script Line 23')
Va = csvread(spreadsheetname,475298,1,[475298,1,1974610,1]);
disp('Scope Va Imported, Script Line 25')
disp('Excel Importing Done!!!')
%Define Time Domain Series for Plotting
timelength = 0:1:(length(Va)-1);
Time = timelength.*SampleInt;
%Calc' the RMS value of Va
Va_RMS =rms(Va)
Max = max(Va)
% Do the FFT!!
L=length(Va)
Dt = SampleInt; % Get the sampling rate
Fs = 1/Dt;
NFFT = 2^nextpow2(L); % automaticlaly figures out what n is for 2^n
X=fft(Va,NFFT/2);
mx = abs(X);
f = (0:NFFT/2-1)*Fs/NFFT;
%Plot just the FFT
figure(1)
stem(f,mx)
title('FFT of Raw Test Data')
xlabel('Freq. [Hz]')
xlim([0,200])
%Now plot Va against a sinewave to check fundamental from FFT
Vv=Max*sin(2*pi*16.8*Time);
figure(2)
plot(Time,Va,Time,Vv)
xlabel('Time [Sec]')
grid on
% Now Check the FFT function using the reference sinewave
Lv=length(Vv)
Dtv = SampleInt; % Get the sampling rate
Fsv = 1/Dtv;
NFFTv = 2^nextpow2(Lv); % automaticlaly figures out what n is for 2^n
Xv=fft(Vv,NFFTv/2);
mxv = abs(Xv);
fv = (0:NFFTv/2-1)*Fsv/NFFTv;
figure(3)
stem(fv,mxv)
title('FFT of Raw Test Data')
xlabel('Freq. [Hz]')
xlim([0,200])
Note that when I run this script the FFT produced a fundamental frequency of ~ 12Hz, but that the fundamental is actually 16.67Hz.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Spectral Measurements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!