Professional Documents
Culture Documents
Acquire Continuous Audio Data
Acquire Continuous Audio Data
1 of 4
http://www.mathworks.com/help/daq/examples/getting-started-acquirin...
d = daq.getDevices
d =
Data acquisition devices:
index
Vendor
Device ID
Description
----- ----------- ------------------------------------------------------------------------1
directsound Audio0
DirectSound Primary Sound Capture
Driver
2
directsound Audio1
DirectSound Microphone (High
Definition Audio Device)
3
directsound Audio2
DirectSound HP 4120 Microphone (2- HP
4120)
4
directsound Audio3
DirectSound Microphone (Plantronics
.Audio 400 DSP)
5
directsound Audio4
DirectSound Digital Audio (S/PDIF)
(High Definition Audio Device)
6
directsound Audio5
DirectSound Primary Sound Driver
7
directsound Audio6
DirectSound Speakers (Plantronics
.Audio 400 DSP)
8
directsound Audio7
DirectSound HP 4120 (2- HP 4120)
9
directsound Audio8
DirectSound Speakers (High Definition
Audio Device):1
10
directsound Audio9
DirectSound Speakers (High Definition
Audio Device):2
29/09/2014 19:09
2 of 4
http://www.mathworks.com/help/daq/examples/getting-started-acquirin...
dev = d(2)
dev =
directsound: DirectSound Microphone (High Definition Audio Device)
(Device ID: 'Audio1')
Audio input subsystem supports:
-1.0 to +1.0 range
Rates from 80.0 to 1000000.0 scans/sec
2 channels ('1','2')
'Audio' measurement type
s = daq.createSession('directsound');
addAudioInputChannel(s, dev.ID, 1:2);
Prepare session for continuous operation.
s.IsContinuous = true
s =
Data acquisition session using DirectSound hardware:
Will run continuously at 44100 scans/second until stopped.
Number of channels: 2
index Type Device Channel MeasurementType
Range
Name
----- ---- ------ ------- --------------- ------------- ---1
audi Audio1 1
Audio
-1.0 to +1.0
2
audi Audio1 2
Audio
-1.0 to +1.0
hf = figure;
hp = plot(zeros(1000,1));
T = title('Discrete FFT Plot');
xlabel('Frequency (Hz)')
ylabel('|Y(f)|')
grid on;
29/09/2014 19:09
3 of 4
http://www.mathworks.com/help/daq/examples/getting-started-acquirin...
type helper_continuous_fft.m
function continuous_fft(data, Fs, plotHandle)
% Calculate FFT(data) and update plot with it.
lengthOfData = length(data);
nextPowerOfTwo = 2 ^ nextpow2(lengthOfData); % next closest power
of 2 to the length
plotScaleFactor = 4;
plotRange = nextPowerOfTwo / 2; % Plot is symmetric about n/2
plotRange = floor(plotRange / plotScaleFactor);
yDFT = fft(data, nextPowerOfTwo); % Discrete Fourier Transform of
data
h = yDFT(1:plotRange);
abs_h = abs(h);
freqRange = (0:nextPowerOfTwo-1) * (Fs / nextPowerOfTwo); %
Frequency range
gfreq = freqRange(1:plotRange); % Only plotting upto n/2 (as
other half is the mirror image)
set(plotHandle, 'ydata', abs_h, 'xdata', gfreq); % Updating the
plot
drawnow; % Update the plot
29/09/2014 19:09
4 of 4
http://www.mathworks.com/help/daq/examples/getting-started-acquirin...
end
startBackground(s);
figure(hf);
Wait for 10 seconds while continuing to acquire data via the microphone.
pause(10);
Stop the session.
stop(s);
s.IsContinuous = false;
delete(hl);
29/09/2014 19:09