Question

In: Electrical Engineering

During lab 4, we have seen numerical implementation of Fourier Series for periodic signals. As first...

During lab 4, we have seen numerical implementation of Fourier Series for periodic signals. As first part of this assignment, you need to write a Matlab function that would take an array representing a single period of a signal (x), corresponding time array (t), and return the Fourier Series coefficients (Ck) in exponential form. The function should also be able to take two (2) optional input arguments: number of Fourier coefficients (Nk) and plot option (p). Use the template ‘fourier_series_exp.m’ for this problem.

(Template "fourier_series_exp.m")

function [Ck]=fourier_series_exp(x,t,Nk,p)

% Ck = exponential fourier series cofficient
% x = single period of a signal
% t = time corrosponding to 'x'
% Nk = (optional input) number of exponential terms
% p = plotting option ; p=0, no plots, p = 1 plot Ck vs k and reconstructed signal
% dT = t(2)-t(1) = temporal resolution of signal (x)
% T = peiod of signal 'x'
% w0= angular frequency of signal 'x'


dT=t(2)-t(1);
T= dT*length(t);
w0=2*pi/T;   

% Check the number of inputs, 'nargin' returns number of input arguments
if nargin <2
error('Not enough input argument!')
elseif nargin == 2
Nk=101; % you can set any default value you like
p=0; % not plots
elseif nargin ==3
p=0; % not plots
end
k=-floor(Nk/2):floor(Nk/2); % if Nk=11, k=-5:5; if Nk=12, k=-6:6


%% evaluate Ck
%
% % % write this code segment
%
%% plot spectrum and reconstructed signal   
if p==1
% plot abs(Ck) vs k and angle(Ck) vs k
%
% % % write this code segment
%
  
% plot 3 cycles of the signal 'x' and the reconstructed signal
%
% % % write this code segment
%
end

end

Solutions

Expert Solution

function [Ck]=fourier_series_exp(x,t,Nk,p)

% Ck = exponential fourier series cofficient
% x = single period of a signal
% t = time corrosponding to 'x'
% Nk = (optional input) number of exponential terms
% p = plotting option ; p=0, no plots, p = 1 plot Ck vs k and reconstructed signal
% dT = t(2)-t(1) = temporal resolution of signal (x)
% T = peiod of signal 'x'
% w0= angular frequency of signal 'x'


dT=t(2)-t(1);
T= dT*length(t);
w0=2*pi/T;   

% Check the number of inputs, 'nargin' returns number of input arguments
if nargin <2
error('Not enough input argument!')
elseif nargin == 2
Nk=101; % you can set any default value you like
p=0; % not plots
elseif nargin ==3
p=0; % not plots
end
k=-floor(Nk/2):floor(Nk/2); % if Nk=11, k=-5:5; if Nk=12, k=-6:6


%% evaluate Ck
%
Ck = [];
for k=-floor(Nk/2):floor(Nk/2)
Ck1=(1/T)*sum(x.*exp(-j*k*w0*t));
Ck = [Ck, Ck1];
end
k=-floor(Nk/2):floor(Nk/2);
%
%% plot spectrum and reconstructed signal   
if p==1
% plot abs(Ck) vs k and angle(Ck) vs k
%
subplot(2,1,1)
stem(k,abs(Ck),'linewidth',2);
grid on;
xlabel('k');
ylabel('|Ck|');
title('Magnitude Spectrum');

subplot(2,1,2)
stem(k,angle(Ck),'linewidth',2);
grid on;
xlabel('k');
ylabel('\angle Ck');
title('Phase Spectrum');

%
  
% plot 3 cycles of the signal 'x' and the reconstructed signal
%

t = 0:dT:3*T-dT;
x = [x x x];

figure
plot(t,x,'linewidth',2)
grid on;
xlabel('Time, t (s)');
ylabel('Amplitude');
title('Original Waveform');

%
end

end


Related Solutions

Signals and systems Find the complex exponential Fourier series for the following signals. In each case...
Signals and systems Find the complex exponential Fourier series for the following signals. In each case plot the magnitude and phase line spectra for k ≥ 0. (i) x1(t) = cos(5t + 45o ) (ii) x2(t) = sin2 (t) (iii) x3(t) = cos(3t) + cos(5t)]
find Fourier series of periodic function ?(?) = { −?, −1 ≤ ? ≤ 0 with...
find Fourier series of periodic function ?(?) = { −?, −1 ≤ ? ≤ 0 with the period 2 { ?, 0 ≤ ? ≤ 1
Explain why. Is Fourier Series can represent any normal, periodic function if we use enough sinusoid...
Explain why. Is Fourier Series can represent any normal, periodic function if we use enough sinusoid term?
Based on fourier series Q1: how to determine if a signal function x(t) is periodic and...
Based on fourier series Q1: how to determine if a signal function x(t) is periodic and ac. And what happens if there is x(t) = sint + cost + sint? How would we know if ac/periodic? Q2: What is fourier series and fourier coefficients? Q3: What is Fourier Trigonometric Series?
Calculate the fourier series of these periodic functions f(x) = cosh(2πax + πa), x ∈ [0,...
Calculate the fourier series of these periodic functions f(x) = cosh(2πax + πa), x ∈ [0, 1) and f(x) = cos(2πax − aπ) x ∈ [0, 1). The period of these functions is 1. 1-periodic
Given the following functions, can you have the corresponding a) Fourier series, b) Fourier transform and...
Given the following functions, can you have the corresponding a) Fourier series, b) Fourier transform and c) Laplace transform? If yes, find them, if not, explain why you can not. A, x(t) = -1+cos(2t) + sin(pai*t+1)                                               (4-1) B, x(t) = 2d(t) cos(2t) +d(t-1.5p) sin(2t)                                          (4-2) C, x(t) = 1+cos(1.5t) + cos(4t)                                           (4-3)
Given the following functions, can you have the corresponding a) Fourier series, b) Fourier transform and...
Given the following functions, can you have the corresponding a) Fourier series, b) Fourier transform and c) Laplace transform? If yes, find them, if not, explain why you can not. A, x(t) = -1+cos(2t) + sin(pt+1)                                                                                 (4-1) B, x(t) =2d(t) cos(2t) +d(t-1.5p) sin(2t)                                                                    (4-2) C, x(t) = 1+cos(1.5t) + cos(4t)                                                                                    (4-3)
Find the Fourier series expansion of the function f(t) = t + 4 , 0 =<...
Find the Fourier series expansion of the function f(t) = t + 4 , 0 =< t < 2pi
We have seen increase in prices of various goods for example Sugar during this period of...
We have seen increase in prices of various goods for example Sugar during this period of COVID-19 pandemic. Suggest the possible measures that should be taken as far as International Trade is concerned
3) Find the Fourier series of ?(?), which is assumed to have the period 2?. Specify...
3) Find the Fourier series of ?(?), which is assumed to have the period 2?. Specify the relationships for Fourier coefficients, and illustrate the pattern for the first several terms within the series ?(?). You may use software to solve for the integrals, but show the complete result and illustrate the simplification process to a reduced form. [35 pts]    ?(?) = ?2    (0 < ? < 2?)   
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT