Fourier Coefficients function defased

5 ビュー (過去 30 日間)
gustavo
gustavo 2023 年 9 月 1 日
回答済み: William Rose 2023 年 9 月 3 日
Hi! i have this code where i plot 3 square waves with different periods, and then i plot their Fourier coefficients, but for some reason the coefficients vector is being plotted defased, can someone identify why? I already tried to do a(k-9), a(k+11), a(k), a(k+1), but didnt solved the role problem, because it loses some values at the end ou at the beggining. The code:
function [ak, na] = coef(N1, N, n)
%COEF 1
% Determina os coeficientes de fourier
na = n;
ak = zeros(1, na(end)*2 + 1);
for k = 1:length(na)-1
if (k ~= 0) && (mod(k,N) ~= 0)
ak(k) = (sin(2*pi*(k)*(N1+0.5)/N))/(N*sin(pi*k/N));
else
ak(k) = ((2*N1)+1)/N;
end
end
end
figure(Name= "Ex 1 e 2",Position=[50 50 1200 550], Units="centimeters")
larg = 110;
n = -35:35;
N1=2;
% Onda N= 10
N=10;
[y, ny] = ondaquadrada(n,N,N1);
subplot(3,2,1);
stem(ny,y,'filled');
grid on ;
axis([-larg larg -0.5 1.2]);
ylabel('N=10');
title('Ondas');
% Coeficientes N= 10
[Y,nY]= coef(N1,N,ny);
subplot(3,2,2);
stem(nY,Y);
grid on ;
axis([-larg larg -0.5 1.2]);
ylabel('N=10');
title('Coeficientes');
% Onda N= 20
N=20;
[x, nx] = ondaquadrada(n,N,N1);
subplot(3,2,3);
stem(nx,x,'filled');
grid on ;
axis([-larg larg -0.5 1.2]);
ylabel('N=20');
% Coeficientes N= 20
[X,nX]= coef(N1,N,ny);
subplot(3,2,4);
stem(nX,X);
grid on ;
axis([-larg larg -0.5 1.2]);
% Onda N= 40
N=40;
[a, na] = ondaquadrada(n,N,N1);
subplot(3,2,5);
stem(na,a,'filled');
grid on ;
axis([-larg larg -0.5 1.2]);
xlabel('n');
ylabel("N=40");
% Coeficientes N= 40
[A,nA]= coef(N1,N,ny);
subplot(3,2,6);
stem(na,A);
grid on ;
axis([-larg larg -0.5 1.2]);
  2 件のコメント
Paul
Paul 2023 年 9 月 3 日
Hi gustavo,
Can you explain what you mean by "defased," i.e., what result are you expecting?
Also, is there a souce for the definition of the Fourier coefficients?
Finally, if you provide the function ondaquadrada it would be easier for someone to help.
Walter Roberson
Walter Roberson 2023 年 9 月 3 日
I suspect the English word is "dephased" .
That expression for fourier coefficients is suspicious, as it does not involve sqrt(-1) anywhere.

サインインしてコメントする。

回答 (1 件)

William Rose
William Rose 2023 年 9 月 3 日
You say "the coefficients vector is being plotted defased". Do you mean that you expect the coefficients vector ak, which is returned by [ak,na]=coef(), to be complex, and a(k) is not complex?
You say "it loses some values at the end ou at the beggining". To what does "it" refer? How do you know that it loses values at the end or the beginning?
As @Walter Roberson noted, the formula for the Fourier coefficient ak() does not look right. It appears that the time series of interest (y or x or a, generated by ondaquadrada()) is not passed to coef().
I suspect that the formula for ak(), inside function coef(), is a formula for the Fourier series coefficients of an even square wave, i.e. for a square wave that is symmetric about t=0. The Fourier series representation of an even function is real. Therefore it is not surprising that all Fourier coefficients of the square waves which are shown have a phase angle of zero.
Please add comments in function coef() which explain the meaning of each input and output variable. This will make it easier for others to understand your code.
Your script calls ondaquadrada(), which is not shown. I assume ondaquadrada() is similar to the built-in Matlab function square(), but ondaquadrada() has three input parameters, unlike square(). ondaquadrada() returns a signal with values 0 and +1, whereas Matlab's square() returns a signal with values -1 and +1.

カテゴリ

Help Center および File ExchangeDigital Filter Analysis についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by