www.gusucode.com > dsp 案例源码程序 matlab代码 > dsp/HDLCodeGenerationFromHDLFIRRateConverterExample.m
%% Design for HDL Code Generation from HDL FIR Rate Converter % Create a rate conversion function targeted for HDL code generation, and a % test bench to exercise it. The function converts a signal from 40 MHz to % 100 MHz. To avoid overrunning the object, the test bench manually controls % the input rate. %% % Define the sample rate and length of the input signal, and a fixed-point % cosine waveform. Fs = 40e6; Ns = 50; t = (0:Ns-1).'/Fs; x = fi(cos(2*pi*1.2e6*t), 1, 16, 14); %% % Define the rate conversion parameters. Use an interpolation factor of 5 % and a decimation factor of 2. Calculate how often the object can accept a % new data sample. L = 5; M = 2; stepsPerInput = ceil(L/M); numSteps = stepsPerInput*Ns; %% % Generate |dataIn| and |validIn| based on how often the object can accept % a new sample. dataIn = zeros(numSteps,1,'like',x); dataIn(1:stepsPerInput:end) = x; validIn = false(numSteps,1); validIn(1:stepsPerInput:end) = true; %% % Create a *Logic Analyzer* to capture and view the input and output % signals. la = dsp.LogicAnalyzer('NumInputPorts',4,'SampleTime',1/Fs,'TimeSpan',numSteps/Fs); addWave(la,'InputChannel',1,'Name','dataIn','Format','Analog','Height',5) addWave(la,'InputChannel',2,'Name','validIn') addWave(la,'InputChannel',3,'Name','dataOut','Format','Analog','Height',5) addWave(la,'InputChannel',4,'Name','validOut') %% % Write a function that instantiates the System object and calls |step|. % % <include>HDLFIRRC5_2.m</include> % %% % Resample the signal by calling the function for each data sample. for k = 1:numSteps [dataOut,validOut] = HDLFIRRC5_2(dataIn(k),validIn(k)); step(la, dataIn(k), validIn(k), dataOut, validOut) end