What is the Best Approach for Solving a Fourier Coefficient Problem in MATLAB?

In summary: The conversation is about a problem in evaluating Fourier coefficients for an array of numbers representing a magnetic field on a circle. The person has written a code in MATLAB and used some built-in functions, but is not getting the correct results. They are seeking advice on how to improve their code and explain the units in the Fourier domain. The expert suggests that errors in evaluating Fourier coefficients
  • #1
1Keenan
101
4
Hi all,

I have a problem in evaluating Fourier coefficient.
I have an array of numbers (which is a magnetic field) taken on a circle of radius 8mm and I want to know the harmonics of this field.

I have written a code in matlab, I have used some in built function in MATLAB and mathcad, but I can get the correct results.

Any advise?

my code is:

Code:
x=Bx(:,4); 

passo=length(x);
period = 2*pi ;
t=linspace(0,period,passo);
t=t';   
Tc=t(2)-t(1); 
T = max(t)-min(t); 
C = 2/T; 
omega = (2*pi/T);



n_armoniche =16;

a0 = C*sum(x)*Tc;



for k=1:n_armoniche
  
    
    
    a(k)=C*sum(x.*cos(omega*k.*t))*Tc; 
    b(k)=C*sum(x.*sin(omega*k.*t))*Tc; 
    c(k)= sqrt(a(k)^2+b(k)^2);
    phi(k)=atand(b(k)/a(k));
      
end

    

xvalues = a0/2*ones(length(t),1);

for kval=1:n_armoniche

        xvalues=xvalues+a(kval)*cos(omega*kval.*t);
        xvalues=xvalues+b(kval)*sin(omega*kval.*t);
    
end

figure()
subplot(3,1,1)
plot(t,x, 'Linewidth', 2)
hold on
plot(t,xvalues,'r','Linewidth', 2)
xlabel('t')
ylabel('function')
axis([min(t) max(t) -inf inf])



subplot(3,1,2)
plot(t, a0/2*ones(1,length(t)), 'Linewidth', 2)
hold all
for kval = 1:n_armoniche
    plot(t,a(kval)*cos(omega*kval.*t), 'Linewidth', 2)
    plot(t,b(kval)*cos(omega*kval.*t), 'Linewidth', 2)
end
xlabel('t')
ylabel('function')
title('Armoniche')
grid on
legend('a0','a1','b1','a2','b2','a3','b3','a4','b4','...')
axis([min(t) max(t) -inf inf])


subplot(3,1,3)
plot(t, a0/2*ones(1,length(t)), 'Linewidth', 2)
hold all
for kval = 1:n_armoniche
    plot(t,c(kval)*cos(omega*kval.*t+phi(kval)), 'Linewidth', 2)
   
end
xlabel('t')
ylabel('function')
title('Armoniche in forma polare')
grid on
legend('c0','c1','c2','c3','c4','c5','c6','c7','c8','...')
axis([min(t) max(t) -inf inf])
 
Physics news on Phys.org
  • #2
You need to explain your code better - it is impossible for a third party to understand what you are trying to do...

In my experience, errors in evaluating Fourier coefficients come down to calculating the units in the Fourier domain. Basic rule of thumb is that the domain size (in real space) determines the minimum frequency interval, and that the minimum spatial interval determines the maximum frequency (divided by 2 - because you need to include negative frequencies in your allowed bandwidth).

Claude.
 
  • #3
YOu are right, I'm posting my code, the main part at least, with some comment, hopfully you may help me. I think in my case the error comes down from a bad definition of the period and, I'm not sure, problably it is also related to the fact that I'm analizing a set of data, not a continuous function.

x=Bx(:,4); %Vector of data to be analysed

passo=length(x); %number of element in x
period = 2*pi ; %period of the vector, it is actually evaluated on a circle with fixed radius
t=linspace(0,period,passo);
t=t';
Tc=t(2)-t(1); %sampling intervat
T = max(t)-min(t);
C = 2/T; %constant of integrals
omega = (2*pi/T);
n_armoniche =16; %number of coefficients to be evaluated

a0 = C*sum(x)*Tc; % a0 coefficient
for k=1:n_armoniche
a(k)=C*sum(x.*cos(omega*k.*t))*Tc; %an coefficients
b(k)=C*sum(x.*sin(omega*k.*t))*Tc; %bn coefficients
c(k)= sqrt(a(k)^2+b(k)^2); %modulus of comeplex coefficient
phi(k)=atand(b(k)/a(k)); %phase

end
 

What is the Fourier Coefficient Problem?

The Fourier Coefficient Problem is a mathematical concept that is used to decompose a function into a sum of simple sine and cosine functions. It is a method of representing a complex function as a combination of simpler functions, and is commonly used in signal processing, image processing, and other areas of science and engineering.

How is the Fourier Coefficient Problem solved?

The Fourier Coefficient Problem is solved using a mathematical formula called the Fourier series. This formula involves calculating the coefficients of the sine and cosine functions that make up the original function. These coefficients can be found by integrating the original function over a specific interval.

What is the significance of the Fourier Coefficients?

The Fourier Coefficients represent the amplitude and phase of the individual sine and cosine functions that make up the original function. They provide valuable information about the frequency components present in the original function, and can be used to analyze and manipulate the function in various ways.

What are some applications of the Fourier Coefficient Problem?

The Fourier Coefficient Problem has many applications in science and engineering. It is used in signal processing to analyze and filter signals, in image processing to compress and enhance images, and in physics to study the properties of waves. It is also used in music and acoustics to analyze and synthesize sounds.

What are some common challenges in solving the Fourier Coefficient Problem?

One common challenge in solving the Fourier Coefficient Problem is determining the appropriate interval over which to integrate the original function. This can be difficult for functions that are not periodic. Another challenge is dealing with functions that have discontinuities or sharp changes, as this can affect the convergence of the Fourier series. Additionally, finding the exact values of the coefficients can be computationally intensive for complex functions.

Similar threads

  • Other Physics Topics
Replies
1
Views
1K
  • Advanced Physics Homework Help
Replies
1
Views
748
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
6
Views
3K
Replies
5
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
819
Replies
1
Views
1K
  • Introductory Physics Homework Help
Replies
17
Views
372
  • Other Physics Topics
Replies
2
Views
987
  • Introductory Physics Homework Help
Replies
10
Views
912
Back
Top