How do I plot a constant value over multiple different intervals ?
10 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
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!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Waveform Generation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!