简体   繁体   中英

FFT in Octave/Matlab, Plot cos(x) and approximate with

I have to plot in a exercise cos(x) in Octave and interpolate it by

在此处输入图片说明

I plotted cos(x) with

fplot("[cos(x)]", [0, 2*pi])

n are equidistant supporting points on [0, 2*pi] that I calculate by

x = zeros(n,1);
for i=1:n
    x(i,1)= (-1) + (i-1/2)*(2/n);
end

How do I plot the term to approximate it?

I am also confused about what is the question actually. I guess you want to plot that formula.

Have a row vector k = 0:(n/2 - 1) (suppose n even).

Then you need your d coefficients as a row vector of the same length. (I don't know from where you get them though)

Then define your column vector x (column vector is made from a row vector by transposing, eg x = x.' )

Left term of the function is then

leftterm = sum(d .* exp(i * x * k), 2)

Right term:

rightterm = sum( fliplr(d) .* exp(- i * x * (k.+1)), 2)

Alltogether they give:

f = sum(d .* exp(i * x * k) + fliplr(d) .* exp(- i * x * (k .+ 1)), 2)

and you plot it with:

plot(x,f)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM