Question

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...

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

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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'
Fs=100;

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
%Ck = fft(x);

L=length(x);
NFFT = 2^nextpow2(L); % Next power of 2 from length of y
Y = fft(x,NFFT)/L;
f = Fs/2*linspace(0,1,NFFT/2);



%
%% plot spectrum and reconstructed signal   
if p==1
% plot abs(Ck) vs k and angle(Ck) vs k
%
% % % write this code segment
% Plot single-sided amplitude spectrum.
subplot(3,1,1); plot(x); title('Original Signal - Single Period');
subplot(3,1,2); plot(f,2*abs(Y(1:NFFT/2)));
str = strcat('FFT at N = ',num2str(NFFT),' Points'); title(str);
xlabel('Frequency (Hz)'); ylabel('|Y(f)|');

%Reconstructed Signal
y =ifft(Y);
subplot(3,1,3); plot(y); title('Reconstructed Signal');
%
end

end

Original Signal - Single Period FFT at N 16 Points 05 10 15 20 25 30 35 45 50 Frequency (Hz) Reconstructed Signal 0.05 0.05

Add a comment
Know the answer?
Add Answer to:
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...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • PLZ shows you Matlab Code X(t) 2 2 46 1. compute the Fourier Series coefficients, ck...

    PLZ shows you Matlab Code X(t) 2 2 46 1. compute the Fourier Series coefficients, ck for the signal x(t) 2. plot magnitude of c and the phase of ck in separate plots (use subplot command) plot the Fourier Series coefficients for the square wave signal: ck(12/9) sinc(2"k/3)

  • Please help by writing a MATLAB Code for the this lab Fourier Series Synthesis You will...

    Please help by writing a MATLAB Code for the this lab Fourier Series Synthesis You will consider five continuous-time signals 1- 2- for A D 4- We were unable to transcribe this imageWe were unable to transcribe this imager(t) e-t for-1 < t > 1 x(t) 2 2 4 3 3 x(t) -4 2 2 4 2 1, 0sts be a periodic signal with fundamental period T = 2 and Fourier coefficients ak. (a) Determine the value of ao (b)...

  • 1. Using the Fourier series analysis Equation 3 for the periodic function r(t) shown in Figure 2....

    1. Using the Fourier series analysis Equation 3 for the periodic function r(t) shown in Figure 2.1, determine both the DC coefficient ao and a general expression for the other Fourier series coefficients ak. Do this by hand, not in Matlab. Show all your work in your lab report. You can add these pages as hand-written pages, rather than typing them in to your lab report, if you prefer Hint 1: It will be easiest to integrate this function from...

  • Please don't attempt if you can not write a MATLAB PROGRAM. I don't need numerical physics...

    Please don't attempt if you can not write a MATLAB PROGRAM. I don't need numerical physics solution, I need MATLAB code. Read the question carefully 2) Falling Drops Imagine a solid sphere of diameter, d, falling through the air. After its release, the sphere accelerates until it reaches its terminal velocity. The terminal velocity is obtained when the drag force due to air friction, Fa, balances the weight of the sphere, W. The weight of the sphere is simply its...

  • You are given a finite step function xt=-1  0<t<4 1  4<t<8.           Hand calculate the FS coefficients of...

    You are given a finite step function xt=-1  0<t<4 1  4<t<8.           Hand calculate the FS coefficients of x(t) by assuming half- range expansion, for each case below. Modify the code below to approximate x(t) by cosine series only (This is even-half range expansion). Modify the below code and plot the approximation showing its steps changing by included number of FS terms in the approximation. Modify the code below to approximate x(t) by sine series only (This is odd-half range expansion).. Modify...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT