Advertisement
Guest User

Untitled

a guest
Aug 6th, 2020
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.72 KB | None | 0 0
  1.  
  2. %read the audio file x samples, output Fs
  3. [x,Fs]= audioread('Guitar_notes.wav');
  4. %take the fourier transform
  5. xdft = fft(x);
  6. xdft = xdft(1:length(x)/2+1);
  7. % create a frequency vector
  8. freq = 0:Fs/length(x):Fs/2;
  9. %locs is now in frequency
  10. [pks,locs] = findpeaks(20*log10(abs(xdft)));
  11. %finds the peaks within the range of the fundamental frequency of the notes
  12. indesiredrange = locs > 150 & locs < 500;
  13. %gets the subsets within range
  14. pks_subset = pks(indesiredrange);
  15. locs_subset = locs(indesiredrange);
  16. figure(1)
  17. semilogx(freq,20*log10(abs(xdft)))
  18. hold on
  19. plot(freq(locs_subset), pks_subset, 'or')
  20. hold off
  21. xlabel('f(Hz)');
  22. title('FFT of signal')
  23.  
  24. [pks,locs] = findpeaks(20*log10(abs(xdft)), freq);
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement