MATLAB Answers

How to plot delta of dirac from fourier transform result in Matlab GUI

3 views (last 30 days)
Yoav Benita
Yoav Benita on 30 Jul 2021
Answered: Walter Roberson on 5 Aug 2021
Hello everyone,
Im trying to plot any answer of fourier transform (for example) and some of the answers is delta of dirac, the problem is that the matlab GUI do not make the plot at all.
Im using symbolic.
How can i solve this problem?
this is a part of my code to ploting the answer:
elseif app.command2(1) == "fourier"
fplot(app.UIAxes, eval(app.command2(4))); % original function
fplot(app.UIAxes2,app.answer); % fourier result
Walter Roberson
Walter Roberson on 30 Jul 2021
eval() is likely to be the major error in the code, so the datatype and content matter a lot.

Sign in to comment.

Answers (2)

Ashutosh Singh Baghel
Ashutosh Singh Baghel on 5 Aug 2021
Hi Yoav,
From my understanding, you want to ‘plot’ dirac delta using MATLAB App. Updating the callback function by using “fft” function in MATLAB may solve the issue. For an example –
Ts = 1/50; %Sampling Period
t = 0:Ts:10-Ts; %time domain abscissa variable
x = sin(2*pi*15*t) + sin(2*pi*20*t); %time domain ordinate variable
y = fft(x); %take fft of x for frequency domain ordinate variable
fs = 1/Ts; %sampling frequency
f = (0:length(y) -1)*fs/length(y); %frequency domain abscissa variable
A reference guide for using 'fourier' functions can be found in the Fourier Transforms MATLAB Documentation page.

Walter Roberson
Walter Roberson on 5 Aug 2021
When you talk about the result of the fourier transform being in terms of dirac(), that tells me you are using symbolic fourier transform and that you are seeing dirac() calls in the output of fourier() calls.
fplot(app.UIAxes, eval(app.command2(4))); % original function
If app.command2(4) is a symbolic expression or symbolic function, then eval() of it is equivalent to eval() of char() of it, as if you had written
fplot(app.UIAxes, eval(char(app.command2(4)))); % original function
Depending exactly what it contains and what values have been assigned to variables, this can trigger dirac() being evaluated with a numeric argument instead of being evaluated with a symbolic number.
With sufficiently old versions of MATLAB, dirac() was not defined for numeric values, and the call would fail.
Never use eval() on a symbolic expression or symbolic function. eval() assumes that the content to be evaluated is written in MATLAB code, but char() of symbolic expressions do not result in MATLAB code, only something that is similar to MATLAB.

Community Treasure Hunt

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

Start Hunting!