How to sample a signal from a continuous time domain in to a input port digital design (Simulink to HDL integration) - matlab

I am doing Simulink based Hardware software co-simulation. I have a simulink block which is outputing fixed point 32 bit data in a continuous domain. I want to send this data to an HDL design again in fixed point 32 bit format. Whenever i integrate the two blocks together, i am getting error. I tried adding quantizer but it only works on uint/double data types which is not acceptable to the HDL block. How can I discretize the data such that it is acceptable in the RTL domain? If i add unit delay,it works but the data is delayed which is not fair
Thanks a lot for your help

To sample a continuous signal and convert it to digital electronics, you usually need an ADC: "Analog to digital converter".
You should start by googling ADC integration.

Related

how to optimize (reduce) the latency in the verilog HDL code (hardware) generated by the MATLAB HDL CODER add-on from a given Simulink model?

Thanks in advance,
I am having a simple Simulink model, that takes in a 32-bit number in the IEEE-754 format and adds the same number, which gives the output again in the 32-bit wide IEEE-754 format. I used MATLAB's HDL CODER add-on and generated the Verilog HDL code for the same. When I wrote a testbench for the same, I found the latency I get from this code is 100ns. But is there a way I can reduce this to even further, say some 10ns.
Below I am attaching the Simulink model I used to generate the Verilog HDL code, along with the generated Verilog files. Also, I am attaching a screenshot of the simulation in case you don't want to waste your time running the scripts
Link to download the files
my point is how to use pipeline settings before conversion
I am assuming that "pipeline settings" is a MATLAB HDL generator parameter.
Basically what you do is "try": use a pipeline setting and synthesize the code. If you have slack you can:
Reduce the number of pipeline stages.
or
Increase the clock frequency.
(For negative slack you use the inverse methods)
Now here is where things get tricky:
Most of the time you can't really speed things up. A certain functionality needs a time to calculate. Some algorithms can be sped up by using more parallel resources but only up tot a limit. An adder is good example: you can have ripple carry, carry look-ahead and more advanced techniques, but you can not speed up infinitely. (Otherwise CPUs these days would be running at Terra Hz)
I suspect in the end you will find that it takes T time to do your IEEE-754 adder. That can be X clock cycles of an A MHz. clock or Y clock cycles of B MHz. But X times A is about the same as Y times B.
What you can do is pump lots of calculations into your pipe so a new one comes out every clock cycle. But the latency will still be there.

Matlab & Simulink - replacing with octave and others to run digital filters [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
hello dear experts and user
i am currently planning to create a little system for Real Time ECGSignal Transmission [and] for Remote Monitoring
therefore i need to use Matlab and Simulink - (in order to run digital filters)
the question is: can i use the both systems free or do i need to find another systems and programs to substitute the above mentioned to realize the project;
matlab &/ Simulink - Simulation und Model-Based Design - MATLAB & Simulink
https://de.mathworks.com/products/simulink.html
what is wanted; cf Real Time ECGSignal Transmission forRemote Monitoring
https://www.ijedr.org/papers/IJEDR1303068.pdf
Abstract-Our main objective is to implement a monitoring system which monitors the heart pulse of a patient. This work presents a novel easy-to-use system intended for the fast and non invasive monitoring of the Lead I electrocardiogram (ECG) signal by using a wireless steering wheel. The steering wheel used here is a prototype model. A novel heart rate detection algorithm based on the continuous wavelet transform has been implemented, which is specially designed to be robust against the most common sources of noise and interference present when acquiring the ECG in the hands. Skin Electrodes were used to record the nerve voltages for monitoring the heart pulse. The voltages recorded will be sent to an instrumentation amplifier which amplifies the signal, and then to a filter which filters the noise. Thus, analog signal is given to Analog-to-Digital Convertor (ADC) of Arduino. There, analog voltages are been converted to digital and that digital values will be stored in the EEPROM of Arduino. The values stored in EEPROM will be sent to PC via XBEE (IEEE 802.15.4) wirelessly and a serial port will be opened in the MATLAB by using a serial object. GUI is programmed to make the user interface interactive and simple. Using the real time plot, I’ve plotted the values received by XBEE module and making a running waveform which displays when the MATLAB sent a query to Arduino.
love to hear from you
best regards
If you are planning to scavenge some existing code written in Matlab but want to transition to a free software solution instead, then GNU Octave is probably your best bet.
If you are looking for a Simulink equivalent compatible with Octave, I suggest you check out this page. You may also want to read about the Octave-Scilab co-simulation package, that would allow you to take advantage of Scilab's Simulink like package Xcos while working under Octave.
On the other hand, if you are writing your program from scratch, you could also go for Python, along with the bms toolbox, which is presented as an "open-source equivalent to simulink in Python".

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.

Simulink Desktop Real-Time and Least Mean Square adaptive algorithm

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.

Simulink sim of rician channel ber process

I'm learning simulink and I want to use the rician channle block from the communications blockset. I'm told I need to change the format format. Would anyone have some sample code where they used the rician channels in simulink to model a bit error rate process?
MathWorks appears to have a tutorial on the subject. Have you taken a look at that?