[ZZ] An example of MATLAB program to find information entropy of one-dimensional sequence (Shannon entropy)

Source: Internet
Author: User

For a two-dimensional signal, such as grayscale images, the range of gray values is 0-255, so as long as the pixel gray value (0-255) appears in the probability, you can calculate the information entropy.
However, for a one-dimensional signal, such as ECG, the range of data values is not deterministic, will not be (0-255) so determined, if the domain value transformation, so that the conversion to an integer range, it will lose data, please expert guidance, how to calculate.

For example, the digital signal is x (n), N=1~n
(1) The Hist function is used to block the assignment range of x (n), for example, the value of the assignment range in 0~10
A piece, a second piece of 10~20, and so on. Before this, we need to do some normalization of X (n)
(2) Count the number of data in each block and find out the corresponding probability
(3) Solving with information entropy formula

Although the above method obtains the approximate information entropy, it is generally believed that it is no problem to do so.

The MATLAB program code for the information entropy of a one-dimensional sequence is as follows: (in the form of a function called)

Test procedure:

fs=12000;
n=12000;
t=1/fs;
t= (0:n-1) *t;
ff=104;
sig=0.5* (1+sin (2*pi*ff*t)). *sin (2*pi*3000*t) +rand (1,length (t));

Hx=yyshang (sig,10)

% ——————— seeking one-dimensional discrete sequence information entropy matlab code

Function Hx=yyshang (Y,duan)
% does not signal entropy of the time domain referenced by the original signal
% input: MAXF: The largest point in the energy spectrum of the original signal
%y: The sequence of information entropy to be asked
%duan: The sequence of information entropy to be asked to be divided by the number of blocks
%hx:y information entropy
%duan=10;% the sequence by Duan number, if duan=10, the sequence is divided into 10 equal parts
x_min=min (y);
X_max=max (y);
MAXF (1) =abs (x_max-x_min);
MAXF (2) =x_min;
Duan_t=1.0/duan;
JIANGE=MAXF (1) *duan_t;
% for i=1:10
% pnum (i) =length (Find (y_p>= (i-1) *jiange) & (Y_p<i*jiange));
% End

Pnum (1) =length (Find (Y<MAXF (2) +jiange));
For i=2:duan-1
Pnum (i) =length (Find ((Y>=MAXF (2) + (i-1) *jiange) & (Y<MAXF (2) +i*jiange));
End
Pnum (Duan) =length (Find (Y>=MAXF (2) + (duan-1) *jiange));
%sum (Pnum)
Ppnum=pnum/sum (pnum);% probability of occurrence of each segment
%sum (Ppnum)
hx=0;
For I=1:duan
If Ppnum (i) ==0
hi=0;
Else
Hi=-ppnum (i) *log2 (Ppnum (i));
End
Hx=hx+hi;
End
End

%----------------

Extended reading:

Experiment one: Calculate entropy of discrete sources

First, the experimental equipment :

1. Computer

2. Software:Matlab

Second, the purpose of the experiment :

1, familiar with the characteristics of discrete sources;

2. Learn how to simulate discrete sources

3. How to calculate the entropy of discrete source information

4, familiar with Matlab programming;

Third, the contents of the experiment :

1. Write the Matlab program of calculating the self-information

2. Write a Matlab program to calculate the entropy of discrete sources .

3, master two yuan discrete source of the maximum amount of information and probability of the relationship.

4, the program on the computer simulation implementation, verify the correctness of the program and complete the exercise.

Iv. requirements of the experimental report

This paper briefly summarizes the characteristics of discrete sources and calculates the entropy of discrete sources , and writes out the MATLAB Implementation Statement of the exercise.

Information Theory basis:

Formulas for calculating self-information

MATLAB implementation:i=log2 (1/p) or i=-log2 (p)

Calculation formula of entropy (average self-information)

MATLAB implementation:hx=sum (-X.*LOG2 (x)), or h=h-x (i) *log2 (x (i));

Exercises:

1. The source space for the weather forecast consists of:

The source space for the B-ground is:

To find the entropy of the two sources. To find the self-information of various weather.

Case:

To run the program:

The probability of p1=[1/2,1/4,1/8,1/8];%p1 representing the source of a beacon

The probability of p2=[7/8,1/8];%p2 representing the corresponding source of B

h1=0.0;

h2=0.0;

I=[];

J=[];

For I=1:4

H1=H1+P1 (i) *log2 (1/P1 (i));

I (i) =log2 (1/P1 (i));

End

Disp (' Self-Information:');

I

Disp (' H1 source entropy is:');

H1

For J=1:2

H2=H2+P2 (j) *log2 (1/p2 (j));

J (j) =log2 (1/p2 (j));

End

Disp (' Self-Information:');

J

Disp (' H2 source entropy is:');

H2

[ZZ] An example of MATLAB program to find information entropy of one-dimensional sequence (Shannon entropy)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.