Recreate sin(x) using ifft

I'm currently working on a tool that can fouirer decompose a function into its Fourier series using the fft function. The decomposition is working fine, but I'm having some issues with my inverse function, i.e. summing the series back together. Here I use ifft for speed. In a simplified version of my code, I do my fourier decomposition like this:
N = 3 % The number of terms I want in my Fourier decomposition
x = linspace(0,2*pi,N+1); % As I am using f = sin(x) in this example, three modes is sufficient to fully describe the function
x = x(1:end-1) % create an open interval
f = sin(x)
fk = fft(f/N)
fk = fftshift(fk) % Now fk should be [0.5i, 0, -0.5i]
I now want to use this as an input into ifft and recreate the sin(x). However, the return vector from ifft is only three elements long. Is there anyway I can have ifft(fk) return sin(x) in a 100 point resolution rather than only 3 points?

1 Comment

clear all;clc;
syms x n pi
% pi=3.14;
sum=0;
y=x %function you want
a0=(1/pi)*int(y,x,-pi,pi)
% for n=1:5
%finding the coefficients
an=(1/pi)*int(y*cos(n*x),x,-pi,pi)
bn=(1/pi)*int(y*sin(n*x),x,-pi,pi)
sum=a0/2+(an*cos(n*x)+bn*sin(n*x))
% end
ezplot(x,y,[-pi,pi])
grid on;hold on;
ezplot(x,(sum+a0/2),[-pi,pi])
% https://www.instagram.com/koroshkorosh1/
syms x pi
F =(1/pi) * int(x^2+5*x,'Hold',true)
bn=(1/pi)*int(y*sin(n*x),x,-pi,pi), G = bn
Gcalc = release(G)
Fcalc = int(bn)
clear all;clc;
syms x pi n
% pi=3.14;
sum=0;
y= x + (x^2) ; %function you want
a0=(1/pi)*int(y,x,-pi,pi)
% for n=1:3
%finding the coefficients
an=(1/pi)*int(y*cos(n*x),x,-pi,pi)
bn=(1/pi)*int(y*sin(n*x),x,-pi,pi)
sum=sum+(an*cos(n*x)+bn*sin(n*x))
% end
% https://www.instagram.com/koroshkorosh1/
ezplot(x,y,[-3.14,3.14]);
grid on;hold on;
ezplot(x,(sum+a0/2),[-3.14,3.14])
% https://www.instagram.com/koroshkorosh1/

Sign in to comment.

Answers (0)

Products

Release

R2018a

Community Treasure Hunt

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

Start Hunting!