├── README.md ├── SECURITY.md ├── license.txt └── pulse_detector ├── Pulse Detector HDL Tutorial.pdf ├── solution ├── pulse_detector_v1.slx ├── pulse_detector_v2.slx ├── pulse_detector_v3.slx └── pulse_detector_v4.slx └── work ├── compareData.m ├── demoMode.m ├── getLogged.m ├── pulse_detector_reference.mlx ├── pulse_detector_v1_tb.mlx ├── pulse_detector_v2_tb.mlx ├── pulse_detector_v3_tb.mlx └── pulse_detector_v4_tb.mlx /README.md: -------------------------------------------------------------------------------- 1 | # HDL Coder Self Guided Tutorial 2 | [![Open in MATLAB Online](https://www.mathworks.com/images/responsive/global/open-in-matlab-online.svg)](https://matlab.mathworks.com/open/github/v1?repo=mathworks/HDL-Coder-Self-Guided-Tutorial) 3 | [![View HDL Coder Self-Guided Tutorial on File Exchange](https://www.mathworks.com/matlabcentral/images/matlab-file-exchange.svg)](https://www.mathworks.com/matlabcentral/fileexchange/69651-hdl-coder-self-guided-tutorial) 4 | 5 | This tutorial will guide you through the steps necessary to implement a MATLAB algorithm in FPGA hardware, including: 6 | * Create a streaming version of the algorithm using Simulink 7 | * Implement the hardware architecture 8 | * Convert the design to fixed-point 9 | * Generate and synthesize the HDL code 10 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Reporting Security Vulnerabilities 2 | 3 | If you believe you have discovered a security vulnerability, please report it to 4 | [security@mathworks.com](mailto:security@mathworks.com). Please see 5 | [MathWorks Vulnerability Disclosure Policy for Security Researchers](https://www.mathworks.com/company/aboutus/policies_statements/vulnerability-disclosure-policy.html) 6 | for additional information. -------------------------------------------------------------------------------- /license.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018-2025, The MathWorks, Inc. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | * In all cases, the software is, and all modifications and derivatives of the 14 | software shall be, licensed to you solely for use in conjunction with 15 | MathWorks products and service offerings. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 21 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 24 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | -------------------------------------------------------------------------------- /pulse_detector/Pulse Detector HDL Tutorial.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mathworks/HDL-Coder-Self-Guided-Tutorial/3dae40534e05d8ba3f586ff2b29c0e940eb6b664/pulse_detector/Pulse Detector HDL Tutorial.pdf -------------------------------------------------------------------------------- /pulse_detector/solution/pulse_detector_v1.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mathworks/HDL-Coder-Self-Guided-Tutorial/3dae40534e05d8ba3f586ff2b29c0e940eb6b664/pulse_detector/solution/pulse_detector_v1.slx -------------------------------------------------------------------------------- /pulse_detector/solution/pulse_detector_v2.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mathworks/HDL-Coder-Self-Guided-Tutorial/3dae40534e05d8ba3f586ff2b29c0e940eb6b664/pulse_detector/solution/pulse_detector_v2.slx -------------------------------------------------------------------------------- /pulse_detector/solution/pulse_detector_v3.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mathworks/HDL-Coder-Self-Guided-Tutorial/3dae40534e05d8ba3f586ff2b29c0e940eb6b664/pulse_detector/solution/pulse_detector_v3.slx -------------------------------------------------------------------------------- /pulse_detector/solution/pulse_detector_v4.slx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mathworks/HDL-Coder-Self-Guided-Tutorial/3dae40534e05d8ba3f586ff2b29c0e940eb6b664/pulse_detector/solution/pulse_detector_v4.slx -------------------------------------------------------------------------------- /pulse_detector/work/compareData.m: -------------------------------------------------------------------------------- 1 | % 2 | % Copyright 2019 The MathWorks, Inc. 3 | % 4 | function err_vec = compareData(reference,actual,figure_number,textstring) 5 | 6 | % Vector input only 7 | if ~isvector(reference) || ~isvector(actual) 8 | error('Input signals must be vector'); 9 | else 10 | if isrow(reference) 11 | reference = transpose(reference); 12 | end 13 | if isrow(actual) 14 | actual = transpose(actual); 15 | end 16 | end 17 | 18 | % Make signals same length if necessary 19 | if length(reference) ~= length(actual) 20 | % warning(['Length of reference (%d) is not the same as actual signal (%d).'... 21 | % ' Truncating the longer input.'],length(reference),length(actual)); 22 | len = 1:min(length(reference),length(actual)); 23 | reference = reference(len); 24 | actual = actual(len); 25 | end 26 | 27 | % Turn complex into vector 28 | if xor(isreal(reference),isreal(actual)) 29 | error('Input signals are not both real or both complex'); 30 | elseif ~isreal(reference) 31 | ref_vec = double([real(reference) imag(reference)]); 32 | act_vec = double([real(actual) imag(actual)]); 33 | tag = {'(Real)','(Imag)'}; 34 | else 35 | ref_vec = double(reference); 36 | act_vec = double(actual); 37 | tag = {''}; 38 | end 39 | 40 | % Configure figure 41 | if iscell(figure_number) 42 | if size(ref_vec,2) > 1 % complex 43 | error('Cannot yet subplot multiple complex inputs'); 44 | else 45 | figure(figure_number{1}) 46 | end 47 | else 48 | figure(figure_number) 49 | end 50 | c = get(groot,'defaultAxesColorOrder'); 51 | 52 | % Compute error 53 | err_vec = ref_vec - act_vec; 54 | max_err = max(abs(err_vec)); 55 | max_ref = max(abs(ref_vec)); 56 | fprintf('\nMaximum error for %s out of %d values\n',textstring,length(actual)); 57 | 58 | 59 | for n = 1:size(ref_vec,2) 60 | fprintf('%s %d (absolute), %d (percentage)\n',tag{n},max_err(n),max_err(n)/max_ref(n)*100); 61 | if iscell(figure_number) 62 | total_plot = figure_number{2}; 63 | plot_num = figure_number{3}; 64 | else 65 | total_plot = size(ref_vec,2); 66 | plot_num = n; 67 | end 68 | subplot(total_plot,1,plot_num) 69 | plot(ref_vec(:,n),'Color',c(3,:)); 70 | hold on 71 | plot(act_vec(:,n),'Color',c(1,:)); 72 | plot(err_vec(:,n),'Color',c(2,:)); 73 | legend('Reference','Actual','Error') 74 | hold off 75 | title(sprintf('%s %s, max error = %.3d',textstring,tag{n},max_err(n))); 76 | end 77 | end 78 | -------------------------------------------------------------------------------- /pulse_detector/work/demoMode.m: -------------------------------------------------------------------------------- 1 | % 2 | % Copyright 2019 The MathWorks, Inc. 3 | % 4 | function demoMode(varargin) 5 | % demoMode or demoMode('on') adds the folder containing the solution models 6 | % to MATLAB path. The folder is not added if any of the models is already 7 | % on the path. 8 | % 9 | % demoMode('off') removes the folder from MATLAB path. 10 | 11 | if nargin == 0 12 | mode_flag = 'on'; 13 | elseif nargin == 1 14 | mode_flag = varargin{:}; 15 | else 16 | error('Too many input arguments, only 0 or 1 expected.'); 17 | end 18 | 19 | switch lower(mode_flag) 20 | case 'on' 21 | m1 = which('pulse_detector_v1.slx'); 22 | m2 = which('pulse_detector_v2.slx'); 23 | m3 = which('pulse_detector_v3.slx'); 24 | if ~isempty(m1) 25 | error('Model already exists:\n%s',m1); 26 | elseif ~isempty(m2) 27 | error('Model already exists:\n%s',m2); 28 | elseif ~isempty(m3) 29 | error('Model already exists:\n%s',m3); 30 | else 31 | addpath('../solution'); 32 | disp('Added model folder ../solution to path'); 33 | end 34 | 35 | case 'off' 36 | rmpath('../solution'); 37 | disp('Removed folder ../solution from path'); 38 | otherwise 39 | error('Undefined input argument'); 40 | end 41 | -------------------------------------------------------------------------------- /pulse_detector/work/getLogged.m: -------------------------------------------------------------------------------- 1 | % 2 | % Copyright 2020 The MathWorks, Inc. 3 | % 4 | function signal_val = getLogged(simout_obj,signal_name) 5 | 6 | logsout = simout_obj.logsout; 7 | if isempty(logsout) 8 | error('No logged signal found. Make sure ''%s'' is logged in the model',... 9 | signal_name); 10 | end 11 | 12 | sig = logsout.getElement(signal_name); 13 | if isempty(sig) 14 | error('Signal ''%s'' not found. Make sure it is logged and named correctly.',... 15 | signal_name); 16 | end 17 | 18 | signal_val = squeeze(sig.Values.Data); 19 | 20 | end 21 | -------------------------------------------------------------------------------- /pulse_detector/work/pulse_detector_reference.mlx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mathworks/HDL-Coder-Self-Guided-Tutorial/3dae40534e05d8ba3f586ff2b29c0e940eb6b664/pulse_detector/work/pulse_detector_reference.mlx -------------------------------------------------------------------------------- /pulse_detector/work/pulse_detector_v1_tb.mlx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mathworks/HDL-Coder-Self-Guided-Tutorial/3dae40534e05d8ba3f586ff2b29c0e940eb6b664/pulse_detector/work/pulse_detector_v1_tb.mlx -------------------------------------------------------------------------------- /pulse_detector/work/pulse_detector_v2_tb.mlx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mathworks/HDL-Coder-Self-Guided-Tutorial/3dae40534e05d8ba3f586ff2b29c0e940eb6b664/pulse_detector/work/pulse_detector_v2_tb.mlx -------------------------------------------------------------------------------- /pulse_detector/work/pulse_detector_v3_tb.mlx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mathworks/HDL-Coder-Self-Guided-Tutorial/3dae40534e05d8ba3f586ff2b29c0e940eb6b664/pulse_detector/work/pulse_detector_v3_tb.mlx -------------------------------------------------------------------------------- /pulse_detector/work/pulse_detector_v4_tb.mlx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mathworks/HDL-Coder-Self-Guided-Tutorial/3dae40534e05d8ba3f586ff2b29c0e940eb6b664/pulse_detector/work/pulse_detector_v4_tb.mlx --------------------------------------------------------------------------------