How can i solve this problem

I can't fill the answers Coefficients [c....] and %fill here for proper ... of C(k)

Answers (1)

Show me what you have tried for the C(k) equation above.
function C= FourierSeries(x,MaxK)
N=length(x);
n=0:N-1;
for k=1:2*MaxK+1
C(k)=%your equation look at sum() exp() .*
end

9 Comments

C(k) is
Show me your code for it and ask a specific question.
T = 1 ; % suppose the period of a signal is 1 sec
N = 256 ; % we divide 1 sec into 256 time slice
dt = T/N ; % Sampling period
TimeSpan = 2 ;
t = -TimeSpan : dt : TimeSpan ;
%Now we can represent any periodic function x(t) using t vector
x1 = sin(2*pi*t);
plot(t, x1) ;
Tp = 0.2 ;
x2 = 0 ;
for ii = -TimeSpan : T : TimeSpan
x2 = x2 | ( t >= (ii-Tp) & t < (ii+Tp)) ;
end
plot(t, x2) ;
x3 = mod(t,1) ;
plot(t,x3) ;
% Now we will compute Ck using FourierSeries
% function
function C = FourierSeries(x, MaxK)
% this function returns FS coefficients of 2*MaxK+1
Coefficients[ 𝑪−𝒎𝒂𝒙𝑲𝑪−𝒎𝒂𝒙𝑲+𝟏 … 𝑪−𝟏 𝑪𝟎 𝑪𝟏 … 𝑪𝒎𝒂𝒙𝑲]
% Note that C(1) means 𝑪−𝒎𝒂𝒙𝑲 , C(2*MaxK+1) means 𝑪𝒎𝒂𝒙𝑲
N = length(x) ;
for k = 1 : 2*MaxK+1
% Fill here for proper computation of C(k)
end
C = C/ N ;
% cut only one period of signal
x1T = x1(find(t==0) : find(t==T)-1) ;
x2T = x2(find(t==0) : find(t==T)-1) ;
x3T = x3(find(t==0) : find(t==T)-1) ;
% Calculate Fourier Series Coefficients
Kmax = 50 ;
C1 = FourierSeries(x1T, Kmax) ;
C2 = FourierSeries(x2T, Kmax) ;
C3 = FourierSeries(x3T, Kmax) ;
% Check and plot the FS Coefficients
figure(4) ;
k = -Kmax : Kmax ;
stem(k, abs(C1));
% axis, labeling, title, grid here
figure(5) ;
k = -Kmax : Kmax ;
stem(k, abs(C2));
% axis, labeling, title, grid here
figure(6) ;
k = -Kmax : Kmax ;
stem(k, abs(C3));
% axis, labeling, title, grid here
% Suppose we only represent x(t) using C(-3),C(-2), C(-1), C(0), C(1), C(2), C(3)
KuseMax = 3 ;
% initial setting to zero for accumulation
x1_hat = zeros(size(t)) ;
x2_hat = zeros(size(t)) ;
x3_hat = zeros(size(t)) ;
for kk = -KuseMax : KuseMax
x1_hat = x1_hat + C1(find(k == kk))* exp(1j*(2*pi*kk/T*t)) ;
x2_hat = x2_hat + C2(find(k == kk))* exp(1j*(2*pi*kk/T*t)) ;
x3_hat = x3_hat + C3(find(k == kk))* exp(1j*(2*pi*kk/T*t)) ;
end
% Now let’s compare the original signal with reconstructed signal
figure(7) ;
plot(t,x1, t, x1_hat) ;
legend('x_1(t)','x\_hat_1(t)');
figure(8) ;
plot(t,x2, t, x2_hat) ;
legend('x_1(t)','x\_hat_1(t)');
figure(9) ;
plot(t,x3, t, x3_hat) ;
legend('x_1(t)','x\_hat_1(t)');
------------------------------------------
Coefficients[ 𝑪−𝒎𝒂𝒙𝑲𝑪−𝒎𝒂𝒙𝑲+𝟏 … 𝑪−𝟏 𝑪𝟎 𝑪𝟏 … 𝑪𝒎𝒂𝒙𝑲] IS ERROR
% Fill here for proper computation of C(k) have to be filled
What have you done? I am not going to write the computation of C(k) for you, but I can help you once you have made an effort and ask a specific question.
% Fill here for proper computation of C(k)
i think it's
for k = 1 : 2*MaxK+1
for n = 0 : N-1
C= n * exp((-j*2*phi*k*n)/N);
C(k)=C(k)+C;
end
end
N=length(x);
for k = 1 : 2*MaxK+1
C(k)=0;%must initially set to zero
for n = 0 : N-1
c= x(n+1) * exp((-1j*2*pi*k*n)/N);%you need x(n+1) and not n (look at your equation). pi is a constant not phi. 1j or 1i is amaginary whereas i or j are variables.
C(k)=C(k)+c;%need to change the variable name of what you are adding
end
C(k)=C(k)/N;%once the sum is completed you need to do the final division by N.
end
Alturnatively, you would not need the inner for-loop if you use sum() and do element-wise operations.
N=length(x);
n=0:N-1;
for k=1:2*MaxK+1
C(k)=sum(x.*exp(-1j*2*pi*k*n/N))/N;
end
and also
to solve this problem
i made
Coefficients [-Kmax:1:Kmax]
but it said that it's wrong
what should i do
What should the coefficients be? The coefficients are complex, do you know if you are suppose to report only the magnitude?
In MATLAB, [] is only used for building lists (and arrays) . [] is really the horzcat() or vertcat() function. The only place that [] is ever used for indexing in MATLAB is inside the Symbolic Engine, in the MuPAD programming language.

Sign in to comment.

Tags

Asked:

on 28 Oct 2021

Commented:

on 28 Oct 2021

Community Treasure Hunt

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

Start Hunting!