Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Matlab/Octave, fourier transform: Legend: x - Vector of x points [x1, x2,...], E

ID: 1290463 • Letter: M

Question

Matlab/Octave, fourier transform:

Legend:

x - Vector of x points [x1, x2,...], EQUALLY SPACED.

f - Vector of f values at those points

dx - A number, specifying the spacing x_2 - x_1.

k - Vector of k points

F - Vector of the values of F(k) at those k's.

Actual code:

function [k, F] = fourier_transform(x, f)

N = length(f);

dx = x(2) - x(1);

k = (2*pi/N/dx) * (0:(N-1));

F = dx * fft(f);

M = round(N/2);

k = [k(M+1:end)-2*pi/dx, k(1:M)];

F = [F(M+1:end), F(1:M)];

endfunction

Consider Using fourier transform, find the Fourier transform, F(k), and plot the Fourier spectrum IF(k)12 versus k. (Note: to use fourier transform, you must choose an appropriate set of equally-spaced x?s, calculate f(x) at those points, and pass those values of f(x) as the input.) In addition, derive F(k) analytically, and Plot the analytic solution for IF(k)|^2 versus k in the same graph. You do riot need to submit the source code. Consider the more complicated function Where kp = {2, 2.5, 2.75} and gamma p = {0.01, 0.02, 0.1}. Using fourier transform, find the Fourier transform of f. Hence, plot in separate figures (i) f(x) versus x, and (ii) the Fourier spectrum IF(k)12 versus k. Comment on how the Fourier spectrum?s features are related to f(x). Below is a Matlab/Octave function that numerically computes the Fourier transform of f(x), using the values of f sampled at a set of equally-spaced points {x1, X2,? , XN}.

Explanation / Answer

Q1.

k0=2;
gam=0.01;
x1=linspace(-pi,pi,1000);
f=@(x) cos(k0*x)*exp(-gam*abs(x))
y=x1;
for i=1:1000
y(i)=f(x1(i));
end
[k F]=fourier_transform(x1,y);
F1=F.^2;
plot(k,F1)
k0=2;

Q2.

k0=2;
gam=0.01;
x1=linspace(-pi,pi,1000);
kp=[2 2.5 2.75];
gam=[0.01 0.02 0.1];
f=zeros(1,3);

f1=@(x) cos(kp(1)*x)*exp(-gam(1)*abs(x)) + cos(kp(1)*x)*exp(-gam(1)*abs(x)) + cos(kp(1)*x)*exp(-gam(1)*abs(x));


y=x1;
for i=1:1000
y(i)=f1(x1(i));
end
[k F]=fourier_transform(x1,y);
F1=F.^2;
figure(2)

plot(k,F1)
k0=2;