Anda di halaman 1dari 10

Home FPGA Microcontrollers PCB & Schematics Matlab

LATEST Programming PIC18F4450 with Proteus

Plotting audio analog signal in Matlab


using Arduino
By Applied Electronics - Wednesday, February 1, 2017 No Comments

Here we show how to plot audio signal


voltages in matlab using Arduino. As you
know Arduino has inbuilt ADC at the analog pins.
This means that by connecting analog signal
source to one of the six analog pins we can get
the analog voltages in digital values. This means
that we can connect audio signal source such
as music or real voice to the analog pin and plot
it. To plot the audio signal we use Matlab. Last
time we told you how to plot analog signal in
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
Matlab using Arduino in real time where we used
potentiometer. This time we plot audio signal.

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.

Headphone, Arduino Hardware connection


Connection of the headphone wires in Arduino via breadboard is shown below.

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;

while (toc < 300)


k = k+1;

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:

Tags: ARDUINO TUTORIAL ARDUINO VIDEO TUTORIALS MATLAB TUTORIAL


MICROCONTROLLER TUTORIAL

Prevoius Next

Related Posts

Method Attributes in Property Attributes in How to create different


Matlab Object Oriented Matlab Object Oriented handle objects in Matlab?
Programming - Matlab Programming - Matlab Matlab OOP 13
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
OOP 15 OOP 14

No Comment to " Plotting audio analog signal in Matlab using


Arduino "

Enter your comment...

Comment as: Select profile...

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

Subscribe For Update:

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com