MATLAB Answers


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

Asked by Muhammad Shafiq on 12 Sep 2018 at 17:15
Latest activity Commented on by Muhammad Shafiq on 16 Sep 2018 at 16:44

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


Might look at waterfall plot.

I don't know what you mean as far as "in the same graph" when mixing time and frequency domains??? Can you show a representative plot of what you'd like yours to look like?

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', ...

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.

Sign in to comment.

2 Answers

Answer by Aquatris
on 12 Sep 2018 at 18:38
 Accepted Answer

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);;
% 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
% plot time domain

Make sure you understand what is done in each step and if you have questions, feel free to ask.

  1 Comment

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);;



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 = [];)

Sign in to comment.

Answer by Aquatris
on 16 Sep 2018 at 16:14

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 Comment

Sign in to comment.