MatLab Simulink

Thread Starter

cloud

Joined Dec 15, 2006
11
I have obtained my waveform in time axis but I would like to convert to frequency domain. How do I do it?

Thank you.
 

Dave

Joined Nov 17, 2003
6,970
As an example:

Rich (BB code):
>> t = [0:0.1:10]; % Declare a time range
>> y = sin(t); % Calculate a sine wave - this is your wave in the time domain
>> X = fft(y); % Compute the FFT using the Matlab fft function
>> Xyy = X.* conj(X) / 101; % Calculate the power spectrum at different frequencies
>> f = [0:(2*pi):(2*pi*100)]; % Declare the frequency range
>> plot(f,Xyy) % Plot the frequency represenation. You have a spike at a frequency of 2π which is as expected from y = sin(t)
Dave
 

Dave

Joined Nov 17, 2003
6,970
You can use User-Defined Functions > Embedded Matlab Function - you can now insert your own m-code as above.

Dave
 

Thread Starter

cloud

Joined Dec 15, 2006
11
You can use User-Defined Functions > Embedded Matlab Function - you can now insert your own m-code as above.

Dave
But where should I connect the input and output of Embedded Matlab Function to?

I use another method by connecting to FFT block, and then to Spectrum Scope (shown as attached), but not sure whether this is correct. Can you advise me?

Thank you.
 

Attachments

Dave

Joined Nov 17, 2003
6,970
But where should I connect the input and output of Embedded Matlab Function to?

I use another method by connecting to FFT block, and then to Spectrum Scope (shown as attached), but not sure whether this is correct. Can you advise me?

Thank you.
Well your input is the time-domain signal, and the output is the frequency domain signal. For example, if your time-domain signal is stored in an array tdsignal and your frequency-domain signal is stored in an array fdsignal, then your function signature in the m-file should read:

fdsignal = fcnname(tdsignal)

Followed by your domain conversion code.

Your Embedded Matlab Function should merely replace the FFT block which IIRC just implements the Matlab fft function (I may be wrong here). I would advise you to get your domain conversion code working in Matlab as you require, then think about your integration into a Simulink model.

I'll dig around my Simulink notes since it is a while (years) since I have used it.

Dave
 
hi
i have a sine wave with a varying frequency term, as in the f is 10 for a particular time interval and zero everywhere else.
I want to plot the frequency vs time.

any help on how to do the same using matlab/simulink.

I tried using fft but i'm sure of it's working. Just used the code given in matlab help file.
 
Top