EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home Data Science Data Science Tutorials Matlab Tutorial Power Spectral Density MATLAB
 

Power Spectral Density MATLAB

Updated March 15, 2023

Power Spectral Density Matlab

 

 

Introduction to Power Spectral Density MATLAB

Power spectral density Matlab or PSD is used to show the strength of energy variations in terms of frequency.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

PSD is used to detect the frequencies for stronger and weaker variations. PSD is measured in the unit (energy / frequency) or (variance / width).

It is used popularly if we want to understand the amplitudes & frequencies of signals (oscillatory) in our time series data. Using PSD, we can detect noise or unwanted vibrations and also locate the machines producing these unwanted noises.

MATLAB provides various functions to get the power spectral density, but it recommends ‘periodogram’ as the most suitable function for getting PSD. Therefore, let us discuss in detail how the periodogram function is used in MATLAB to get PSD.

Function 1: Power spectral density using periodogram function

Syntax

psd = periodogram (s)

Description of periodogram function:

psd = periodogram (s) will return the power spectral density estimate of the input signal, which is found using a rectangular window. Please note that the number of points in discrete Fourier transform will be either 256 or immediate next power of 2, whichever is greater than the length of the signal.

Examples of Power Spectral Density Matlab

Let us see how the code for periodogram function to get PSD looks like in MATLAB:

Example #1

a = 0 : 499;

[Defining number of samples as 500]

s = sin (pi / 2 * a) + randn (size (a));

[creating an input wave with an angular frequency of pi/2 radian/sample]

[psd] = periodogram (s);

[Calling the periodogram function]

plot (10 * log10 (psd))

[Calling the plot function and using a logarithmic scale to get the output]

Input:

a = 0 : 499;
s = sin (pi / 2 * a) + randn (size (a));
[psd] = periodogram (s);
plot (10 * log10 (psd))

Output:

power spectral density matlab output 1

Please note that the power spectral density obtained in the above output will have a DFT length of 512 points (which is the immediate power of 2 greater than the length of the signal).

Example #2

F = 1000

[Sampling the frequency]

a = 0:1/F:1-1/F;

[Defining the sample time]

x = cos (4 * pi /200 * a) + randn (size (a));

[Creating input wave with an angular frequency of 4pi/200 radian/sample]

[psd, w] = periodogram (x, [], length (x), F);

[Calling the periodogram function]

plot (w, 10 * log10 (psd))

[Calling the plot function and using a logarithmic scale to get the output]

Input:

F = 1000
a = 0:1/F:1-1/F;
x = cos (4 * pi /200 * a) + randn (size (a));
[psd, w] = periodogram (x, [], length (x), F);
plot (w, 10 * log10 (psd))

Output:

power spectral density matlab output 2

We can also get power spectral density without using the ‘periodogram’ function.

Next, we will learn to create PSD using ‘Fourier transform.’

Syntax:

F = 600;

[Sampling the frequency]

T = 1 / F;

[Defining the sample time]

L = 3000;

[Defining the length of the signal]

a = (0 : L-1) *  T;

[Defining the time vector]

s = cos (4 * pi / 200 * a) + randn (size (a));

[Creating input wave with an angular frequency of 4pi/200 radian/sample]

Ft = fft (s);

[Calling the Fourier transform function using input signal ‘s’]

Psd = 1 / (L * F) * abs (Ft (1 : length (s) / 2+1)).^3;

[Normalizing the signal]

fre = 0 : F/L : F/2;

[Setting the frequency]

plot (fre, 10 * log10 (Psd));

[Calling the plot function and using a logarithmic scale to get the output]

Input:

F = 600;
T = 1 / F;
L = 3000;
a = (0 : L-1) *  T;
s = cos (4 * pi / 200 * a) + randn (size (a));
Ft = fft (s);
Psd = 1 / (L * F) * abs (Ft (1 : length (s) / 2+1)).^3;
fre = 0 : F/L : F/2;
plot (fre, 10 * log10 (Psd));

Output:

power spectral density matlab output 3

As we can see in the output, we have obtained the PSD using Fourier transform.

Conclusion

Power spectral density is mostly used to understand the amplitudes & frequencies of signals (oscillatory) in our time series data. MATLAB provides us with various functions like a periodogram to get PSD. Power spectral density can also be created using Fourier transform, as we learned in this article.

Recommended Articles

This is a guide to Power Spectral Density Matlab. Here we discuss the Examples of Power Spectral Density Matlab along with the input and output. You may also have a look at the following articles to learn more –

  1. Matlab Forms
  2. Matlab xcorr
  3. Matlab plot title
  4. Signal Processing Matlab

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA Login

Forgot Password?

🚀 Limited Time Offer! - 🎁 ENROLL NOW