How do I plot a constant value over multiple different intervals ?

18 vues (au cours des 30 derniers jours)
Aaron Richards
Aaron Richards le 21 Oct 2019
doubleArray = getaudiodata(rec);
plot(doubleArray);
title('Audio Signal of "Hello World"');
xlabel('Time t');
ylabel('Signal Amplitude x');
hold on %Getting them on same plot
grid on
Squared_Sig = doubleArray.^2; %Squaring all the vaules in the array
b = reshape(Squared_Sig,[],50); %Divides the square signal into 20msec
%chunks by divideing total samples by
%100, each one has 160 elements
partSum = sum(b); % Sum of each of the 100 parts
Average_power = partSum./160;
Here you can see I have the average power for each of the 100 sections of the original signal. How do I create a CT plot of the average power of these sections on the same plot as the original signal ???
  3 commentaires
KALYAN ACHARJYA
KALYAN ACHARJYA le 21 Oct 2019
The average power (1x50 size) with respect to what?
Aaron Richards
Aaron Richards le 21 Oct 2019
The first plot, doublearray is the plot of the signal amplitude with respect to time.
Average_power is the average power of a 0.02 sec interval of the signal.
There are 50 total 0.02 sec intervals in the signal.
The singal length is 8000, so each of the 50, 0.02 sec intervals will have a length of 160
I need to plot Average_power(:,1) for the interval t=1, to t=160
Avergae_power(:,2) for the interval t=161, to t=320
Average power(:,3) for the interval t=321, to t=480
..... and so on for the entire signal, which is 8000.

Connectez-vous pour commenter.

Réponses (1)

Kaashyap Pappu
Kaashyap Pappu le 24 Oct 2019
To plot an overlapping line onto the figure, an x-axis vector would need to be specified and provided to the “plot” function along with the data. The vector would need to have the exact x-values where the corresponding data points should be plotted. The linspace function can help generate an evenly spaced vector.
The following modification to code can achieve this:
doubleArray = getaudiodata(rec)
durationOfSignal = length(doubleArray)*0.02/50; %Specified X-Axis vector using the time values
timeValues = linspace(0,durationOfSignal,length(doubleArray));
plot(timeValues,doubleArray);
title('Audio Signal of "Hello World"');
xlabel('Time t in ms');
ylabel('Signal Amplitude x');
hold on %Getting them on same plot
grid on
Squared_Sig = doubleArray.^2; %Squaring all the vaules in the array
b = reshape(Squared_Sig,[],50); %Divides the square signal into 20msec
%chunks by divideing total samples by
%100, each one has 160 elements
partSum = sum(b); % Sum of each of the 100 parts
Average_power = partSum./160;
xVal = linspace(0,durationOfSignal,length(Average_power)); %X-Axis vector for the Average Power sequence
plot(xVal,Average_power)
Hope this helps!

Catégories

En savoir plus sur Line Plots dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by