Performing FFT from three different Excel input data

4 次查看(过去 30 天)
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

采纳的回答

Geoff Hayes
Geoff Hayes 2020-4-22
编辑:Geoff Hayes 2020-4-22
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 个评论
Geoff Hayes
Geoff Hayes 2020-4-22
Jmv - I don't know enough about your data to understand what may be going wrong. Why do you subtract the mean?
Jmv
Jmv 2020-4-27
Hi Geoff. Thanks again. I substracted mean to remove DC Component.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Measurements and Feature Extraction 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by