I want to only fft last half of data from simulink

3 ビュー (過去 30 日間)
Haakon Helle
Haakon Helle 2016 年 8 月 30 日
コメント済み: Adam 2016 年 8 月 31 日
I want to only apply fft to the last half of signal obtained from simulations in simulink. My take:
time=Vs_a.time(end/2:end);
vs_a=Vs_a.signals.values(end/2:end);
Ns=length(time);
Vsaf = abs(fft(vs_a))/Ns;
Vsaf(2:end)= Vsaf(2:end)*2;
This didn't give the results I expected, anyone got a clue what I'm doing wrong?
  1 件のコメント
Adam
Adam 2016 年 8 月 31 日
You need to give more information that just that results are not as expected. What do you expect and what are you getting?

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

回答 (2 件)

David Barry
David Barry 2016 年 8 月 30 日
The (end/2:end) indexing syntax will fail if you have an odd number of elements in your array. You would need to handle this case and decide which element you want. You could use round or floor, for example:
time=Vs_a.time(round(end/2):end);

Haakon Helle
Haakon Helle 2016 年 8 月 31 日
編集済み: Haakon Helle 2016 年 8 月 31 日
Thank you for your answer. It still doesn't work, so something else is the problem then. The code allways runs but gives bad results. My code only work when the length of the signal is 1 second. So if I run simulations for 2 seconds the signal have to be divided in half. My code:
time=Vs_a.time(round(end/2):end); %Time signal from Simulink
vs_a=Vs_a.signals.values(round(end/2):end); % Phase a voltage signal from Simulink
is_a=Is_a.signals.values(round(end/2):end); % Phase a current signal from Simulink
Ns=length(time); %%number of samples of the signals.
DTs=abs(time(2)-time(1)); %sampling time.
Vsaf = abs(fft(vs_a))/Ns; %%Voltage Va magnitude Fourier Transform
Vsaf(2:end)= Vsaf(2:end)*2; %Getting the Fourier series components values.

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by