Plotting Audio Analog Signal in Matlab Using Arduino
Plotting Audio Analog Signal in Matlab Using Arduino
Headphone Hack
For this tutorial we need old headphone jack. We play audio or music and transmit that signal using
headphone jack to the arduino analog pin. There are different types of headphone jacks with different
number of wires but they all will work. In this tutorial, we used a old headphone jack which has 3
wires. They were soldered to three jumper wires as shown in the figure below.
Two of the wires are signal wires for left and right headphone and the third is the ground wire. By
connecting the either the left or the right headphone soldered jumper wire to one of the analog pin
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
and the ground wire to the ground of the Arduino we can get the analog signal into Arduino.
The yellow wire is the signal wire where audio signal flows. This is connected to the black colored
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
wire which is in turn connected to analog pin A2. The blue wire is ground and is connected to the
GND pin of Arduino. The red wire is the another signal wire.
Once the hardware connection is made, we can use Matlab to read the digital values of the
converted analog signal voltages. These digitally converted signal values can be plotted using Matlab
and we can view the audio signal in real time.
The following picture shows the audio signal plot in real time by playing music in PC.
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
Matlab Program Code
The matlab program code to plot the audio signal in real time is given below.
clear all
close all
a = arduino();
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
tic; % starts a stopwatch timer to measure performance,
% it internally records starting time
% toc read elapsed time from stopwatch
k = 0;
t(k) = toc;
v(k) = readVoltage(a,'A2');
figure(1)
plot(t,v);
axis([0,inf,0,1]);
xlabel('time')
ylabel('voltage')
grid on
pause(0.1);
end
In the above code, mainly we have used the tic and toc feature of matlab. Basically they are
functions that tiggers an internal watchdog timer in matlab. tic starts the timer and toc reads the time
elapsed. This feature is used to set the time for plotting the audio signal. To read the analog signal
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
from the analog pin A2 we have used readVoltage() function.
To learn the basic of using Matlab with Arduino see Programming Arduino using Matlab.
Video Demonstration of Plotting audio analog signal in Matlab using Arduino
The following video shows the connections of headphones wires with Arduino and breadboard. It
also shows the real time graph plot of the audio signal.
So in this way you can plot audio signal in real time in Matlab using Arduino utilizing its internal ADC.
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
If you like this tutorial share it and subscribe to our blog.
Share This:
Prevoius Next
Related Posts
Publish Preview
ABOUT US
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
A blog where you can read
tutorials, get tips and tricks, get
the latest news, download free
ebooks
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com