Clear Filters
Clear Filters

plot multiple PSD lines in single graph in color scale (imagesc)

7 views (last 30 days)
Hi, I have 13 signals where I produce the PSD for each with the psd function using Welch's method object (spectrum.welch). But this only allows me to generate separate plots for each signal. Is there a way to express all 13 PSDs in pseudocolor (like imagesc) in a single figure where Y is each of the 13 signals, X is the frequencies, and the color is the power/frequency (dB/Hz)? So basically I want to generate a 13 x n matrix containing the PSD of each signal.
Example:
Fs=10000; %sampling frequency in samples per second
t=0:(1/Fs):1; %one second time vector, 10001 elements
y=0.4*cos(2*pi*2000*t)+0.2*sin(2*pi*1000*t)+randn(size(t));
h = spectrum.welch;
Hpsd=psd(h,y,'Fs',Fs,'ConfLevel',0.95);
figure, plot(Hpsd)
This only gives me 1 plot. If I do this 13 times, how can I create a 13 x n figure where the PSDs are expressed in color? I basically want a figure that looks like imagesc(rand(13,100)) but with PSDs and not random numbers.
Thanks in advance!

Accepted Answer

Youssef  Khmou
Youssef Khmou on 11 Jan 2014
Edited: Youssef Khmou on 11 Jan 2014
Yes you can generate the 2D spectrum, here is an example with 13 signals as you said :
Fs=80;
f=10+rand(13,1)*10; % frequencies of the signals
t=0:1/Fs:10-1/Fs;
y=zeros(13,length(t));
for n=1:13
y(n,:)=sin(2*pi*t*f(n));
end
% spectrum
h=spectrum.welch;
F=zeros(13,129);
for n=1:13
t=psd(h,y(n,:),'Fs',Fs);
F(n,:)=t.Data;
end
figure, surface(F), shading interp
You add the x,y labels...
  3 Comments
S
S on 14 Jan 2014
I figured it out. I just need to multiply F by 10*log10 and the units become dB/Hz.

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 11 Jan 2014
Perhaps the waterfall() function?

Community Treasure Hunt

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

Start Hunting!