>> 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.
Dave
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?
Thank you.
by Luke James
by Jake Hertz