An example for generating a sinusoid was included in Lab00. Here, we will again
ID: 3278742 • Letter: A
Question
An example for generating a sinusoid was included in Lab00. Here, we will again use the built-in MATLAB editor to create a script file called asinusoid.m containing the following lines for future use: function xs = asinusoid(amp, freq, pha, fs, tsta, tend) % amp = amplitude % freq = frequency in cycle per second % pha = phase, time offset for the first peak % fa = number of sample values per second % tsta = starting time in sec % tend = ending time in sec tt = tsta: 1/fs: tend: % time indices for all the values xs = amp * cos(freq*2*pi*tt + pha): end This function asinusoid can be called once the argument values are specified. For example, amp = 2.2: freq = 100: pha = pi/3: fs = 8000: tsta = 0: tend =3: %a 3-sec long signal xs = asinuaoid(amp, freq, pha, fs, tsta, tend): %Explanation / Answer
so the new code is as under
function xs = asinusoid(amp, freq, pha, fs, tsta, tend)
%amp = amplitude
%freq = frequency
%pha = phase , time offset for first peak
%fs = number of sample values per second
%tsta = starting time in sec
%tend = ending time in sec
tt = tsta : 1/fs : tend; %time indeces for all values
xs = amp*cos(freq*2*pi*tt+pha);
amp = 1.6;
freq = 400;
fs = 8000;
pha = 1.2;
tsta = 0;
tend = 3;
xs1 = asinusoid(amp, freq, pha, fs, tsta, tend)
amp = 2.1;
freq = 410;
fs = 8000;
pha = 0;
tsta = 0;
tend = 3;
xs2 = asinusoid(amp, freq, pha, fs, tsta, tend)
tsta = 0.7;
tend = 1;
ts = tsta:1/fs:tend;
le = length(ts);
xss = xs1 + xs2;
plot(ts,xss(1:le), 'b-', ts, xss(1:le), 'r--'),grid on
title('SOLUTION PLOT OF SINUSOID')
xlabel('TIME (sec)')
ylabel('AMPLITUDE (m)')
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.