Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
power spectral density

Subject: power spectral density

From: Mehmet Demirtas

Date: 25 Apr, 2010 20:14:04

Message: 1 of 5

Hi all,

I have a signal vector (Fase1vuoto1) with length(Fase1vuoto1). I would like to obtain power/frequency values of each frequency component. I used Hpsd=dspdata.psd(...) function and i can obtain the Frequency versus Power/frequency plot. But, i need them in two different vectors. How can i obtain such vectors one for frequency, one for power/frequency.

Fs=5000;

nfft=2^nextpow2(length(Fase1vuoto1));
Pxx=abs(fft(Fase1vuoto1,nfft)).^2/length(Fase1vuoto1)/Fs;

% Create a one-sided spectrum
Hpsd=dspdata.psd(Pxx(1:length(Pxx)/2),'SpectrumType','Onesided','Fs',Fs);

figure(1)
plot(Hpsd)

I need to obtain all frequency values in a vector and Power/frequency values in another vector...

Subject: power spectral density

From: Sadik

Date: 25 Apr, 2010 20:29:06

Message: 2 of 5

Hi Mehmet,

One solution is that after you have your plot, you could obtain the handle to the [blue] line object in the plot and then get its XData [which will be the frequency values] and YData [which will be the power/frequency values].

Something like this: [You may need to modify the code a bit]

h = findobj('type','line');
freq = get(h, 'XData');
powerOverFreq = get(h,'YData');

If you have put a legend on your plot or due to some other reason h is an array rather than a scalar, you can select the elements of it to use in get, just like:

freq = get(h(2),'XData');

Best.

Subject: power spectral density

From: Mehmet Demirtas

Date: 25 Apr, 2010 22:41:05

Message: 3 of 5

Hi Sadik,

Thank you for your reply. I checked matlab help for the usage of findobj function but i didn't understand it... how can i implement it in my code? could you please help me?

Subject: power spectral density

From: Mehmet Demirtas

Date: 25 Apr, 2010 22:50:06

Message: 4 of 5

After running the m-file, in Matlab command window when i type Hpsd, i get:


Hpsd =
 
                   Name: 'Power Spectral Density'
                   Data: [8192x1 double]
           SpectrumType: 'Onesided'
    NormalizedFrequency: false
                     Fs: 5000
            Frequencies: [8192x1 double]
              ConfLevel: 'Not Specified'
           ConfInterval: []

So, how can i implement the findobj function in this case? Sorry, i am a Matlab newbie... i would be grateful if you help me...

Subject: power spectral density

From: Sadik

Date: 25 Apr, 2010 23:51:04

Message: 5 of 5

Hi Mehmet,

I suggested a solution as a reply to your mail. Please check your inbox.

Best.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us