What error message?Hi Guys
I am trying to find a problem with this program.
This is the question I was given:
Using the MATLAB function integ (below) write an m–file to calculate the first 50 pairs of coefficients An and Bn which express a saw-tooth wave as a Fourier Series. Your code should define one period of the saw-tooth wave x(t) and call the function integ to perform the appropriate integration.
function [area] = integ(x,t)
% integ is a function which calculates an approximation
% to the integral of x(t) between the limits t(1) (the
% first value of the array t) and t(end) (the last value
% of the array t). It is assumed that the points in t are
% equally spaced a distance dt apart.
dt=t(2) – t(1);
area = area + (x(k)+x(k+1))*dt/2
This is what I have written:
Code for 50 coefficients:
t = [-0.5:dt:0.5];
T = 1;
f = 1/T;
for n = 1:1:50
for k= 1:1:50
y=y + a(k)*(cos(2*pi*k*f*t))+ b(k)*(sin(2*pi*k*f*t));
Its giving an error when you run it.
Can someone help me to fix this please?