I want to only fft last half of data from simulink

3 次查看(过去 30 天)
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.

产品

Community Treasure Hunt

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

Start Hunting!

Translated by