Simulink Desktop Real-Time and Least Mean Square adaptive algorithm - matlab

I need to implement an LMS-based adaptive audio-cancellation algorithm on the Simulink Desktop Real-Time toolbox.
The physical system is composed of a microphone recording a noise source and another microphone recording the residual noise after the control process (antinoise being injected by a speaker controlled by Simulink).
For the (adaptive) LMS algorithm to work properly I need to be able to work on a sample-by-sample basis, that is at each sampled time instant I need to update the adaptive filter using the synchronised current sample value of both microphones. I realise some delay is inevitable but I was wondering whether it's possible on Simulink Desktop Real-Time to reduce the buffer size of the inputs to one sample and thus work on a sample-by-sample basis.
Thanks for your help in advance.

You can always implement the filter on a sample by sample basis.
But you still need a history of input values to perform the actual LMS calculation on. On a sample by sample basis this would just mean using a simple FIFO buffer.
If you have access to the DSP Toolbox then there is already an LMS Filter block that will do this for you.

Related

How to use Simlink PID tools to implement a controller in matlab

I was wondering if it is possible to use simlink's PID architecture in matlab to actually control hardware - rather than modelling it.
I have been playing around a little with the PID tuning in matlab - and have worked out the correct gains for my system (or at least good enough).
Now I want to implement the actual control loop in matlab using the real hardware. In this case I am tying to stabilise a laser using a measurement from a wavemeter - although from the point of view of matlab essentially I have two functions - one which returns the current wavelength, and another which alters the wavelength with an input from 0-100.
How do I get the fancy PID objects to work in a loop where for example I input data each loop, and get the required output to stabilise things given my gains - or should I just hardcode the equations in?
I have tried looking through some of the simlink examples - but there doesn't seem to me much actual implementation - mostly just modelling.
Thanks in advance for any advice.
MATLAB (without Simulink, or with Simulink in purely a simulation mode) is not a real-time environment. Trying to use it to control hardware in real-time won't work unless you have very slow sample rates.
If you do have slow sample rates, then you'd connect to your hardware to MATLAB using device drivers such as those in the Data Acquisition Toolbox
You haven't found any info on real-time implementation in the Simulink documentation because from Simulink the mechanism for real-time implementation is via Simulink Coder. You would need to use it in conjunction with a real-time environment such as Simulink Desktop Real-Time (if your sample rates are relatively slow), Simulink Real-Time, or one of many other 3rd party real-time form factors.

Converter control simulation on simulink

I am struggling with a little project I decided to tackle. I am trying to replicate an example I found on a book using matlab simulink but I have no experience with simulink and control theory (I do understand the principles etc.).
The control block diagram is given but I do not understand some blocks and how to add my input (sine wave block on simulink)?
Here are the details:
Example I wish to reproduce
Schematic of the converter and desired control block diagram
If anyone could give me a little insight or direct me to some examples from which I could build on an understanding would be great!
Thank you in advance.
The portion entitled controller is the closed-loop feedback control for the system. K(s) would typically contain some type of PI control. In a more complicated control system, the structure of K(s) may be a little different, but will usually always contain an integration in order to ensure that the system eventually settles at the desired value.
The input Iref is your current command. In this case you would inject your sinusoid here which would produce a current waveform matching your desired output. If your desired output.
Output m is the modulating waveform produced by the controller. Everything inside the half-bridge converter section is a representation of the converter and everything that it is interfaced to (voltage sources).
The feedforward filter here is also a very important component. Since Vs contains an alternating waveform, the feed forward filter allows the system to respond to changes in Vs without relying on feedback compensation K(s). This helps to decouple current regulation from changes in voltage VD.
To start with the project, you can probably build the half bridge converter as shown. You can inject 400*cos(377t - pi/2) as VD.
For the feedback compensator K(s) you can feed the input into two gains (Ki and Kp) which you will select values for later. At the output of Ki insert an integrator (1/s) then sum the output of Kp and the integrator together.
For the feed-forward filter, you should probably just use a low pass filter with a gain of 1 at DC. The low pass filter prevents noise from entering the system. In this case you are running a simulation, so there will be no noise. However, the filter will eliminate any algebraic loops, which can cause warnings or errors in the simulation.
You can input your control signal at Iref.

Which input format is the best for sound recognition in recurrent neural networks?

I want to create sound or pitch recognition with recurrent deep neural network. And I'm wondering with what input will I get best results.
Should I feed DNN with amplitudes or with FFT(Fast Fourier transform) result?
Is there any other format that is known to produce good results and fast learning?
While MFCCs have indeed been used in music information retrieval research (for genre classification etc...), in this case (pitch detection) you may want to use a semi-tone filterbank or constant Q transform as a first information reduction step. These transformations match better with musical pitch.
But I think it's also worth trying to use the audio samples directly with RNNs, in case you have a huge number of samples. In theory, the RNNs should be able to learn the wave patterns corresponding to particular pitches.
From your description, it's not entirely clear what type of "pitch recognition" you're aiming for: monophonic instruments (constant timbre, and only 1 pitch sounding at a time)? polyphonic (constant timbre, but multiple pitches may be sounding simultaneously)? multiple instruments playing together (multiple timbres, multiple pitches)? or even a full mix with both tonal and percussive sounds? The hardness of these use cases roughly increases in the order I mentioned them, so you may want to start with monophonic pitch recognition first.
To obtain the necessary amount of training examples, you could use a physical model or a multi-sampled virtual instrument to generate the audio samples for particular pitches in a controlled way. This way, you can quickly create your training material instead of recording it and labeling it manually. But I would advise you to at least add some background noise (random noise, or very low-level sounds from different recordings) to the created audio samples, or your data may be too artificial and lead to a model that doesn't work well once you want to use it in practice.
Here is a paper that might give you some ideas on the subject:
An End-to-End Neural Network for Polyphonic Piano Music Transcription
(Siddharth Sigtia, Emmanouil Benetos, and Simon Dixon)
https://arxiv.org/pdf/1508.01774.pdf
The Mel-frequency cepstrum is general used for speech recognition.
mozilla DeepSpeech is using MFCCs as input to their DNN.
For python implementation you can use python-speech-features lib.

Remove noise from magnetometer data

I want to use data from a magnetometer to gain information about the motion of a metal object near it. After recording the data, I need to remove noise from the data before using it. What is a good method to remove noise? I read about filters in Matlab here but cannot decide which one to use. How can I decide which filter to use?
Edit:
The metal object moves at a steady rate and I want to find out the angle of its motion. I am adding a graph from my sample data which I want to filter. Sample Magnetometer data
I guess you're able to record the noise. And if you can do it, yo can also use some adaptive filtering.
From MathWorks' Overview of Adaptive Filters and Applications:
Block Diagram That Defines the Inputs and Output of a Generic RLS Adaptive Filter
You can use recorded noise as desired signal and your error signal should be around 0 without any motion near it, and should have some filtered value when the motion appears.
You can find an example of adaptive filtering on the MathWorks website:
Consider a pilot in an airplane. When the pilot speaks into a microphone, the engine noise in the cockpit combines with the voice signal. This additional noise makes the resultant signal heard by passengers of low quality. The goal is to obtain a signal that contains the pilot's voice, but not the engine noise. You can cancel the noise with an adaptive filter if you obtain a sample of the engine noise and apply it as the input to the adaptive filter.
Read more about adaptive filtering:
Overview: http://www.mathworks.com/help/dsp/ug/overview-of-adaptive-filters-and-applications.html
NN adaptive filters: http://www.mathworks.com/help/nnet/ug/adaptive-neural-network-filters.html

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.