フィルターのクリア

How to get average power from simulink scope

18 ビュー (過去 30 日間)
Yousef
Yousef 2021 年 2 月 10 日
I creat this blocks to find average power of two sin waves with different frequencies
p(t)=v(t)*i(t) (frequency of v(t) is 1 rad/s and i(t) is 3 rad/s)
then i got this plot
from this plot it's clearly the average power is zero but how can i get it from command window

採用された回答

Pratyush Roy
Pratyush Roy 2021 年 2 月 15 日
Hi Yousef,
Firstly the data can be exported to workspace as an array of shape (N,2). Here N represents the number of time instances. The code snippet below can be used to obtain the array
scopeConfig = get_param('power_model/Scope','ScopeConfiguration');% power_model denotes the Simulink model mentioned before
scopeConfig.DataLogging = true;
scopeConfig.DataLoggingSaveFormat = 'Array';
out = sim('power_model');
arr = out.ScopeData;
The first column in the array represents the time values and the second column represents the array values. To obtain the average power we can simply take the mean of the second array:
avgPower = mean(arr(:,2));
Hope this helps!
Regards,
Pratyush.
  1 件のコメント
Tomas Salvadores Viertel
Tomas Salvadores Viertel 2022 年 4 月 4 日
Can this be done directly in simulink?
I tried to use moving average blocks, but they work in a discrete manner, using a sample number as parameter. I'd like to use a continuos moving average specifying a time window. Is there a way to do this without exporting the data to the workspace? It's very easy in other simulation enviroments like Plecs.

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

その他の回答 (0 件)

コミュニティ

カテゴリ

Help Center および File ExchangeSources についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by