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

In Matlab A harmonic signal is basically the sum of a number of sinusoids, whose

ID: 2292011 • Letter: I

Question

In Matlab

A harmonic signal is basically the sum of a number of sinusoids, whose frequencies are multiples of a fundamental frequency.

Write a function named harmonic signal, which receives the fundamental frequency, f0 (a real and positive number), the number of harmonics, Nh (a positive integer number), harmonic
amplitudes, Ah (a vector of length Nh with elements greater than zero), the total duration of the harmonic signal, dur (a real and positive number), and the sampling rate, fs (a positive and integer number). The function should return a vector containing samples of the harmonic signal, X(t), over the speci?ed duration. The output vector should be normalized so that its maximum value is equal to one.

Explanation / Answer

f0 = input('please enter the fundamental frequency which is a real and positive number');
Nh = input('please enter the number of harmonics which is a positive integer');
Ah = zeros (Nh,1);
for c=1:Nh

display (c)

Ah(c,1)=input('Please enter the amplitude of the above harmonic');
end
B = zeros (Nh,1)
dur = input('please enter the total duration of the harmonic signal which is real and positive number');
fs = input('please enter the sampling rate desired which is a positive integer');
Xt = zeros(dur*fs,1)
for i=0:1/fs:dur
for r = 1:1:Nh
B(r,1)= Ah(r,1)*sin(r*2*pi*f0*i);
end

if i==0

Xt(1, 1)= sum (B)

else
Xt(i*fs, 1)= sum (B)
end

end
Xt= Xt/norm (Xt, inf);
display (Xt)

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