I wrote the following code. I have one question regarding mean and SMS. Since the Disp_Data is a vecotor, how can I write the code to make sure the mean and RMS result come as a vector as well for plotting.
Time = 0:0.001:5;
T = Time(2)-Time(1); % Sampling period
Fs = 1/T; % Sampling frequency
L = size(Time,2); % Length of signal
Disp_Data = 5*(sin(10*2*pi*Time)+0.1*((rand(1,L)-0.5)*2));
M_data = mean(Disp_Data);
RMS_data = RMS (Disp_Data)

 採用された回答

Star Strider
Star Strider 2020 年 12 月 9 日

0 投票

Try this:
Time = 0:0.001:5;
T = Time(2)-Time(1); % Sampling period
Fs = 1/T; % Sampling frequency
L = numel(Time); % Length of signal
Disp_Data = 5*(sin(10*2*pi*Time)+0.1*((rand(1,L)-0.5)*2));
M_data = mean(Disp_Data);
RMS_data = rms(Disp_Data);
figure
plot(Time, Disp_Data)
hold on
plot(xlim, [1 1]*M_data, 'LineWidth',1.5)
plot(xlim, [1 1]*RMS_data, 'LineWidth',1.5)
hold off
grid
xlabel('Time')
ylabel('Amplitude')
legend('Signal', 'Signal Mean', 'Signal RMS')
Note that the mean and RMS values are the same for the entire signal.

6 件のコメント

Image Analyst
Image Analyst 2020 年 12 月 9 日
Right, so I was wondering why Fred thinks that they should be vectors.
Note: with later versions you can use xline() and yline() to draw vertical or horizontal lines.
Star Strider
Star Strider 2020 年 12 月 9 日
Fred Mahoney wants to plot them, and needs a way to do that. The plot function only plots vectors (unless markers are used to plot single points).
My code creates the necessary 2-element vectors that plot wants, and plots them.
Fred Mahoney
Fred Mahoney 2020 年 12 月 9 日
Thank you both. I appreciate it
Star Strider
Star Strider 2020 年 12 月 9 日
As always, my pleasure!
OGUNGBEMI Ezekiel
OGUNGBEMI Ezekiel 2021 年 8 月 16 日
Hi, I tried using the RMS @ Star strider provided but the error am getting is ' undefined Function or Variable * nume1*'
L = nume1(Time):
Thanks in anticipation.
Star Strider
Star Strider 2021 年 8 月 16 日
l ~= 1

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeStartup and Shutdown についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by