How do I get the probability density function of a sine wave?
19 views (last 30 days)
Show older comments
Hi, I want to do something very simple in MATLAB which is just to get the probability density function of a sine wave and plot it. I know that the pdf plot has a U-shape, but I am not able to get it by using the pdf function in MATLAB no matter which "name" I use. For example:
x=-4*pi:.01:4*pi; y=sin(x);
So I just want to plot pdf for x between -1 and 1. Any help is appreciated. Thanks.
3 Comments
Star Strider
on 30 Aug 2012
Edited: Star Strider
on 30 Aug 2012
I'm not going to enter this as an ‘Answer’ because I can only take credit for Googling until I found a good discussion of it in EXAMPLES for Matlab Signal Processing (curiously without any associated MATLAB scripts). See ‘Probability Distribution of a Sine Wave’ pages 232-3, eqns 8.47-8.55 and figures 8.11 and 8.12.
Answers (1)
Image Analyst
on 29 Aug 2012
Edited: Image Analyst
on 29 Aug 2012
So why don't you generate a long sine wave signal and then pass it in to hist()? It's really really easy:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
workspace; % Make sure the workspace panel is showing.
format longg;
format compact;
fontSize = 20;
omega = 1:80000;
period = 8000;
y = sin(2*pi*omega / period);
subplot(2, 1, 1);
plot(omega, y, 'b-');
title('Signal', 'FontSize', fontSize);
grid on;
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
[counts binValues] = hist(y, 64);
subplot(2, 1, 2);
bar(binValues, counts);
title('Histogram', 'FontSize', fontSize);
grid on;
Run my code above and you'll see your image.
2 Comments
Image Analyst
on 30 Aug 2012
Simply divide the counts by the sum of the counts so that the total "area" equals 1.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!