Matlab Synthesize the sound piano ro 130.5 % Fundamental frequency / Hz 67- 68 6
ID: 3594334 • Letter: M
Question
Matlab Synthesize the sound piano ro 130.5 % Fundamental frequency / Hz 67- 68 69 70 % 2.2.1 Synthesize a signal that will define frequency resolution (all % components same phase) % duration in 3 72 73 74- 75- 76- number of components % sampling frequency in Hz N s = 20; fs_1 = 44100; len-Ts* fss;% length (YS) deltaf=fss/ len ; n peak- f0/delta1+1; % number of samples between to peaks - - % distance between two samples - - - 78 79 80Y-zeros (len, 1); 81- Ypos= zeros (fix( (fs 82 83 84 85 % create a vector Ys (synthesized) containing complex spectrum of a sum of % sinusoids s/2) /delta f % positive half (freq) of the vector ) +1,1); here we divide the NYQUIST freq by the spectral resolution and see i - - - % we have a sample there (fix). % for loop to fill in the peaks for the positive frequencies for n=1:N s 20 peaks on the positive frequencies % amplitude of peaks Y pos (n*n peak) -lj/2; = - - end 89 90 91 92 93 94 95 % check if vector is even or odd. If it is even, it will hiot the NYQUIST % frequency, then the spectrum is mirrored around this -and hence it is % NOT contained in the negative frequencies. If it is odd, the NYQUIST % frequency will NOT be hit, hence you have a sample symetrically around % the NYQUIST frequency and need to take all but the first sample of the % positive frequencies (the DC) with you:Explanation / Answer
function [freq,coeff,APspec] = fourier_coeff(fun,t0,T,M,N,method,res,num_P)
% Amplitude and phase spectra
freq = (0:1:M)'/T;
tmp = coeff;
Aspec = sqrt( tmp(1:(M+1)).^2 + [0;tmp(M+2:end).^2] );
tmp(abs(tmp)<thresh) = 0;
Pspec = [0 ; atan2(tmp(M+2:end),tmp(2:M+1))];
Pspec(isnan(Pspec)) = 0;
APspec = [Aspec Pspec];
% Show results
if res
fseries = fourier_series(coeff,t,T);
figure
plot(t,y,'k',t,fseries,'r.')
legend('Original function','Fourier series')
grid on
title('Fourier series expansion')
xlabel('t')
figure
subplot(1,2,1)
plot(freq,Aspec)
grid on
title('Amplitude spectrum: (a_m^2+b_m^2)^{1/2}')
xlabel('Frequency (Hz)')
subplot(1,2,2)
plot(freq,Pspec*180/pi)
grid on
title('Phase spectrum: phi_m (degrees)')
xlabel('Frequency (Hz)')
end