Matlab Question: B. Generating Harmonic Tones A harmonic signal is basically the
ID: 2292299 • Letter: M
Question
Matlab Question:
B. Generating Harmonic Tones A harmonic signal is basically the sum of a number of sinusoids, whose frequencies are multiples of a fundamental frequency, i.e. where A, is the amplitude, and f h fo the frequency of the hth harmonic. Write a function named harmonic signal, which receives the fundamental frequency, fo (a real and positive number), the mumber 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(), over the specified duration The output vector should be normalized so that its maximum value is equal to one.Explanation / Answer
MATLAB CODE:
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