www.gusucode.com > dsp 案例源码程序 matlab代码 > dsp/HDLFIRRateConverterInterp6PortExample.m

    %% Control Output Rate When Upsampling 
% Convert a signal from 40 MHz to 100 MHz using the HDL FIR Rate Converter System
% object(TM). Use the optional |request| input signal to control the output 
% data rate. When the object receives the |request| signal, it returns a new 
% output data sample. This example models a clock rate of 200 MHz by requesting an
% output sample every second call to the step method. 
%%
% Define the sample rate and length of the input signal, and a fixed-point 
% cosine waveform. Create a |SignalSource| object to provide data samples
% on demand. 
Fs = 40e6;                                  
Ns = 50;                                    
t = (0:Ns-1).'/Fs;                          
x = fi(cos(2*pi*1.2e6*t),1,16,14);          
inputSource = dsp.SignalSource(x);          
%%
% Define the rate conversion parameters. Use an interpolation factor of 5 and 
% a decimation factor of 2. Determine the number of calls to the |step| method 
% needed to convert _Ns_ samples.  
L = 5;                                      
M = 2;                 
numSteps = floor(2*Ns*L/M);
%% 
% Create the System object and configure it to perform rate conversion
% using the specified factors and an equiripple FIR filter. Enable the
% optional |ready| and |request| ports.
Numerator = firpm(70, [0,.15,.25,1], [1,1,0,0]);      
rateConverter = dsp.HDLFIRRateConverter(L,M,Numerator,...
                                        'ReadyPort',true,...
                                        'RequestPort',true); 
%%
% Create a *Logic Analyzer* to capture and view the input and output signals.
la = dsp.LogicAnalyzer('NumInputPorts',6,'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','request')
addWave(la,'InputChannel',4,'Name','dataOut','Format','Analog','Height',5)
addWave(la,'InputChannel',5,'Name','validOut')
addWave(la,'InputChannel',6,'Name','ready')
%%
% Generate a signal that requests a new output sample every second call to the 
% |step| method. 
request = false(numSteps,1);
request(1:2:end) = true; 
%%
% Initialize the |ready| signal. The object is always ready for input data on 
% the first call to the |step| method.
ready = true;
%%
% Execute the |step| method of the System object to perform the rate
% conversion and obtain each output sample. Apply a new input sample when 
% the object indicates it is ready. Otherwise, set |validIn| to |false|.
% The object returns valid output samples when |request| is set to |true|.
for k = 1:numSteps  
    if ready
        dataIn = step(inputSource);
    end
    validIn = ready;
    [dataOut,validOut,ready] = step(rateConverter,dataIn,validIn,request(k));
    step(la, dataIn, validIn, request(k), dataOut, validOut, ready)    
end