ALSA Audio Capture block on Simulink - simulink

I need to read and work into a matlab code block with the data coming from the "Raspberry Pi ALSA Audio Capture block" inside Simulink frame. I'm using Matlab r2013a and matlab r2013b, with raspberry Pi Simulink libraries.
That's because i need to develope a special audio analysis.
So my question is: How can I read the stream of data coming from the "Raspberry Pi Audio Capture" block, and modify them before to "plot" or "record" the modified data into a file?
And how to plot such a kind of data in a streaming plot?
And how to record such a kind of data into a file?
Thank you!

Do you have DSP System toolbox? Start by looking at the audio Example in that toolbox. There are many of them. For plotting you need scope blocks. You can find them under "Sinks" in Simulink library. For writing you need "To Multimedia File" block which is also in DSP System toolbox.

Related

Data from LabVIEW to Matlab for processing

I want to make a biometric identification system of the ECG/EKG.
Provided that Matlab does not perform Data Acquisition in Real Time (for monitoring), is there any way to make the monitoring and data acquisition in LabVIEW and then work simultaneously with Matlab for signal processing?
You could just get a matlab compatible daq and run everything in matlab. http://www.mathworks.com/products/daq/
You can indeed do some data acquisition with LabView and work simultaneously with Matlab for signal processing by calling the Matlab script node, which executes some Matlab code during vi execution.
You may have some performance issues, though, because both Labview and Matlab have to run on your machine simultaneously.
Question:
is there any way to make the monitoring and data acquisition on
LabView and then work simultaneously with Matlab for signal processing
Answers:
LabVIEW has "MathScript" node which is basic MatLab built into
an add-on. It is not the MatLab toolboxes. It runs native MatLab
code. It also runs slightly faster LabVIEW updates to the code. If
your code runs there, then LabVIEW will pass data natively
to your code. This box does not have direct MatLab toolbox access, so if
you use any special calls then that can cause a problem.
If you have MatLab on the box, then you can call the external MatLab
function/code using mathscript (link), and the MatLab will run
the function.
Clarification:
Real time just means "bounded time" (link), not "instant". If your idea of bounds are loose enough then many systems can work for them. You do not state it in your question - but what do you consider acceptable response time?
I've worked a lot with LabVIEW and Matlab. Personally, I would not use the Math Scripting node and would opt for using the Matlab Automation Server. You can call Matlab from LabVIEW using the ActiveX palette in LabVIEW (See Functions>>Connectivity>>ActiveX>>Automation Open) A couple reasons why I'd go for ActiveX and NOT the MathScript node:
The Math Script node does not allow you to change code dynamically. You must hardcode your data into the Math Script node and any future changes would require a change to LabVIEW's G code and therefore a recompile of your EXE
The Math Script node does not support all functions when compiled to an executable. Most notably graphing functions. See the help file here to read more on this.
Calling Matlab from ActiveX is going to give you a lot more flexibility in regards to how data is passed and processed.

connecting RC circuit to s-function block in Simulink

Can I connect an RC circuit from the Simscape library (as a feedback) to an s-function block and apply a time series as input? I am trying to use the Linearize tool from Control Design to obtain the frequency response of the whole system.
Yes, you can. You need to use the PS-Simulink Converter block to convert the physical signals from your electrical sensor blocks to Simulink signals, and the Simulink-PS Converter block to convert the Simulink signals from your S-function into physical signals to feed into electrical source blocks. Beware of creating algebraic loops though.

How to use Simulink to output to real time microcontroller

I want to design a system that has to read some values from sensors through Arduino microcontroller using Matlab.
I want to use the simulink inputs as the sensors and the output to the motors,
I wrote an app to do that on Arduino, and also I wrote some functions in Matlab to read these sensors and to control the output, but I want to use simulink to implement a Fuzzy logic Controller the input is the values of sensors and the output is the speed.
If you wrote the functions for MATLAB in C, you can put your code in an S-Function, whether it is for sensor input or actuator output.
Otherwise, either use Embedded M file or S-function in your Simulink model.

Extract signal from mp3 using multimedia file block in Simulink

I have a multimedia file block in Simulink, and I'm using it to play out of my speakers. It's working fine, but I'm wondering if there's a way to extract the signal in MATLAB using get_param or something similar. I want to plot the entire signal on a GUI, so I need to have the entire signal before I play it.
I ended up using a dsp.AudioFileReader to read my song. Not even bothering with the from Multimedia File, because I don't know how to get the entire signal from that quickly (it outputs at the sampling rate, I wanted to plot the signal before playing the song).
I created a while loop and stepped through the dsp.AudioFileReader quickly enough and then played my song through the multimedia block.
Can you connect your multimedia block to a 'To File' or a 'To Workspace' block? That would save the signal to a file that you could later load in, or directly to a workspace variable. You could then plot it, or incorporate it into your GUI, within MATLAB.

Real time speech transformation in MATLAB

Is it possible to transform speech (pitch/formant shift) in (near) real-time using MATLAB? How can it be done?
If not, what should I use to do that?
I need to get input from the microphone, visualise the sound wave, add a filter to it, see the oscilloscope again, and play back the modified sound.
The real-time visualization (spectrogram) can be created with SparkNG package by Hideki Kawahara.
Sure. There's a demo application up on the MATLAB Central File Exchange that does something similar. It reads in a signal from the sound card (requires Data Acquisition Toolbox) in near real time, applies an FFT transform - you could do something else like applying a filter - and visualises the results in 3D graphs live. You could use it as a template and modify it to your needs, such as visualising in different ways (more of an oscilloscope style), or outputting the sound as a .wav file for later playback.
If you need properly real time, you might look into implementing in Simulink rather than just base MATLAB.