expressions are equivalent if we define the complex amplitudes X as Xk = Akejk. 4.2.1 Write the Function M-file x(t) = Xke N x(t) = Ak cos(2πfkl+ok) k=1 (7) (8) Write an M-file called syn.sin.m that will synthesize a waveform in the form of (7). Although for loops are rather inefficient in MATLAB, you must write the function with one loop in this lab. The first few statements of the M-file are the comment lines-they should look like: function SYN_SIN usage: $ [xx, tt] 3 fk Xk 鲁 8 fs % dur tstart xx tt [xx, tt] = syn_sin (fk, Xk, fs, dur, tstart) Function to synthesize a sum of cosine waves syn sin (fk, Xk, fs, dur, tstart) vector of frequencies (these could be negative or positive) vector of complex amplitudes: Amp*e (j*phase) the number of samples per second for the time axis. total time duration of the signal starting time (default is zero, if you make this input optional) vector of sinusoidal values vector of times, for the time axis Note: fk and Xk must be the same length. Xk (1) corresponds to frequency fk (1), Xk (2) corresponds to frequency fk (2), etc. The MATLAB syntax length (fk) returns the number of elements in the vector fk, so we do not need a separate input argument for the number of frequencies. On the other hand, the programmer (that's you) should provide error checking to make sure that the lengths of fk and Xk are the same. See help error. Finally, notice that the input is defines the number of samples per second for the cosine generation; in other words, we are no longer constrained to using 20 samples per period. Include a copy of the MATLAB code with your lab report. 4.2.2 Default Inputs You can make the last input argument(s) take on default values if you use the nargin operator in MATLAB. For example, tstart can be made optional by including the following line of code: if nargin<5, tstart=0, end %--default value is zero 4.2.3 Testing In order to use this M-file to synthesize harmonic waveforms, you must choose the entries in the frequency vector to be integer multiples of some desired fundamental frequency. Try the following test and plot the result. [xx0, tt0] syn sin([0,100,250], [10,14*exp(-j*pi/3), 8*j1, 10000, 0.1, 0); *-Period = ? Measure the period of xx0 by hand. Then compare the period of xx0 to the periods of the three sinusoids that make up xx0, and write an explanation on the verification sheet of why the period of xx0 is longer.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
Please use my syn.sin.m code to answer 4.2.3. Also, please answer the explanation for the last part
function [xx, tt] = syn_sin(fk, Xk, fs, dur, tstart)
%SYN_SIN - Function to synthesize a sum of cosine waves
% usage: [xx, tt] = syn_sin(fk, Xk, fs, dur, tstart)
% fk = vector of frequencies
% Xk = vector of complex amplitudes: Amp*e^(j*phase)
% fs = number of samples per second for the time axis
% dur = total time duration of the signal
% tstart = starting time (default is zero if not provided)
% xx = vector of sinusoidal values
% tt = vector of times for the time axis
 
% Check if tstart is provided, otherwise set it to zero
if nargin < 5
tstart = 0;
end
 
% Check if fk and Xk have the same length
if length(fk) ~= length(Xk)
error('Length of frequencies (fk) and amplitudes (Xk) must be the same.');
end
 
% Generate time vector
tt = linspace(tstart, tstart + dur, dur * fs);
 
 
xx = zeros(size(tt));
 
% Loop through frequencies and add sinusoidal components
for k = 1:length(fk)
xx = xx + real(Xk(k) * exp(1j * 2 * pi * fk(k) * tt));
end
 
 
expressions are equivalent if we define the complex amplitudes X as Xk = Akejk.
4.2.1 Write the Function M-file
x(t) =
Xke
N
x(t) =
Ak cos(2πfkl+ok)
k=1
(7)
(8)
Write an M-file called syn.sin.m that will synthesize a waveform in the form of (7). Although for loops are rather
inefficient in MATLAB, you must write the function with one loop in this lab. The first few statements of the M-file are
the comment lines-they should look like:
function
SYN_SIN
usage:
$
[xx, tt]
3
fk
Xk
鲁
8
fs
%
dur
tstart
xx
tt
[xx, tt] = syn_sin (fk, Xk, fs, dur, tstart)
Function to synthesize a sum of cosine waves
syn sin (fk, Xk, fs, dur, tstart)
vector of frequencies
(these could be negative or positive)
vector of complex amplitudes: Amp*e (j*phase)
the number of samples per second for the time axis.
total time duration of the signal
starting time (default is zero, if you make this input optional)
vector of sinusoidal values
vector of times, for the time axis
Note: fk and Xk must be the same length.
Xk (1) corresponds to frequency fk (1),
Xk (2) corresponds to frequency fk (2), etc.
The MATLAB syntax length (fk) returns the number of elements in the vector fk, so we do not need a separate input
argument for the number of frequencies. On the other hand, the programmer (that's you) should provide error checking
to make sure that the lengths of fk and Xk are the same. See help error. Finally, notice that the input is defines
the number of samples per second for the cosine generation; in other words, we are no longer constrained to using 20
samples per period.
Include a copy of the MATLAB code with your lab report.
4.2.2 Default Inputs
You can make the last input argument(s) take on default values if you use the nargin operator in MATLAB. For
example, tstart can be made optional by including the following line of code:
if nargin<5, tstart=0, end %--default value is zero
4.2.3 Testing
In order to use this M-file to synthesize harmonic waveforms, you must choose the entries in the frequency vector to
be integer multiples of some desired fundamental frequency. Try the following test and plot the result.
[xx0, tt0] syn sin([0,100,250], [10,14*exp(-j*pi/3), 8*j1, 10000, 0.1, 0);
*-Period = ?
Measure the period of xx0 by hand. Then compare the period of xx0 to the periods of the three sinusoids that make
up xx0, and write an explanation on the verification sheet of why the period of xx0 is longer.
Transcribed Image Text:expressions are equivalent if we define the complex amplitudes X as Xk = Akejk. 4.2.1 Write the Function M-file x(t) = Xke N x(t) = Ak cos(2πfkl+ok) k=1 (7) (8) Write an M-file called syn.sin.m that will synthesize a waveform in the form of (7). Although for loops are rather inefficient in MATLAB, you must write the function with one loop in this lab. The first few statements of the M-file are the comment lines-they should look like: function SYN_SIN usage: $ [xx, tt] 3 fk Xk 鲁 8 fs % dur tstart xx tt [xx, tt] = syn_sin (fk, Xk, fs, dur, tstart) Function to synthesize a sum of cosine waves syn sin (fk, Xk, fs, dur, tstart) vector of frequencies (these could be negative or positive) vector of complex amplitudes: Amp*e (j*phase) the number of samples per second for the time axis. total time duration of the signal starting time (default is zero, if you make this input optional) vector of sinusoidal values vector of times, for the time axis Note: fk and Xk must be the same length. Xk (1) corresponds to frequency fk (1), Xk (2) corresponds to frequency fk (2), etc. The MATLAB syntax length (fk) returns the number of elements in the vector fk, so we do not need a separate input argument for the number of frequencies. On the other hand, the programmer (that's you) should provide error checking to make sure that the lengths of fk and Xk are the same. See help error. Finally, notice that the input is defines the number of samples per second for the cosine generation; in other words, we are no longer constrained to using 20 samples per period. Include a copy of the MATLAB code with your lab report. 4.2.2 Default Inputs You can make the last input argument(s) take on default values if you use the nargin operator in MATLAB. For example, tstart can be made optional by including the following line of code: if nargin<5, tstart=0, end %--default value is zero 4.2.3 Testing In order to use this M-file to synthesize harmonic waveforms, you must choose the entries in the frequency vector to be integer multiples of some desired fundamental frequency. Try the following test and plot the result. [xx0, tt0] syn sin([0,100,250], [10,14*exp(-j*pi/3), 8*j1, 10000, 0.1, 0); *-Period = ? Measure the period of xx0 by hand. Then compare the period of xx0 to the periods of the three sinusoids that make up xx0, and write an explanation on the verification sheet of why the period of xx0 is longer.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 1 steps

Blurred answer
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education