Performing FFT from three different Excel input data

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

Jmv
Jmv le 22 Avr 2020
Hi Goff. Thanks very much for help with this. Yes what i am trying to do is perform FFT on each file. I added the iteration part of the code however I am not getting the right FFT plot. the below plot is what I should be getting. i intentionally used test data1.csv file only for the three signal to check if I would get the below plot.
i Don't know where I am going wrong as I am not getting any error when i implement the code in your comment above.
Thanks for any more help you can provide.
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)

Catégories

En savoir plus sur Fourier Analysis and Filtering 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!

Translated by