首页 > 代码库 > [MATLAB&SIMULINK] 如何提取并处理Simscape Power System 中powergui的谐波分析数据
[MATLAB&SIMULINK] 如何提取并处理Simscape Power System 中powergui的谐波分析数据
花了一两个小时研究了一番powergui的fft。在powergui中,FFT Analysis Tool如图所示
那么如果我想提取出Simulink模型中的数据并且做fft处理,得到自己想要的分析图像,应该怎么办呢?
方法一:
其实MATLAB在这个过程中调用了power_fftscope()这个函数。它的函数原型可以在matlab的帮助文档中找到。函数调用的格式如下。
在command窗口里输入如下命令即可设定与调用由FFT Analysis Tool产生的波形数据
>> FFTDATA =http://www.mamicode.com/ power_fftscope(Va) %实例化对象FFTDATA,它代表Va的fft结构体数据FFTDATA = time: [457947x1 double] signals: [1x1 struct] blockName: ‘HP/VA‘ input: 1 signal: 1 startTime: ‘last‘ cycles: 1 fundamental: 60 maxFrequency: 1000 THDmaxFrequency: Inf THDbase: ‘fund‘ mag: [17x1 double] phase: [17x1 double] freq: [17x1 double] THD: 272.5235 samplingTime: 4.3673e-06 samplesPerCycle: 3816 DCcomponent: 14.5702 magFundamental: 48.1973>> FFTDATA.fundamental = 100 %设定基频FFTDATA = time: [457947x1 double] signals: [1x1 struct] blockName: ‘HP/VA‘ input: 1 signal: 1 startTime: ‘last‘ cycles: 1 fundamental: 100 maxFrequency: 1000 THDmaxFrequency: Inf THDbase: ‘fund‘ mag: [17x1 double] phase: [17x1 double] freq: [17x1 double] THD: 272.5235 samplingTime: 4.3673e-06 samplesPerCycle: 3816 DCcomponent: 14.5702 magFundamental: 48.1973>> FFTDATA.cycles = 200 %设定周期数FFTDATA = time: [457947x1 double] signals: [1x1 struct] blockName: ‘HP/VA‘ input: 1 signal: 1 startTime: ‘last‘ cycles: 200 fundamental: 100 maxFrequency: 1000 THDmaxFrequency: Inf THDbase: ‘fund‘ mag: [17x1 double] phase: [17x1 double] freq: [17x1 double] THD: 272.5235 samplingTime: 4.3673e-06 samplesPerCycle: 3816 DCcomponent: 14.5702 magFundamental: 48.1973>> FFTDATA.maxFrequency = 7900 %设定最高频率FFTDATA = time: [457947x1 double] signals: [1x1 struct] blockName: ‘HP/VA‘ input: 1 signal: 1 startTime: ‘last‘ cycles: 200 fundamental: 100 maxFrequency: 7900 THDmaxFrequency: Inf THDbase: ‘fund‘ mag: [17x1 double] phase: [17x1 double] freq: [17x1 double] THD: 272.5235 samplingTime: 4.3673e-06 samplesPerCycle: 3816 DCcomponent: 14.5702 magFundamental: 48.1973
>> x = FFTDATA.freq %获得频率
x =
0
60
120
180
240
300
360
420
480
540
600
660
720
780
840
900
960
>> y = FFTDATA.mag %获得幅值
y =
14.5702
48.1973
79.0183
18.0582
9.8706
7.3618
5.3919
4.5902
3.5941
3.4998
3.1022
2.7178
2.7215
2.3526
2.3970
2.6270
2.1154
之后通过简单的绘图命令我们就可以绘制出模型的频谱图。
方法二:
如果你只是很简单的想修改由FFT Analysis Tool生成的频谱分析图形,不妨试试下面简单的方法。
在command中新建一个figure
>> figure
打开后选择工具下的plot edit
然后右键粘贴即可。
这样你就可以通过set()来设定figure的参数,改变图形的配置。具体要设定gca句柄。
比如
>> set(gca,‘yscale‘,‘log‘) %将y轴转换成对数坐标
对于gca句柄,在[2]中有较为详尽的命令。
参考:
[1]:http://cn.mathworks.com/help/physmod/sps/powersys/ref/power_fftscope.html;jsessionid=db0b9a8ee73742bf537d1f0a3291?refresh=true#responsive_offcanvas
[2]:http://wenku.baidu.com/link?url=HqIyvz6p9G8IY1Xb01_sXcN_aZjdV8iUk2AuCby1T0WHIKxahcHTPozq2M8UgGqQdjzJElSpfEI2W83EB0gYbRbB3uVGxpJKQjJGJobwR6C
[MATLAB&SIMULINK] 如何提取并处理Simscape Power System 中powergui的谐波分析数据