Matlab 66 “ Synthesize the sound piano 67- eo! 130.5 fundamental frequency, Hz 6
ID: 3597403 • Letter: M
Question
Matlab 66 “ Synthesize the sound piano 67- eo! 130.5 fundamental frequency, Hz 68 69 70 71-T-2 72-N20: 73- tss-44100: % sampling frequency in Hz 74- len-1-s*ts-s; % length (rs) 75-delta f-ts s/1en:distance between two samples 76- npeak-eo/deltaf+1; % number of samples between to peaks 2.2.1 Synthesize a signal that will define frequency resolution (a11 components same phase) duration in number of components - - - create a vector Ys (synthesized) containing complex spectrum of a sum of % sinusoids 78 79 0Yzeros (len, 1) 81-y_pos-zeros (fix ( 82 83 04 85 86- for n-1:Ns 87- -end 89 90 91 92 93 94 95 (ts-s/2),delta-f ) +1,1) ; positive half (freq) of the vector here we divide the IrOUIST freq by the spectral resolution and see it we have a sample there (tx) foz loop to ti11 in the peaks for the positive fxequencies 20 peaks on the positive frequencies amplitude of peaks - Y_pos (n-n-peak) --Ij/2; check if vector is even oz odd. If it is even, it will hiot the NYOUIST frequency, then the spectrum is mirrored around tis-and hence it is NOT Contained in the negative frequencies. If it is odd, the NYQUIST frequency will Nor be hit, hence you have a sample symetrically around the NYOUIST frequency and need to take all but the fizst sample of the positive frequencies (the DC) with you:Explanation / Answer
Answer: First of all, please note that the code shown in image is not running properly. At line 100 in the code, the dimensions of f_pos and fliplr(f_pos(2:end-1)) are inconsistent. It is to be noted that f_pos is of size 1X44101, while size of fliplr(f_pos(2:end-1)) will be 1X44099 as range is 2:end-1. No operation can be performed on vectors of inconsistent sizes. Also on line 108, in the call to stem() function, sizes of both the arguments should be consistent. This needs to be corrected.
As far as including amplitude as per the equation given is concerned, it can be calculated and assigned in the for loop in lines 86:88.