필터 지우기
필터 지우기

Calculating Fourier Series Coefficients Using Custom Matlab Function

조회 수: 14 (최근 30일)
ha9981
ha9981 2012년 10월 19일
댓글: Parul Saini 2019년 7월 26일
My attempt at creating such a function where it must have the three inputs x, w0, and N:
function[ak] = cal_fs(x, w0, N)
ak = zeros(1,2*N+1); %intialize a row vector of 2N+1 zeros
T = 2*pi/w0; %calculate the period and store in T
syms t;
for k = -N:N
ak = 1/T * int(x * exp(-1i*k*w0*t), t); % ak is fourier coefficient
end
Above is my attempt. I am trying to make a vector ak that contains all the fourier series coefficents as calculated by the equation above. I am new to Matlab and highly confused as to why i do not get an output of a matrix when I do the following:
syms x;
syms t;
x = 2*t;
w0 = 62;
N = 20;
cal_fs(x,w0,N)
  댓글 수: 1
ha9981
ha9981 2012년 10월 19일
The problem is the output of cal_fs is not coming as a vector but rather a symbolic matrix 1x1. What am I doing wrong friends?

댓글을 달려면 로그인하십시오.

답변 (2개)

Alexander
Alexander 2012년 10월 22일
You forgot the index for assigning to ak. Also do you want the indefinite integral or an integral from 0 to 2*pi/w0? I added the index and changed the integral:
function[ak] = cal_fs(x, w0, N)
ak = zeros(1,2*N+1); %intialize a row vector of 2N+1 zeros
T = 2*pi/w0; %calculate the period and store in T
syms t;
for k = -N:N
ak(1,1+k+N) = 1/T * int(x * exp(-1i*k*w0*t), t, 0, T); % ak is fourier coefficient
end
  댓글 수: 1
Parul Saini
Parul Saini 2019년 7월 26일
Can we take piecewise continuous function with the same format of calculating fourier coefficients?

댓글을 달려면 로그인하십시오.


Azzi Abdelmalek
Azzi Abdelmalek 2012년 10월 22일
  댓글 수: 1
Kyon
Kyon 2016년 4월 8일
i have the RMS value and the angle values using the fourier block in simulink
what code to use to use rms and theta to plot fourier series ?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by