Skip to content

Instantly share code, notes, and snippets.

@tmwatchanan
Created June 4, 2016 14:47
Show Gist options
  • Select an option

  • Save tmwatchanan/08ab1c2fcca6897aea7e58cd27e08f5c to your computer and use it in GitHub Desktop.

Select an option

Save tmwatchanan/08ab1c2fcca6897aea7e58cd27e08f5c to your computer and use it in GitHub Desktop.
Audio MATLAB scripting – recording with microphone, and audio player for the recorded audio data
p = audioplayer(s, 1.5*Fs);
p.play();
% t = (0:(length(s)-1))/Fs; % Ts = 1/Fs
% figure; plot(t,s)
figure; plot(s);
Fs = 10000; %Sampling Frequency [Hz]
Duration = 5; %Duration for recording [sec]
Nbit = 8; %Bits per sample [bits]
r = audiorecorder(Fs,Nbit,1); % 1 = Number of channels
% r is the object of audiorecorder class
disp('Start Recording')
recordblocking(r, Duration); % record for duration time
disp('Finish')
s = getaudiodata(r, 'double'); % s will be array r but in double type
t = (0:(length(s)-1))/Fs; % Ts = 1/Fs
figure; plot(t,s)
%figure; plot(s);
% plto spectrum
F = fft(s);
figure; plot(abs(F))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment