Clear Filters
Clear Filters

Hi. I am having issues with having my matlab get past the ifourier part of my code. It just continually runs and is stuck at that part. The bold is where my computer is stuck.

4 views (last 30 days)
m = 10; % kg
k = 15; % N/m
b = 8;
syms x(t)
Dx = diff(x,t);
h_eqn = m*diff(x,t,2) + b*diff(x,t,1) + k*x;
Initial_conds = [x(0)==25 , Dx(0)==5];
h_solve = dsolve(h_eqn,Initial_conds);
t = linspace(0,10,1000);
ht = eval(h_solve);
syms t w
f_sym = exp(-2*t).*heaviside(t-3);
imp_sym= ht.*heaviside(t);
four_f_t = fourier(f_sym,t,w);
four_h_t = fourier(imp_sym,t,w);
X_w = four_h_t*four_f_t;
x_t = ifourier(X_w,w,t);
xt_vector = eval(x_t);
t = linspace(0,10,1000);
plot(t, xt_vector,'LineWidth',2)
  3 Comments
Justin Bryant
Justin Bryant on 31 Oct 2022
Fourier Transforms: Declare t and ω symbolically. Redefine f(t) from part B as a symbolic
equation. Use the built in function fourier() to find the Fourier transform, F(ω), of f(t). Use the built
in function fourier() to find the Fourier transform, H(ω), of h(t).
(Hint: Use the symbolic h(t) equation that you got as your output from dsolve() in part A multiplied
by the unit step function as your input to fourier().)
In the Fourier domain, calculate X(ω) as a symbolic equation. Use the built in function ifourier() to
perform the inverse Fourier transform to get x(t) as a symbolic equation. Redefine your time vector
and use eval() to calculate x(t). Plot x(t) vs. t in the figure space indicated in the diagram above and
title the plot “Fourier Transform”
Paul
Paul on 31 Oct 2022
Was dsolve() in part A used to solve an initial condition problem? If so, then all is fine, even though that doesn't make sense to me. But it only needs to make sense to you.

Sign in to comment.

Answers (1)

Star Strider
Star Strider on 29 Oct 2022
It seems to work here —
m = 10; % kg
k = 15; % N/m
b = 8;
syms x(t)
Dx = diff(x,t);
h_eqn = m*diff(x,t,2) + b*diff(x,t,1) + k*x;
Initial_conds = [x(0)==25 , Dx(0)==5];
h_solve = dsolve(h_eqn,Initial_conds)
h_solve = 
t = linspace(0,10,1000);
% ht = eval(h_solve);
ht = h_solve;
syms t w
f_sym = exp(-2*t).*heaviside(t-3);
imp_sym= ht.*heaviside(t);
four_f_t = fourier(f_sym,t,w);
four_h_t = fourier(imp_sym,t,w);
X_w = four_h_t*four_f_t;
x_t = ifourier(X_w,w,t) %
x_t = 
% xt_vector = eval(x_t);
% t = linspace(0,10,1000);
% plot(t, xt_vector,'LineWidth',2)
figure
fplot(x_t, [0 10])
grid
xlabel('t')
ylabel('x\_t')
I eliminated the eval calls. (Perhaps that could be the problem?) I also replaced the plot call with the fplot call.
.

Tags

Community Treasure Hunt

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

Start Hunting!