Unable to see fft output during co-simulation.

3 次查看(过去 30 天)
I am converting the following code to VHDL but after cosimulation I am only seeing validOut, how can I see the fft output as well?
function [yOut, validOut] = HDLFFT(yIn, validIn)
persistent fftObj;
if isempty(fftObj)
fftObj = dsphdl.FFT(FFTLength=128)
end
[yOut, validOut] = fftObj(yIn, validIn);
end
the main function
N = 1024;
Fs = 800000;
number_of_samples = 0:N-1;
time = (0:N-1)*Fs;
signal = cos(2*pi*200000*time);
sampled_signal = cos(2*pi*8*number_of_samples/Fs);
signal_fixed = fi(sampled_signal,0,32,24);
signal_zeros = zeros(1, N);
validOut = false(1,N);
for loop = 1:1:3*N
if (mod(loop, N) == 0)
i = N;
else
i = mod(loop, N);
end
[signal_zeros(loop),validOut(loop)] = HDLFFT128_final((signal_fixed(i)),(loop <= N));
end
signal_zeros = signal_zeros(validOut == 1);
fft_reverse = bitrevorder(signal_zeros);
disp(fft_reverse);
figure(1)
stem(0:N-1,fft_reverse)
title('FFT')
the above is testbench

采纳的回答

Sahas
Sahas 2024-7-11
As per my understanding, when the code file is executed, it does not return the required FFT “yOut” variable value.
I was able to verify the issue and have provided a modified script that executes FFT function with the required FFT “yOut” output.
The issue was arising because the function defined in the main code was “HDLFFT” and it was being called as “HDLFFT128_final” in the testbench.
% Modified script
function [yOut, validOut] = HDLFFT(yIn, validIn) %function name
persistent fftObj;
if isempty(fftObj)
fftObj = dsphdl.FFT('FFTLength', 128);
end
[yOut, validOut] = fftObj(yIn, validIn);
end
N = 1024;
Fs = 800000;
number_of_samples = 0:N-1;
time = (0:N-1) / Fs;
signal = cos(2*pi*200000*time);
sampled_signal = cos(2*pi*8*number_of_samples/Fs);
signal_fixed = fi(sampled_signal, 0, 32, 24);
signal_zeros = zeros(1, N);
validOut = false(1, N);
for loop = 1:1:3*N
if (mod(loop, N) == 0)
i = N;
else
i = mod(loop, N);
end
[signal_zeros(loop), validOut(loop)] = HDLFFT(signal_fixed(i), (loop <= N)); % function being called
end
signal_zeros = signal_zeros(validOut);
fft_reverse = bitrevorder(signal_zeros);
disp(fft_reverse);
figure(1)
stem(0:length(fft_reverse)-1, fft_reverse)
title('FFT Output')
Here are some documentation links which might be helpful:
  1. Compute fast Fourier transform (FFT) - MATLAB - MathWorks India – FFT using DSP HDL Toolbox
  2. Fast Fourier transform - MATLAB fft - MathWorks India – Basic understanding of FFT
I hope this is useful.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Code Generation 的更多信息

产品


版本

R2024a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by