The fourier series coefficient phase
I am trying to get the x[n] from fourier coefficients, then I used the fft to find the coefficients of my x[n] and compare it with the prompt. So Here is the code
N = 8; % the period
figure;
k = -4:3; % the index for fourier transform
a_k = [0,0,1,1,1,1,1,0]; % fourier series
subplot(2,2,1);
stem(k,abs(a_k)); % plot the magnitude of the fourier coefficient
xlabel(‘k’); ylabel(‘|a_k|’); title(‘Magnitude of the Fourier Series Coefficient Directly From Prompt’); %xlabel tilte and ylabel
subplot(2,2,3);
stem(k,angle(a_k)); % plot the phase of the fourier coefficient
xlabel(‘k’); ylabel(‘phase of a_k’); title(‘Phase of the Fourier Series Coefficient Directly Prompt’);%xlabel title and ylabel
x = zeros(1,N);
n = -4:3; % the n matrix
w = 2*pi/N; % omega
A = [1,2,2,0,0,0,0,0]; % the cos wave amplitude
phi = [0,0,0,0,0,0,0,0]; % the phase
for i = 1:N
x = x+A(i)*cos((i-1)*w*n+phi(i));
end
ak_re = fft(fftshift(x)); % the coefficients
ak_shifted = fftshift(ak_re); % shifted version
subplot(2,2,2);
stem(k,abs(ak_shifted)/N);% stem plot
xlabel(‘k’); ylabel(‘|a_k|’); title(‘Magnitude of the Fourier Series Coefficient by FFT’); %xlabel tilte and ylabel
subplot(2,2,4);
stem(k,angle(ak_shifted));% stem plot
xlabel(‘k’); ylabel(‘phase of a_k’); title(‘Phase of the Fourier Series Coefficient by FFT’);%xlabel title and ylabel
x_re = N*fftshift(ifft(ifftshift(a_k))); % Rebuilt x[n]
figure;
subplot(1,2,1);
stem(n,x_re); % plot the original graph
xlabel(‘n’); ylabel(‘x[n]’); title(‘Plot of x[n] Rebuilt from Coefficients’); %xlabel tilte and ylabel
subplot(1,2,2);
stem(n,x); % stem plot
xlabel(‘n’); % xlabel of the x[n]
ylabel(‘x[n]’); % ylabel
title(‘Plot of x[n] Directly from Expression’); % title
I find out that x[n] plots are same, but a_k plots are a little bit off on phase plots. Apparently the Phase of the Fourier Series Coefficient by FFT is not equal to the original phase of the coefficients by prompt. They are like half periods off. So I tried to use fftshift, but it did not help. So please let me know what is wrong here.I am trying to get the x[n] from fourier coefficients, then I used the fft to find the coefficients of my x[n] and compare it with the prompt. So Here is the code
N = 8; % the period
figure;
k = -4:3; % the index for fourier transform
a_k = [0,0,1,1,1,1,1,0]; % fourier series
subplot(2,2,1);
stem(k,abs(a_k)); % plot the magnitude of the fourier coefficient
xlabel(‘k’); ylabel(‘|a_k|’); title(‘Magnitude of the Fourier Series Coefficient Directly From Prompt’); %xlabel tilte and ylabel
subplot(2,2,3);
stem(k,angle(a_k)); % plot the phase of the fourier coefficient
xlabel(‘k’); ylabel(‘phase of a_k’); title(‘Phase of the Fourier Series Coefficient Directly Prompt’);%xlabel title and ylabel
x = zeros(1,N);
n = -4:3; % the n matrix
w = 2*pi/N; % omega
A = [1,2,2,0,0,0,0,0]; % the cos wave amplitude
phi = [0,0,0,0,0,0,0,0]; % the phase
for i = 1:N
x = x+A(i)*cos((i-1)*w*n+phi(i));
end
ak_re = fft(fftshift(x)); % the coefficients
ak_shifted = fftshift(ak_re); % shifted version
subplot(2,2,2);
stem(k,abs(ak_shifted)/N);% stem plot
xlabel(‘k’); ylabel(‘|a_k|’); title(‘Magnitude of the Fourier Series Coefficient by FFT’); %xlabel tilte and ylabel
subplot(2,2,4);
stem(k,angle(ak_shifted));% stem plot
xlabel(‘k’); ylabel(‘phase of a_k’); title(‘Phase of the Fourier Series Coefficient by FFT’);%xlabel title and ylabel
x_re = N*fftshift(ifft(ifftshift(a_k))); % Rebuilt x[n]
figure;
subplot(1,2,1);
stem(n,x_re); % plot the original graph
xlabel(‘n’); ylabel(‘x[n]’); title(‘Plot of x[n] Rebuilt from Coefficients’); %xlabel tilte and ylabel
subplot(1,2,2);
stem(n,x); % stem plot
xlabel(‘n’); % xlabel of the x[n]
ylabel(‘x[n]’); % ylabel
title(‘Plot of x[n] Directly from Expression’); % title
I find out that x[n] plots are same, but a_k plots are a little bit off on phase plots. Apparently the Phase of the Fourier Series Coefficient by FFT is not equal to the original phase of the coefficients by prompt. They are like half periods off. So I tried to use fftshift, but it did not help. So please let me know what is wrong here. I am trying to get the x[n] from fourier coefficients, then I used the fft to find the coefficients of my x[n] and compare it with the prompt. So Here is the code
N = 8; % the period
figure;
k = -4:3; % the index for fourier transform
a_k = [0,0,1,1,1,1,1,0]; % fourier series
subplot(2,2,1);
stem(k,abs(a_k)); % plot the magnitude of the fourier coefficient
xlabel(‘k’); ylabel(‘|a_k|’); title(‘Magnitude of the Fourier Series Coefficient Directly From Prompt’); %xlabel tilte and ylabel
subplot(2,2,3);
stem(k,angle(a_k)); % plot the phase of the fourier coefficient
xlabel(‘k’); ylabel(‘phase of a_k’); title(‘Phase of the Fourier Series Coefficient Directly Prompt’);%xlabel title and ylabel
x = zeros(1,N);
n = -4:3; % the n matrix
w = 2*pi/N; % omega
A = [1,2,2,0,0,0,0,0]; % the cos wave amplitude
phi = [0,0,0,0,0,0,0,0]; % the phase
for i = 1:N
x = x+A(i)*cos((i-1)*w*n+phi(i));
end
ak_re = fft(fftshift(x)); % the coefficients
ak_shifted = fftshift(ak_re); % shifted version
subplot(2,2,2);
stem(k,abs(ak_shifted)/N);% stem plot
xlabel(‘k’); ylabel(‘|a_k|’); title(‘Magnitude of the Fourier Series Coefficient by FFT’); %xlabel tilte and ylabel
subplot(2,2,4);
stem(k,angle(ak_shifted));% stem plot
xlabel(‘k’); ylabel(‘phase of a_k’); title(‘Phase of the Fourier Series Coefficient by FFT’);%xlabel title and ylabel
x_re = N*fftshift(ifft(ifftshift(a_k))); % Rebuilt x[n]
figure;
subplot(1,2,1);
stem(n,x_re); % plot the original graph
xlabel(‘n’); ylabel(‘x[n]’); title(‘Plot of x[n] Rebuilt from Coefficients’); %xlabel tilte and ylabel
subplot(1,2,2);
stem(n,x); % stem plot
xlabel(‘n’); % xlabel of the x[n]
ylabel(‘x[n]’); % ylabel
title(‘Plot of x[n] Directly from Expression’); % title
I find out that x[n] plots are same, but a_k plots are a little bit off on phase plots. Apparently the Phase of the Fourier Series Coefficient by FFT is not equal to the original phase of the coefficients by prompt. They are like half periods off. So I tried to use fftshift, but it did not help. So please let me know what is wrong here. matlab, fft, ifft, fftshift MATLAB Answers — New Questions









