www.gusucode.com > dsp 案例源码程序 matlab代码 > dsp/CreateAVectorInputFFTForHDLGenerationExample.m
%% Create a Vector-Input FFT for HDL Generation %% % Create specifications and input signal. This example uses a % 128-point FFT and computes the transform over 16 samples at a time. N = 128; V = 16; Fs = 40; t = (0:N-1)'/Fs; x = sin(2*pi*15*t) + 0.75*cos(2*pi*10*t); y = x + .25*randn(size(x)); y_fixed = sfi(y,32,24); y_vect = reshape(y_fixed,V,N/V); %% % Write a function that instantiates the System object(TM) and calls the % |step| method. The function does not need to know the vector size. The % object saves the size of the input signal the first time you call |step|. % % <include>HDLFFT128V16.m</include> % %% % Compute the FFT by passing 16-element vectors to the |step| method. Use the % |getLatency| method to find out when the first output data sample will be % ready. Then, add the frame length to determine how many times to call the % object. Because the object instance is in the function, use a dummy instance % of the object to call the method. Use the loop counter to flip |validIn| % to false after N input samples. a = dsp.HDLFFT; loopCount = a.getLatency(N,V)+N/V; Yf = zeros(V,loopCount); validOut = false(V,loopCount); for loop = 1:1:loopCount if ( mod(loop,N/V) == 0 ) i = N/V; else i = mod(loop,N/V); end [Yf(:,loop),validOut(loop)] = HDLFFT128V16(complex(y_vect(:,i)),(loop<=N/V)); end %% % Discard invalid output samples. C = Yf(:,validOut==1); Yf_flat = C(:); %% % Plot the frequency channel data from the FFT. The FFT output is in % bit-reversed order. Reorder it before plotting. Yr = bitrevorder(Yf_flat); plot(Fs/2*linspace(0,1,N/2),2*abs(Yr(1:N/2)/N)); title('Single-Sided Amplitude Spectrum of Noisy Signal y(t)'); xlabel('Frequency (Hz)'); ylabel('Output of FFT(f)');