Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In this section, you will write a function called syn_sin.m that will synthesize

ID: 3781830 • Letter: I

Question

In this section, 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.

Explanation / Answer

Please find the function as below:

function [xx,tt] = syn_sin(fk, Xk, fs, dur, tstart)

if(length(fk) ~= length(Xk))

   ERROR('syn_sin:Length mismatch','The vector of frequencies and complex amplitudes must of the same length');

end

if(nargin < 5)

   tstart = 0;

end

tt= tstart : 1/fs : dur;

xx= zeros(1,length(tt));

M=length(fk);

for k=1:M

   xx = xx + real(Xk(k)*exp(j*2*pi*fk(k)*tt));

end

end

Thank you.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote