Spectral Entropy vs Frequency

I use pentropy(x,sampx) function to calculate spectral entropy distribution for a signal.
The function plots spectral entropy versus time.
However, I need to plot spectral entropy versus frequency.
Does anyone know a function in matlab to do it?

Answers (2)

Star Strider
Star Strider on 12 Aug 2020
Plotting spectral entropy as a function of frequency is actually described in the documentation in: Plot Spectral Entropy of Speech Signal Note that because the entropy spectrum varies withh time, it will be necessary to plot the result as a spectrogram, as described in the documentation section linked to here. A Fourier transform alone will not produce the appropriate result.

4 Comments

Could you please provide a code to calculate and plot spectral entropy as a function of frequency for a discrete signal? The documentation is about a continuous signal.
It is a discrete signal, since it is sampled.
Running:
C = matfile('Hello')
returns (on my computer):
C =
matlab.io.MatFile
Properties:
Properties.Source: 'C:\Program Files\MATLAB\R2020a\examples\signal\data\Hello.mat'
Properties.Writable: false
x: [220500x2 double]
The documentation also uses it and refers to it as a discrete signal.
Note that — except for the output of the soundcard — everything in a computer is discrete and sampled.
Yes, you were right it wasn't about a continious signal.
However, the example plots a color map with some predefined frequency bins.
Is there a way to evaluate entropy value at some frequency values rather than frequency ranges?
The reason I am asking is that I need to draw a xy plot with x as frequency and y as entropy axes.
Thank you.
It depends what you want. The second figure here (‘Individual Frequency Bins As Function Of Time’ that I added to an example in the documentation) demonstrates how to access the individual frequency bins displayed in the spectrogram plot. I offset them here for the plot. Access them as rows of ‘se2’ in the example code. The frequency band (bin) limits correspond to the elements of ‘flow’ and ‘fup’. In the third figure, I took a shot at plotting entropy as a function of frequency. (This is simply my best guess as to what it would be. I have no idea what you want to do.)
load Hello x
fs = 44100;
t = 1/fs*(0:length(x)-1);
x1 = x(:,1) + 0.01*randn(length(x),1);
[p,fp,tp] = pspectrum(x1,fs,'FrequencyResolution',20,'spectrogram');
flow = [300 628 1064 1634 2394];
fup = [627 1060 1633 2393 3400];
se2 = zeros(length(flow),size(p,2));
for i = 1:length(flow)
se2(i,:) = pentropy(p,fp,tp,'FrequencyLimits',[flow(i) fup(i)]);
end
subplot(2,1,1)
plot(t,x1)
xlabel('Time (seconds)')
ylabel('Speech Signal')
subplot(2,1,2)
imagesc(tp,[],flip(se2)) % Flip se2 so its plot corresponds to the ascending frequency bins.
h = colorbar(gca,'NorthOutside');
ylabel(h,'Spectral Entropy')
yticks(1:5)
set(gca,'YTickLabel',num2str((5:-1:1).')) % Label the ticks for the ascending bins.
xlabel('Time (seconds)')
ylabel('Frequency Bin')
figure
plot(tp, ((0:4).'+se2))
grid
title('Individual Frequency Bins As Function Of Time')
xlabel('Time')
ylabel('Frequency Bin')
freqmean = mean([flow; fup]);
freqmult = freqmean(:)+ones(size(se2));
figure
plot(freqmult.', se2.')
grid
title('Entropy As Function Of Frequency')
xlabel('Midband Frequency')
ylabel('se2 Row')
grid
.

Sign in to comment.

hosein Javan
hosein Javan on 12 Aug 2020
Edited: hosein Javan on 12 Aug 2020
using fft (Fast Fourier Transform). I'll give you an example.
suppose you have a discrete signal called "x[n]" that has been sampled with a sampling frequency of "Fs". do the following to achieve your frequency spectrum.
N = length(x); % signal length (samples)
a = 1/N*fft(x); % complex fourier series coefficients require 1/N for fft
X = a(1:N/2+1);
X(2:(N-1)/2+1) = 2*X(2:(N-1)/2+1); % your frequency spectrum. X(i)=fourier coefficient of harmonic(i)

2 Comments

I need to plot spectral entropy vs frequency not fft.
Spectral entropy is calculated using pentropy(x,sampx) function in matlab:
However, as I wrote in my question I need to plot spectral entropy versus frequency.
if you have a signal vs time, no matter what, you can extract its frequency-domain data using fft. I don't know if pentropy is no ordinary signal. refer to Star Strider comment if there is something special about this signal that I couldn't answer.

Sign in to comment.

Asked:

on 12 Aug 2020

Commented:

on 13 Aug 2020

Community Treasure Hunt

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

Start Hunting!