Extract signal from mp3 using multimedia file block in Simulink - matlab

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.

Related

ALSA Audio Capture block on 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.

Plotting in Matlab using Real Time data from Simulink

I'm trying to solve a problem of simulating in real time in Simulink (This is solved) but plotting (real time) in Matlab ?
Details:
I want to be able to run a Simulink simulation (which is running in real time) and be able to turn on / off manual switches while the simulation is happening. This works well when I'm using the built in Scopes in Simulink but now I want to export that data to Matlab in real time as well (To make a custom looking graph).
So is there a way, to export this data (it can be sampled if that is necessary) to Matlab and make a plot that is constantly updating. Meanwhile I can still manipulate the switches in Simulink and influence the simulation manually ?
Simulink is effectively running continuously until I stop it.
Thanks for the help!
There should be some kind of notification going when simulink updates the data to be visualized. Maybe this is the linkdata feature.
Another, worse, solution is the drawnow command to redraw the graphs continously (the latter could be unnescessary costly for you program).

How to play a row of numbers on an iPhone as audio?

I'm looking at an output of an electroencephalogram sensor. This data is displayed on screen in raw form at about 200Hz. I read that in the old times, it was possible to hook up such output to a speaker and hear the waveform, instead of seeing it. So I'm interested if it is possible to replicate this experiment with modern iPhone. How can I take a waveform that is displayed in a graph form and package it in such a way that it can be played through a iPhone's speakers live? In other words, I'm looking to stream EEG data through some sort of audio player and need to know how to create audio packets from this data on the fly.
Here's the raw waveform, it is displayed at 200 data points per second (200Hz)
After I clean up and process the waveform, I'm interested in how far it deviates from the average of the waveform. In this case, I think this can be played as a increasing/decreasing amplitude of a sine wave, which may be easier.
Thank you for your input
Here's a good tutorial on generating a sine tone for output through CoreAudio:
http://www.cocoawithlove.com/2010/10/ios-tone-generator-introduction-to.html
The RenderProc is the bit of code you're twiddling with, in the example they're using an NSSlider to change the frequency, you just need to feed it with your signal data instead.
One of the ideas that I had for playing sound in response to the signal amplitude change is to divide the amplitude into a set of discrete bands of values (for example 0-10, 10-20, 20-30, etc) and then assign a sound to each band. Then using audio services or system sound, it might be possible to loop a unique sound fragment for each band.

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.

Beat extraction in MATLAB

I have no experience in MATLAB and unfortunately my project is in MATLAB.
Basically the objective is to read a music source (preferably in mp3 format but .wav is also OK) into MATLAB and then apply a low pass filter in such a way that it filters everything except the beats. Then it should get the time at which each beat occurs and write the results to a text file.
It's quite a bit easier to work with .wav files I think, although Matlab way well have utilities for such things, in fact it does: Reading .wav
The easiest way to implement a low pass filter is a moving average filter.
The simplest way to do this would be be to loop over the data and take an average of each group of n values. I'm not sure exactly how the cutoff frequency would depend on n, but you could experiment a bit.
Otherwise, I know that there is a signal processing toolkit for Octave and I think that Matlab has a built-in filter function: https://ccrma.stanford.edu/~jos/fp/Matlab_Filter_Implementation.html
A third way which is over the top, would be to perform an FFT and do the filtering in the frequency domain.
Once you have the low-frequency part of the signal you can check for samples that are above an amplitude threshold and output where in the data these were found.
30 seconds on google with the keywords "beat extraction matlab" yield the following two code sources:
Music Audio Tempo Estimation and Beat Tracking
Beat This A Beat Synchronization Project
In Matlab you can use and state of the art Multi Feature beat tracker algorithm, the information of the algorithm is publish here:
J.R. Zapata, M. Davies and E. Gómez, "Multi-feature beat tracker," IEEE/ACM Transactions on Audio, Speech and Language Processing. 22(4), pp. 816-825, 2014. http://dx.doi.org/10.1109/TASLP.2014.2305252
The Matlab implementation of the multifeature beat tracker is:
https://github.com/JoseRZapata/MultiFeatureBeatTracking