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.
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)
Get Answers For Free
Most questions answered within 1 hours.