Data Acquisition in MATLAB Without Writing Code
Common data acquisition tasks can be performed in MATLAB® without writing code. The Analog Input Recorder app allows you to acquire analog voltage, current, or audio data from supported devices. The Signal Analyzer app provides visualization and signal analysis capabilities. And you can output analog data using the Analog Output Generator app.
Each of these apps allows you to perform a task and then automatically generate the equivalent MATLAB code for that task so you can easily configure your environment and perform the same analysis again in the future.
In this video, these steps are demonstrated using audio data as an example. Audio is recorded into MATLAB from a microphone, a low-pass filter is applied, and the resulting signal is generated on a speaker. The automatically generated MATLAB code is then assembled in a single MATLAB script that can run the whole workflow.
The Analog Input Recorder and Analog Output Generator apps are included with Data Acquisition Toolbox™. The Signal Analyzer app is included with Signal Processing Toolbox™.
In this video, I’ll show how you can acquire, analyze, and generate analog signals in MATLAB without writing code. To do this, you can use interactive apps in MATLAB.
To acquire data, you can use the Analog Input Recorder from Data Acquisition Toolbox. This app allows you to acquire analog voltage signals from supported DAQ devices and audio signals from audio devices. I’ll acquire audio data from my headset microphone. Let’s record five seconds’ worth of data while I whistle.
As you can see, this is recorded to the MATLAB workspace. Here it is in a timetable, which is nice because this single variable contains the timing information and the data. I can select the data and plot it in MATLAB. And if I zoom in, I can see that this audio data has a sinusoidal behavior.
Now if I want to perform this same acquisition configured the same way in the future, I can generate a script. This script provides me with the equivalent MATLAB code to perform these same steps in the future. Let’s save the script.
Now that I’ve acquired some data, what if I want to analyze it? I can use the Signal Analyzer app from Signal Processing Toolbox. This app offers me a number of things I can do with the data stored in this DAQ_1 timetable. I can visualize it in the time domain, but I can also look at it in the frequency domain or in a time-frequency plot. If I zoom into this region where I have the strongest frequencies, I can clearly see in the time-frequency plot those notes that I whistled.
In addition to visualizing data, I can also perform analysis like a low-pass filter. Let’s say I want to remove some of these higher frequencies. I can set a passband frequency of 1 kHz and bump up the steepness. As you can see, some of these higher frequencies are cut out and some of those higher notes that I whistled are no longer visible here.
From this app, I can export this new data into MATLAB, and I can also generate a function. You can see here that this function gives me the MATLAB code for creating that same low-pass filter with 1000 Hz passband frequency and a steepness of 0.9999. Let’s save this function.
I’ve acquired data. I’ve done some analysis. I can also output data. We can use the Analog Output Generator app from Data Acquisition Toolbox. I’ll output audio data to my computer’s soundbar. For comparison, I’ll first output the data that we originally recorded in the DAQ_1 variable. Now let’s listen to the data that we analyzed with that low-pass filter in DAQ_1_ch1.
As before, I can generate a script to perform these steps in the future. This again provides me with a MATLAB code version to perform the same configuration and signal generation.
Now I’ve generated the equivalent MATLAB code for each of these three steps. How do I tie them all together in a single workflow? Well, I’ve created this script template here, and I can take that automatically generated code and add it in. The code for AcquireAudio, GenerateAudio, and for the preprocessing step, we have a function with this signature. But instead of preprocessing x and tx, we preprocess the data that we acquired in this acquire audio step: data and timesteps. And this function gives us a variable y. So when we generate audio, instead of generating DAQ_1_ch1.ch1, we’ll generate the data in y. So let’s run this all together.
That’s how you can acquire, analyze, and generate analog data in MATLAB without writing code. Thank you.
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.