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
댓글 수: 0
채택된 답변
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
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?
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Fourier Analysis and Filtering에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
