Asked by Muhammad Shafiq
on 12 Sep 2018

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

Answer by Aquatris
on 12 Sep 2018

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

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.

Muhammad Shafiq
on 16 Sep 2018

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

Sign in to comment.

Answer by Aquatris
on 16 Sep 2018

Opportunities for recent engineering grads.

Apply Today
## 2 Comments

## dpb (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/418709-plotting-fft-of-several-data-sets-signals-of-same-length-in-the-same-graph#comment_609507

## Muhammad Shafiq (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/418709-plotting-fft-of-several-data-sets-signals-of-same-length-in-the-same-graph#comment_609515

Sign in to comment.