Title(,' int2str(Nav) '-spectrum avg'])įigure 2: Zoom in on first second and two octaves and pick out notes figure(2) Twav = mean(reshape(tw(1:nwininav),Nav,ntav)) % Average times % Note use of reshape for computationally efficient block averaging Ylabel( 'octaves above concert A (440 Hz)')īlock-average S from Nav adjacent overlapping windows, then replot Nav = 4 % Number of overlapping windows used for averaging spectra Replot with frequency in octaves from concert A = 440 Hz % Plot log2(freq) = octaves, but have to exclude m=1 (zero freq) Image(t2,fw2,SdB2, 'CDataMapping', 'scaled') %CDataMapping=scaled % uses the range of values of SdB2 to make the color scale.Īxis xy % Puts low frequencies at the bottom SdB2 = 10*log10(S2) % Convert spectral power to decibel scale % Convert 1-sided power spectral density P2 (in power per Hz) % into two sided periodogram (in power per FFT frequency Use Matlab spectrogram function to make the same plot = spectrogram(y,hann(Nw, 'periodic'),Nw/2,Nw,Fs) Title( 'Windowed spectral power of Messiah sample') % Add offsets and padding so pcolor centers each cell on (tw,fw) % and last row/col of field is included in plots Tw = (1:nwin)*0.5*Nw/Fs % Center time of each window % Plot the power spectra (log or decibel scale) vs. Mw = 0:(Nw/2 - 1) % Nonnegative windowed harmonicsįw = Fs*Mw/Nw % "Frequencies'(inverse periods in Hz) of these harmonics ![]() SdB = 10*log10(S) % log of spectrum in decibel-like units ![]() S = S(1:Nw/2,:) % Only keep nonnegative harmonics for plotting S = (abs(ythat/Nw).^2)/varw %Windowed power spectrum Yw = zeros(Nw,nwin) % Define array in which to insert windowed data Nwinh = nwinf - 1 % Number of 'half' windows (half-way between fulls) Nwinf = floor(Ny/Nw) % Number of 'full' windows starting each Nw samples % Segment the data into 'full' and 'half' windows, arrayed in columns Varw = 3/8 % Mean-square value of taper function w (used to % renormalize power spectrum). W = 0.5*(1-cos(2*pi*(j-1)/Nw))' % Hanning window of length Nw: % SP toolbox: w=hanning(Nw,'periodic') Play the data as music p8 = audioplayer(y,Fs) ĭFT power spectra using Hann window Nw = 256 Ny = length(y) % Number of samples in the segment Load data and see what we have load handel %this music dataset is built into Matlab
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |