Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

you will write a function called syn_sin.m that will synthesize a waveform from the vectors of frequencies and complex amplitudes. You must write the function

you will write a function called syn_sin.m that will synthesize a waveform from the vectors of frequencies and complex amplitudes. You must write the function with one loop. Below is a template that you should base your solution on:

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 (could be

negative or positive) Xk = vector of complex amplitudes: A*e^(j*phi) for each fk fs = the number of

samples per second for the time axis dur = total time duration of the signal tstart = starting time

(default is 0, 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.

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ADD YOUR FUNCTION BODY HERE \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ %

Here's a description in words: your function will take in two vectors of the same length: a vector of frequencies and a vector of phasors, along with numbers for sampling frequency fs, duration dur, and start time tstart. Adapt your code, from the one_cos function in your last lab, to now process these arguments, generate a sinusoid for each frequency and phasor in the two vectors and add them together. Hints:: The MATLAB command length(fk) returns the number of elements in fk, so we do not need an input for the number of frequencies. However, you should provide error checking to make sure the lengths of fk and Xk are the same. We are no longer constrained to 20 samples per period; in this function, fs defines the number of samples per second, and should be used in the construction of your time vector, tt.

More Hints (cont).): Below are some relevant help commands:): In Matlab, you can check the number of arguments users give a function with "nargin." So, the following line might be helpful: if nargin < 5, tstart = 0, end For a more mathematical basis for adding sinusoid, please see the Appendix at the end of this document.

Testing: Now that you've completed your function, you need to test it!! 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 resulting sinusoid: [xx0,tt0] = syn_sin([0,100,250], [10,14*exp(-j*pi/3), 8*j],10000,0.1,0);

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro Database Migration To Azure Data Modernization For The Enterprise

Authors: Kevin Kline, Denis McDowell, Dustin Dorsey, Matt Gordon

1st Edition

1484282299, 978-1484282298

More Books

Students also viewed these Databases questions