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

조회 수: 10 (최근 30일)
Aaron Richards
Aaron Richards 2019년 10월 21일
답변: Kaashyap Pappu 2019년 10월 24일
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
KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 10월 21일
The average power (1x50 size) with respect to what?
Aaron Richards
Aaron Richards 2019년 10월 21일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

Kaashyap Pappu
Kaashyap Pappu 2019년 10월 24일
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!

카테고리

Help CenterFile Exchange에서 Waveform Generation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by