Plotting FFT of several data sets (signals) of same length, in the same graph

15 ビュー (過去 30 日間)
Muhammad Shafiq 2018 年 9 月 12 日
コメント済み: Muhammad Shafiq 2018 年 9 月 16 日
I have a data of several thousands samples (say 60000), the sampling frequency is given (1 MHz). I want to divide the data in equal frames, each of 500 samples that makes 120 frames, then plot all those (120) frames on the same graph to compare them. I want to plot in time domain and frequency domain. I have been able to do the time domain plot but I don’t know how to do the frequency domain plot of all of the signals in the same graph. Looking forward for the help. Thanks
2 件のコメント表示非表示 1 件の古いコメント
Muhammad Shafiq 2018 年 9 月 12 日
I mean time plots in one graph and frequency domain plots in another. For example;
plot(f/1E6,2*abs(Y1(1:NFFT/2))/1E-3,'r', ...
f/1E6,2*abs(Z1(1:NFFT/2))/1E-3,'b', ...
f/1E6,2*abs(A1(1:NFFT/2))/1E-3,'g');
This plots the FFTs of three signals in same graph. But if we have large number of signals then how to do it. While signals are, as I mentioned in my main question.

サインインしてコメントする。

採用された回答

Aquatris 2018 年 9 月 12 日
You put all of the signals you want in a matrix (each column is a different partition of the signal);
data = rand(60000,1); % replace with your data
y = [];
for i = 1:120
y(:,i) = data((i-1)*500+1:(i)*500);;
end
% perform the fft as;
L = 500;
Y = fft(y);
P2 = abs(Y/L);
P1 = P2(1:L/2+1,:);
P1(2:end-1,:) = 2*P1(2:end-1,:);
% obtain frequency matrix;
Fs = 1e3; % sampling frequency
f = Fs*(0:(L/2))/L;
% plot frequency domain
figure(1)
semilogy(f,P1)
% plot time domain
figure(2)
plot([1:L]/Fs,y)
Make sure you understand what is done in each step and if you have questions, feel free to ask.
1 件のコメント表示非表示 なし
Muhammad Shafiq 2018 年 9 月 16 日
Many thanks Aquatris for your help and sorry for the late feed back I was on travel so responding late.
I have included my data file
Data1=VarName1(1:60000);% I used 60,000 samples among the big data file.
Then in your code I replaced my data
data = Data1; % replace with your data
y = [];
for i = 1:12
y(:,i) = data((i-1)*500+1:(i)*500);;
end
-------------------
I have not replaced anything in
y = [];
Still I could see the plots in time and frequency domain. Could you please mention further about it (y = [];)

サインインしてコメントする。

その他の回答 (1 件)

Aquatris 2018 年 9 月 16 日
y = [] just makes y an empty matrix. It is not a necessary code. I include it in the off chance that you had a variable named y in your code. That line would delete any contents of previously assigned y variable values
1 件のコメント表示非表示 なし
Muhammad Shafiq 2018 年 9 月 16 日
OK great and thanks again :)

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!