>> 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)
But where should I connect the input and output of Embedded Matlab Function to?You can use User-Defined Functions > Embedded Matlab Function - you can now insert your own m-code as above.
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: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?
|Thread starter||Similar threads||Forum||Replies||Date|
|LCL Filter Plant Control||Homework Help||0|
|A||Convert pole-placement feedback control to PID control||Automation, Robotics & Control||0|
|A||Problem in writing MATLAB code of Simulink model (state space)||Programming & Languages||0|
|L||Discretize continuous controller in Matlab-simulink||Digital Design||1|
|N||Continuous to discrete modeling in MATLAB/Simulink||Power Electronics||0|
by Gary Elinoff
by Cabe Atwell
by Luke James