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] = syn_sin (fk, Xk, fs, dur, tstart) Function to synthesize a sum of cosine waves [xx, tt] = syn_sin (fk, Xk, fs, dur, tstart) fk = vector of frequencies (these could be negative or positive) vector of complex amplitudes: Amp*e^(j*phase) 응 Xk 응 fs = the number of samples per second for the time axis total time duration of the signal dur = .. tstart = starting time (default is zero, if you make this input optional) xx = vector of sinusoidal values 응 tt 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 fs 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.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter6: User-defined Functions
Section: Chapter Questions
Problem 22PE
icon
Related questions
Question

this will be a code in matlab, thank you

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] =
syn_sin (fk, Xk, fs, dur, tstart)
Function to synthesize a sum of cosine waves
[xx, tt] = syn_sin (fk, Xk, fs, dur, tstart)
fk = vector of frequencies
(these could be negative or positive)
vector of complex amplitudes: Amp*e^(j*phase)
응
Xk
응
fs =
the number of samples per second for the time axis
total time duration of the signal
dur =
.. tstart = starting time (default is zero, if you make this input optional)
xx = vector of sinusoidal values
응
tt 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 fs 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.
Transcribed Image Text: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] = syn_sin (fk, Xk, fs, dur, tstart) Function to synthesize a sum of cosine waves [xx, tt] = syn_sin (fk, Xk, fs, dur, tstart) fk = vector of frequencies (these could be negative or positive) vector of complex amplitudes: Amp*e^(j*phase) 응 Xk 응 fs = the number of samples per second for the time axis total time duration of the signal dur = .. tstart = starting time (default is zero, if you make this input optional) xx = vector of sinusoidal values 응 tt 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 fs 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.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 1 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr