Performing FFT from three different Excel input data
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi I have 3 different excel sheets i am reading data from and trying to perform FFT. the first colum in each file has time data, while the second colum has voltage data. I am able to perform FFT with one excel file, however i am stuck reading from three different files.
If anyone can help I would really apreciate it. I have attached test data files and code I am currently using here
%INITIALISATION
% % % % % % % % % % % % % % % % % % % % % % % % % % % %
Ts = 0.00005; % Sampling Interval (seconds)
Fs = 1/Ts; % Sampling Frequency (Hz)
Fn = Fs/2;
path = genpath('C:\Users\Power User\Desktop\');
x31 = csvread('test data1.csv',2); %read data
x32 = csvread('test data1.csv', 2);
x33 = csvread('test data1.csv', 2);
Details = (strsplit(path,'\')); %extract details for plot titles from path name
Details = char(Details(2));
Signal = {x31;x32;x33}; %Load all SC current signals into cell array
%PLOT TIME SERIES DATA
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure
plot(t, v); % plot time domain signal
grid
xlabel('Time')
ylabel('Voltage')
% Nyquist Frequency (Hz) half of the sampling rate of a discrete signal processing system
%PERFOM FFT
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
N = length(Signal);
meanSignal = mean(Signal); % ‘Signal’ Mean
FTSignal = fft(Signal-meanSignal)/N; % Normalised Fourier Transform Of Baseline-Corrected ‘Signal’.
Fv = linspace(0, 1, fix(numel(FTSignal)/2)+1)*Fn; % Frequency Vector
Iv = 1:numel(Fv); % Index Vector
% % % % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Plotting FFT
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[pks,locs] = findpeaks(abs(FTSignal(Iv))*2, 'MinPeakHeight',0.044);
figure
plot(Fv, abs(FTSignal(Iv))*2)
grid
xlabel('Frequency(Hz)')
ylabel('Amplitude')
plotIdx = 1:Iv(max(locs));
figure
plot(Fv(plotIdx), abs(FTSignal(Iv(plotIdx)))*2)
hold on
plot(Fv(plotIdx(locs)), pks, '^r', 'MarkerFaceColor','r')
title('FFT for Power Analysis')
xlabel('Frequency (Hz)')
ylabel('Amplitude')
xlswrite('myfile.xls',Fv')
xlswrite('myfile2.xls',abs(FTSignal(Iv))*2')
hold off
0 Kommentare
Akzeptierte Antwort
Geoff Hayes
am 22 Apr. 2020
Bearbeitet: Geoff Hayes
am 22 Apr. 2020
Jmv - if you just want to perform the FFT on each file, then wouldn't your code look something more like
%INITIALISATION
% % % % % % % % % % % % % % % % % % % % % % % % % % % %
Ts = 0.00005; % Sampling Interval (seconds)
Fs = 1/Ts; % Sampling Frequency (Hz)
Fn = Fs/2;
path = genpath('C:\Users\Power User\Desktop\');
x31 = csvread('test data1.csv',2); %read data
x32 = csvread('test data1.csv', 2);
x33 = csvread('test data1.csv', 2);
Details = (strsplit(path,'\')); %extract details for plot titles from path name
Details = char(Details(2));
Signal = {x31;x32;x33};
for k = 1:length(Signal) % <------- iterate over each file
%PERFROM FFT
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
N = length(Signal{k}(:,2));
meanSignal = mean(Signal{k}(:,2)); % kSignal(:,2) Mean
FTSignal = fft(Signal{k}(:,2) - meanSignal)/N; % Normalised Fourier Transform Of Baseline-Corrected {Signalk.
% etc.
end
The above code iterates over each dataset stored in Signal. On each iteration, we consider the dataset at Signal{k}.
3 Kommentare
Geoff Hayes
am 22 Apr. 2020
Jmv - I don't know enough about your data to understand what may be going wrong. Why do you subtract the mean?
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!