Effacer les filtres
Effacer les filtres

Performing FFT from three different Excel input data

9 vues (au cours des 30 derniers jours)
Jmv
Jmv le 22 Avr 2020
Commenté : Jmv le 27 Avr 2020
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

Réponse acceptée

Geoff Hayes
Geoff Hayes le 22 Avr 2020
Modifié(e) : Geoff Hayes le 22 Avr 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 commentaires
Geoff Hayes
Geoff Hayes le 22 Avr 2020
Jmv - I don't know enough about your data to understand what may be going wrong. Why do you subtract the mean?
Jmv
Jmv le 27 Avr 2020
Hi Geoff. Thanks again. I substracted mean to remove DC Component.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by