Problem 7 Matlab Exercise In this problem you will calculate the accuracy of the
ID: 2965085 • Letter: P
Question
Problem 7 Matlab Exercise In this problem you will calculate the accuracy of the fourier series as a function of the number of terms used. Let f(z) be a rectangular function in the interval [0, 2T] -1 for 0 z f(a) 1 for S z 2T Calculate the fourier coefficients of the exponential fourier series (that is, you can elim- inate the real parts directly without calculations). Now plot the mean-square error If (a) Co explirn) 2 -M as a function of M for a convenient number of harmonics M (example: ME (1,20).Explanation / Answer
Calculate the Fourier coefficients of the series expansion of a function, and the amplitude and phase spectra. The script contains some theory and 3 different methods to calculate the coefficients.
USAGE
fourier_coeff(fun,t0,T)
fourier_coeff(fun,t0,T,M)
fourier_coeff(fun,t0,T,M,N)
fourier_coeff(fun,t0,T,M,N,method)
fourier_coeff(fun,t0,T,M,N,method,res)
fourier_coeff(fun,t0,T,M,N,method,res,num_P)
INPUT
- FUN: character string representing the function with "t" as the independent variable (e.g. '10*cos(2*pi*3*t-pi/4)'). Dot-arithmetic operators must be used (.* ./ . .^). FUN must be defined for [T0,T0+T]
- T0: initial "t" for the definition of FUN
- T: period of the function
- M: number of frequencies (default: 5)
- N: number of data points per period (default: 100)
- METHOD: 1 (least-squares), 2 (integrals [default]) or 3 (FFT)
- RES: 1 (plot results) or 0 (do not plot [default])
- NUM_P: number of periods the function will be sampled at (default: 1)
OUTPUT
- FREQ: frequencies
- COEFF: Fourier series coefficients in the form in the form [a0 a1 ... aM b1 ... bM], where f(t) = a0 + sum_{m=1}^M { a_m cos(2pi m t/T) + b_m sin(2pi m t/T) }
So the corresponding frequencies are: 0, 1/T, 2/T, ..., M/T
- APSPEC: the first column contains the amplitude spectrum, and the second column the phase spectrum
- If RES=1:
Figure the original function and the Fourier series expansion, and another with the amplitude and phase spectra
FOR MEAN SQUARE PLOT
ev=EvalHeartSet(:,end);
rmse(1)=norm(evu(1,:)-ev)/sqrt(length(evu(1,:)));
rmse(2)=norm(evu(2,:)-ev)/sqrt(length(evu(2,:)));
subplot(2,1,1);
if rmse(1)<rmse(2)
r=1;
else
r=2;
end
str=sprintf('Testing Set RMSE: %f',rmse(r));
disp(str);
ctr=0;
for i=1:m
if evu(r,i)==ev(i)
ctr=ctr+1;
end
end