Last active
          February 6, 2018 15:21 
        
      - 
      
- 
        Save morganp/4944028 to your computer and use it in GitHub Desktop. 
    Basic Matlab FFT
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | %% Trial FFT | |
| % http://www.mathworks.co.uk/help/matlab/math/fast-fourier-transform-fft.html | |
| fs = 48000; % Sample Rate | |
| n = 4096; % Power of 2 number of samples/ length of FFT | |
| % Get/Generate data | |
| t = 0:1/fs:(n-1)/fs; % n/fs sec sample | |
| x = (1.3)*sin(2*pi*1500*t) ... % 1.5k Hz component | |
| + (1.7)*sin(2*pi*4000*(t-2)) ... % 4.0k Hz component | |
| + (2.5)*randn(size(t)); | |
| %# Frequency Bins | |
| bins = (0:1:n-1)*(fs/n); | |
| y = fft(x,n); | |
| %# plot fft | |
| % plot(bins, abs(y)); | |
| % title('FFT') | |
| % xlabel('Frequency (Hz)') | |
| % ylabel('Magnitude') | |
| plot(bins, 20*log10(abs(y))); | |
| title('FFT') | |
| xlabel('Frequency (Hz)') | |
| ylabel('Magnitude (dB)') | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment