Bodeplot of a differential equation using a fourier transform in MATLAB - matlab

I have a second order differential equation which I want to transform to the frequency domain using a fourier transform from which I can create a bode plot using matlab.
I have transformed the equation by hand already, but I can't seem to find documentation on how to get the bode plot going. The bodeplot accepts a laplace transform functions from what I have read.
So my question is, how can I define a function in the frequency domain in order to create a bode plot with said function?
Another thing I am curious about is how I can take a differential equation in matlab and transform it into the frequency domain using fourier?
The differential equation is attached below.

Use the Laplace transform to get the transfer function from the differential equation:
Y(s)/X(s) = 1/(10*s^2+0.1*s+1)
In MATLAB, this is defined easily (you need the Control System Toolbox) with the tf function:
H = tf(1,[10 0.1 1]);
and then you can use the bode function to get the bode plot:
bode(H)

Related

Matlab quadratic equation/convolution

I've got a convolution where the final result is
y=(-t/2)+5t=6
Is there any chance to check this in matlab but not through convolution, I have programmed that part. What I am wondering is it possible to plot the signal using this equation and compare it with the one that I got with coding convolution.
You can plot functions easily in matlab: look at the examles from here.
For example using this code:
t = 0:.1:10
plot(t,(-t/2)+5*t)
will plot you your function between the values x = [0, 10].

I need help in computing the frequecines of fourier coeffients using MATLAB after applying the fft2 and fftshift on map data

I need help in implementing a MATLAB code to compute the frequency of the Fourier coefficients for 2D data. I first applied MATLAB's fft2 on the data followed by the fftshift, all I need to do now is compute the f=sqrt(fx*fx+fy*fy) such that fx is the coefficients along the columns and fy is the coefficients along the rows.
data=data-mean(data(:))
dft=fft2(data,1024,1024);
dftshift=fftshift(dft);
wn=2*pi/1024
cx=floor(1024/2)+1
for I=1:1024
for J=1:1024
freqx=(I-cx)*wn;
freqy=(J-cy)*wn;
freq=sqrt(freqx*freqx+freqy*freqy);
end
end

Find transfer function from bode plot in matlab

I have obtained the bode plot for a system. The system seems to have a very complex magnitude and phase plot. It's not possible to find the transfer function manually. Is there a way of finding the transfer function from the magnitude and phase data, in Matlab?
Here's my code:
%%FFT method for finding Transfer Function
load testdata2.mat;
input = fft(signal(:,1));
% FFT of input data
output = fft(signal(:,2));
% FFT of output data
fft_ratio = output ./ input;
subplot(2,1,1)
%Magnitude
semilogx(20*log10(abs(fft_ratio)))
subplot(2,1,2)
%Phase
semilogx((180/pi)*angle(fft_ratio))
mag = 20*log10(abs(fft_ratio));
phase = (180/pi)*angle(fft_ratio);
Here's my data.
I don't believe so, and that's not Matlab's fault. The problem is mathematically nontrivial because there can be poles and zeros of the transfer function that lie at large imaginary frequency. These might not significantly affect the Bode plot, but how would you rule out their existence?
I think your best bet is to fit the Bode plot to a rational transfer function, and just keep increasing the number of poles and zeros in the transfer function until you get acceptable agreement.

Extract data from curve fit toolbox

I am using matlab and I have a certain set of x and y data,
x=[0,1.25,1.88,2.5,5,6.25,6.88,7.19,7.5,10,12.5,15,20];
y=[-85.93,-78.82,-56.95,-34.56,-33.57,-39.64,-41.96,-49.28,-66.6,-66.61,-59.16,-48.78,-41.53];
I want to use the curve fitting toolbox which has the spline function to generate a graph, so i did this,
cftool
It would bring me to the toolbox which i can then choose the spline fit. I was thinking if its possible that i extract the data points from the spline graph generated. Which means i probably would have more x and y data points than those that i input in, since the spline graph is sort of a continuous graph. Anyone could give me some advice on this? Thanks!
You can perform the equivalent of the spline fit performed with cftool with fit, see for instance here, here, or here:
% perform spline fit without cftool
ft = fittype('cubicspline');
coeff=fit(x,y,ft);
% use plot to display the interpolating polynomial
% (relying on internal plot settings)
figure
h=plot(coeff,x,y,'o');
% extract the *interpolated* curve from the figure
xi=get(h,'XData');
yi=get(h,'YData');
Replot it just to show that we can:
But if you just want to interpolate do as Fraukje explained here. Define a finer grid on x and use the interp1 function, as in the following example (same x,y input data as before):
% interpolate
Ni = 100;
xi = linspace(x(1),x(end),Ni);
yi = interp1(x,y,xi,'spline');
Now xi,yi is the interpolated data:

Linear regression line in MATLAB scatter plot

I am trying to get the residuals for the scatter plot of two variables. I could get the least squares linear regression line using lsline function of matlab. However, I want to get the residuals as well. How can I get this in matlab. For that I need to know the parameters a and b of the linear regression line
ax+b
Use the function polyfit to obtain the regression parameters. You can then evaluate the fitted values and calculate your residuals accordingly.
Basically polyfit performs least-squares regression for a specified degree N which, in your case will be 1 for straight line regression. The regression parameters are returned by the function and you can use the other function polyval to get the fitted values from the regression parameters
If you have the curve fitting toolbox, type cftool and press enter and the GUI will appear.
You can use this tool to find a linear polynomial fit for a given data set, as well as many other fits.