Upsample by adding zeros between input samples 您所在的位置:网站首页 mathworkscn Upsample by adding zeros between input samples

Upsample by adding zeros between input samples

#Upsample by adding zeros between input samples| 来源: 网络整理| 查看: 265

Generate Frames of Random Input Samples

Set up workspace variables for the object to use. The object supports scalar and vector inputs. For vector inputs, the input data must be a column vector of size 1 to 64.

L = 8; % Upsample factor O = 2; % Sample offset scalar = true; if scalar vecSize = 1; value = 1; else vecSize = 2; %#ok % multiple or factor of L value = vecSize*L; end numFrames = 1; dataSamples = cell(1,numFrames); framesize = zeros(1,numFrames); refOutput = []; WL = 0; % word length FL = 0; % fraction length

Generate Reference Output from Function

Generate frames of random input samples and apply the upsample function. You can use the output that this function generates as a reference against which to compare the output of the System object.

totalsamples = 0; for i = 1:numFrames framesize(i) = randi([5 200],1,1); dataSamples{i} = fi(randn(vecSize,framesize(i)),1,16,8); ref_upsample= upsample((dataSamples{i}(:)),L,O); refOutput = [refOutput,ref_upsample]; %#ok end

Run Function Containing System Object

This example uses the HDLUpsample function for a scalar input and HDLUpsample_Vec function for a vector input. Set the properties of the System object in these functions to match the input data properties.

function [dataOut,validOut] = HDLUpsample(dataIn,ValidIn) persistent hdlUSObj if isempty(hdlUSObj) hdlUSObj = dsphdl.Upsampler('UpsampleFactor',8,'SampleOffset',2,'NumCycles',8); end [dataOut,validOut] = hdlUSObj(dataIn,ValidIn); end function [dataOut,validOut] = HDLUpsample_Vec(dataIn,ValidIn) persistent hdlUSObj if isempty(hdlUSObj) hdlUSObj = dsphdl.Upsampler('UpsampleFactor',8,'SampleOffset',2,'NumCycles',1); end [dataOut,validOut] = hdlUSObj(dataIn,ValidIn); end

Insert the required number of idle cycles after each frame using the latency variable to avoid invalid output data.

latency = 3; dataOut = zeros(value,totalsamples+numFrames*latency); validOut = zeros(1,totalsamples+numFrames*latency); idx=0; for ij = 1:numFrames dataIn = zeros(vecSize,size(dataSamples{ij},2)*L); validIn = upsample(true(1,length(dataSamples{ij})),L); dataIn(:,validIn) = dataSamples{ij}; if scalar for ii = 1:length(validIn) idx = idx+1; [dataOut(:,idx),validOut(idx)] = HDLUpsample( ... fi(dataIn(:,ii),1,16,8), ... validIn(ii)); end for ii = 1:latency idx = idx+1; [dataOut(:,idx),validOut(idx)] = HDLUpsample( ... fi(zeros(vecSize,1),1,16,8), ... false); end else for ii = 1:length(validIn) %#ok idx = idx+1; [dataOut(:,idx),validOut(idx)] = HDLUpsample_Vec( ... fi(dataIn(:,ii),1,16,8), ... validIn(ii)); end for ii = 1:latency idx = idx+1; [dataOut(:,idx),validOut(idx)] = HDLUpsample_Vec( ... fi(zeros(vecSize,1),1,16,8), ... false); end end end

Compare Function Output with Reference Output

Compare the output of the HDL function with the output of the upsample function.

HDLOutput = dataOut(:,validOut==1); HDLOutput = HDLOutput(:); fprintf('\n Upsampler\n'); difference = (abs(HDLOutput-refOutput(1:length(HDLOutput)))>0); fprintf(['\nTotal number of samples differed between Behavioral ' ... 'and HDL simulation: %d \n'],sum(difference)); Upsampler Total number of samples differed between Behavioral and HDL simulation: 0


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有