Advertisement
Guest User

Untitled

a guest
Sep 18th, 2014
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. Fs = 8000; %# sampling frequency in Hz
  2. T = 1; %# length of one interval signal in sec
  3. t = 0:1/Fs:T-1/Fs; %# time vector
  4. nfft = 2^nextpow2(Fs); %# n-point DFT
  5. numUniq = ceil((nfft+1)/2); %# half point
  6. f = (0:numUniq-1)'*Fs/nfft; %'# frequency vector (one sided)
  7.  
  8. %# prepare plots
  9. figure
  10. hAx(1) = subplot(311);
  11. hLine(1) = line('XData',t, 'YData',nan(size(t)), 'Color','b', 'Parent',hAx(1));
  12. xlabel('Time (s)'), ylabel('Amplitude')
  13. hAx(2) = subplot(312);
  14. hLine(2) = line('XData',f, 'YData',nan(size(f)), 'Color','b', 'Parent',hAx(2));
  15. xlabel('Frequency (Hz)'), ylabel('Magnitude (dB)')
  16. set(hAx, 'Box','on', 'XGrid','on', 'YGrid','on')
  17. %#specgram(sig, nfft, Fs);
  18.  
  19. %# prepare audio recording
  20. recObj = audiorecorder(Fs,8,1);
  21.  
  22. %# Record for 10 intervals of 1sec each
  23. disp('Start speaking...')
  24. for i=1:10
  25. recordblocking(recObj, T);
  26.  
  27. %# get data and compute FFT
  28. sig = getaudiodata(recObj);
  29. %%%%%%%%%%%%%%%%%%%%%%%%%%%
  30. ms20=Fs/50; % minimum speech Fx at 50Hz
  31. r=xcov(sig,'coeff');
  32. %d=(-ms20:ms20)/Fs; % times of delays
  33. subplot(3,1,3);
  34. plot(r);
  35. legend('Autocorrelation');
  36. xlabel('Delay (s)');
  37. ylabel('Correlation coeff.');
  38. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  39. fftMag = 20*log10( abs(fft(sig,nfft)) );
  40.  
  41. %# update plots
  42. set(hLine(1), 'YData',sig)
  43. set(hLine(2), 'YData',fftMag(1:numUniq))
  44. title(hAx(1), num2str(i,'Interval = %d'))
  45. drawnow %# force MATLAB to flush any queued displays
  46. end
  47. disp('Done.')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement