Matlab FFT

Thread Starter

laura89

Joined Oct 25, 2013
4
Hello everyone, I'm implementing a matlab code that realizes the space vector modulation for a three-phase inverter. One of the points required is the representation of the spectrum of inverter output voltage.
I wrote the following code:
Rich (BB code):
function out=spettro(ValoreNelTempo,IntervalloTempo,fmax)

dime = max(size(ValoreNelTempo));
f0 = 1/IntervalloTempo;
n = floor(fmax/f0);
if (n>dime)
    n=dime-1;
end
ValoreNelTempo=reshape(ValoreNelTempo,dime,1);
tempo = linspace(0,IntervalloTempo,length(ValoreNelTempo));

a=fft(ValoreNelTempo);

Armoniche=2*abs(a(2:dime))/dime;
numarm=1:n;


    figure(1), subplot(2,1,1)
    
    bar(numarm*f0,Armoniche(numarm),0.5,'r')
    xlabel('frequenza - Hz'),grid
    
    figure(1), subplot(2,1,2)
    plot(tempo,ValoreNelTempo,'b-');
    xlabel('tempo - s'), grid
    
out=Armoniche(numarm);
I later called up as follows:
Rich (BB code):
tempo = simout.time;
% tempo= t(time>0.3)
y = simout.signals.values;
% signal_mod= y(time>0.3)
out = spettro(y,max(tempo),2/Ts);

figure(1),
subplot(2,1,1), ylim([0 40]), xlim([0 100])
legend('spettro del segnale campionato')
subplot(2,1,2), ylim([-100 100]), xlim([0 2])
legend('laura')
Simout is a signal that I take from a scope of simulink.
I get the attached graph.
This chart is not correct, because I should do the FFT of the sine wave (omitting the transient) and then the teacher told me to take an integer number of periods.
I am not able to do so. Could you please help me?
Thanks in advance
Ps: sorry for my english
 

Attachments

WBahn

Joined Mar 31, 2012
30,060
What, exactly, is it that you need to do that you don't know how to do?

It seems that you have a data vector that are a whole bunch of samples of a signal as a function of time. You then want to take a subset of that vector that starts far enough into the vector to get past the transient and that is the right length so as to amount to an integral number of periods of a particular frequency.

What part of that process is tripping you up? Or it is some other aspect?
 

Thread Starter

laura89

Joined Oct 25, 2013
4
Thanks for the reply. The problem is that I'm not able to take only part of the signal. I tried to write in the code
Rich (BB code):
signal_mod= y(time>0.3)
, but still I get a wrong chart. Should I get only the fundamental harmonic. How can I fix the problem?
 

Attachments

WBahn

Joined Mar 31, 2012
30,060
How is "time" encoded in any of these data structures at all? That's not al all apparent to me?

What is "simout.time"?

It's been some time since I worked with Matlab, so there are lots of things that you may need to describe to me.
 

MrChips

Joined Oct 2, 2009
30,808
I do both Matlab and FFT. If you can break it down to the heart of the problem I may be able to help. I cannot go over the entire code to search for your problem.
 

Thread Starter

laura89

Joined Oct 25, 2013
4
I try to explain the problem better.
Simout cames from To Workspace block.
The To Workspace block inputs a signal and writes the signal data to the MATLAB workspace. The block writes the data to an array or structure that has the name specified by the block's Variable name parameter. This format consists of a structure with three fields: time, signals, and blockName. The time field is empty. The blockName field contains the name of the To Workspace block. The signals field contains a structure with three fields: values, dimensions, and label.
In my code the signal is the output voltage of an inverter. I need to find the FFT of this signal, but It has a transient that I must bypass.
How can I do this? Can I write
Rich (BB code):
signal_mod= y(time>0.3)
?
 

Attachments

Top