My problem is find the output to U(t+1)-U(t-1) with Matlab given the transfer function H(s).
I know that I should be able to find the output to any input of an LTI system when given H(s), so I tried using convolution to find the output and plot it. Below is my attempt at using the conv to produce the output. Ht= dirac(t) - 4*exp(-6*t)
syms s t b
Hs=(s+2)/(s+6)
Ht=ilaplace(Hs)
tt=0:.1:60
Hnum= subs(Ht, 't',[eps:.1:10]);
%turn symbolic vector into actual
A=double(Hnum);
input=ones(1, 501);
output=conv(input,A)
figure(3)
plot(tt,output)
I also tried to use the integral way
%b is tau
t1=0;
t2=int(exp(-(6*b)),b,0,t+1)+1
t3=int(exp(-(6*b)),b,t-1,t+1)
I know that H(t)*x(t) = y(t).
I was not able to get any reasonable output for the graphs. Any hints or help are much appreciated.
Related
enter image description here
I've checked my code, which I think is ok, but can't get the right plot as in the book
here's my code:
clc,clear,close all
syms y(x) dy d2y
dy=diff(y,1)
d2y=diff(y,2)
y=dsolve((1-x)*diff(y,2)==sqrt(1+diff(y,1)^2)/5,y(0)==0,dy(0)==0)
fplot(y,[0,2],'r')
the output of y = dsolve is a vector with 2 equations as its elements. Also in the range of fplot these functions are complex. Since I don't know which results you are looking for, you can try and check these alternatives for your plot and have a look at the output:
fplot(real(y(1)),[0,2],'r')
fplot(abs(y(1)),[0,2],'r')
fplot(imag(y(1)),[0,2],'r')
I'm having some trouble with a script that I need to plot the TE and TM modes of a circular waveguide.
Everything is based on these formulas:
Right now I'm focused on the TE modes and what I have to plot is the field vector e_mn'' inside a squared-mesh equal to the radius of the waveguide.
To do it I need to compute the bessel function of the first kind and extract x_mn that correspond to the n-th root in which the function is equal to zero. These points are supposed to be real but positive.
I followed this example
https://www.mathworks.com/examples/matlab/community/22719-roots-of-a-bessel-function
but I get an error:
Undefined function 'isfinite' for input arguments of type> 'function_handle'. Error in roots (line 26) if ~all(isfinite(c)) Error
in circular (line 20)
x_mn=roots(J0)
This is my code. Can you help me?
clc
clear all
close all
a=20; %radius
m=0;
n=1;
%%
if m==0
ki_m=1;
else
ki_m=sqrt(2);
end
r=0:0.1:a;
J0 = #(r) besselj(0,r);
%J0 = besselj(m,r);
%plot(J0)
x_mn=roots(J0)
%plot(J0(x_mn))
%x_mn=abs(x_mn);
k_mn=x_mn./a;
F_mn=(ki_m*k_mn)./(J0(x_mn)*sqrt(pi*(x_mn^2-m^2)));
for r=0:1:a
for phi=0:1*pi/180:2*pi
e_mnR=-F_mn.*(J0(k_mn*r)/(k_mn.*r))*sin(m*phi);
e_mnPHI=F_mn.*J0(k_mn*r)*cos(m*phi);
end
end
e_mnR=abs(e_mnR);
e_mnPHI=abs(e_mnPHI);
X=0:1:a;
[X,Y] = meshgrid(1:1:a);
quiver(X,Y,e_mnR,e_mnPHI);
hold on
This is not my area of expertise so take this with a grain of salt, but I did some googling and think I know what's going on:
The code you are working from in the provided link defines:
J0 = chebfun(#(x) besselj(0,x),[0 100]);
Note the link from your reference to a Chebfun example is dead, but I read here that:
Chebfun is an open-source package for computing with functions to about 15-digit accuracy. Most Chebfun commands are overloads of familiar MATLAB commands...
The only reason the example you cited works is because J0 is defined using Chebfun, which overloads the matlab command roots with its own version that works on a function handle. Maybe read more here and try using this tool if you want to replicate that code example. Hope this helps...
You can use fzero instead of roots, but you confused polar and cartesian coordinates in the plot section and dimensions of vectors don't agree
I have been having a big problem understanding the concept of numerical ifft.
Consider a function in spatial domain like f(x)=-2/pi*Ln(abs(x)) in which x is between -Lx and Lx. The fourier transform of this function is F(w)=2/abs(w).
I want to figure out whether these two are numerically the same using ifft command in Matlab. If you run the simple code below, you will see the difference that bothers me:
clc
clear all
Lx=0.0005;
N=pow2(10);
dx=2*Lx/(N-1);
w=pi/(N*dx)*linspace(-N/2,N/2,N);
Hw=2./abs(w);
hx=1/dx*abs(fftshift(ifft(Hw)));
x=linspace(-Lx,Lx,N);
hxexact=-2/pi.*log(abs(x));
plot(x,hx,x,hxexact,'r')
legend('ifft','exact')
here is the output:
I would appreciate that if anyone could help me with this.
You seem to have some confusion about the FFT for your function, the result you might have been looking for is:
sqrt(2./pi) / w
This is the fft of your function IFF w is positive!
This is the FFT in the general case:
If you use MATLAB's fft function instead of using your own 2./abs(w) you will see that the ifft and the original function align.
I'm trying to plot the transfer function in time domain - h,
when I run the following code I get an error:
syms s;
H=((1+2*s)*1.943)/(s*(s^2)*(1+0.15*s)+((1+2*s)*1.943));
h = ilaplace(H);
ezplot(h);
I read the help on ilaplace and understood it returns a sym function.
what am I missing?
I tried to look up on the internet and I didn't find an example that perform what I want without errors.
if it is relevant I'm using 7.12.0 (R2011a)
thanks
If you look at the expression for h, I bet you'll find it's not a straightforward expression of t, and it's not something that can be plotted by MATLAB due to the complexity of the equation. You might want to try substituting some numerical values of t with subs to get the corresponding values of h, which you could then plot using the plot command, but I don't know if this will work owing to the complexity of the inverse Laplace transform expression.
If I have an RC circuit with transfer function 1/(1+sRC) how do I draw the transfer function using MATLAB?
Num2=[1];
Den2=[R*C 1];
RCcirc=tf(Num2,Den2);
How do I declare the R and the C so that there are no errors?
tf is the wrong tool for plotting the transfer function. Try these instead:
Use linspace to generate a range of values for s. Give R and C reasonable values of your choice.
Read up on arithmetic operations in MATLAB, especially ./
Look at how to use plot and familiarize yourself with the command using some simple examples from the docs.
With these you should be able to plot the transfer function in MATLAB :)
First of all you need to understand what transfer function you want. Without defined values of R and C you won't get any transfer function. Compare it to this, you want to plot a sine wave: x = sin(w*t), I hope you can agree with me that you cannot plot such a function (including axes) unless I specifically say e.g. t is the time, ranging from 0 seconds to 10 seconds and w is a pulsation of 1 rad/s. It's exactly the same with your RC network: without any values, it is impossible for numerical software such as MATLAB to come up with a plot.
If you fill in those values, you can use th tf function to display the transfer function in whatever way you like (e.g. a bode plot).
On the other hand, if you just want the expression 1/(1+s*R*C), take a look at the symbolic toolbox, you can do such things there. But to make a plot, you will still have to fill in the R and C value (and even a value for your Laplace variable in this case).