How to pass complex double value of array in the workspace to "HDL FFT block-DSP HDL toolbox block" to generate HDL code
3 次查看(过去 30 天)
显示 更早的评论
Fayaz
2023-7-13
script:
FFT_OUTPUT = fft(ARRAY);% TAKE FFT FOR THE SAMPLES
worspace:
what are the blocks shoulb be added before the FFT block prior to pass the complex double (fixed point value?)
采纳的回答
Bharath Venkataraman
2023-7-14
I assume the data you are showing is for a 512 point FFT and you have 20 frames of data.
I would first serialize this data using reshape the data:
ARRAY2 = ARRAY(:);
Check to make sure that ARRAY2(1:10) has the right order of data you expect to send in to the FFT.
The attached model uses the Signal From Workspace block to get the data into the Simulink model and uses the data type conversion block to convert it to fixed point before feeding it to the FFT block. I have the set teh input valid to be true all the time - this is something you can modify if needed.
The sample time for the Signal From Workspace is set to 1sec, so I run the model 512*20 seconds to get the 20 frames of data in. Because of the FFT latency, you will get about 18-19 frames of data out. To get all the 20 frames out, you can add another 600 seconds to the Stop Time.
Hope this helps,
Bharath
16 个评论
Fayaz
2023-7-15
THANK YOU so much sir. once aganin thanx for sparing your time for me. i will go throuh the steps that you have mentioned.
can i contact you to clarify some doubts? i would be grateful to you
Fayaz
2023-7-15
sir, if i can add a "To workspace" block at output of "data conversion to Double", i should a get the same output coming in the script ouput in the workspace from " FFT_OUTPUT = fft(ARRAY)", isnt it ?
Bharath Venkataraman
2023-7-15
Yes, that is largely true, but because of fixed point and implementation differences, the values will not be exact. Attached is a model and script that compare the two implementations. Run the script and you will see some differences, but they are not large.
Fayaz
2023-7-16
>> fft_compare
Unrecognized function or variable 'hdlfft_data'.
Error in fft_compare (line 14)
hdlfft_valid_data = hdlfft_data(hdlfft_valid);
############## I AM GETTING AN ERROR , It seems that hdfft_data might be a custom function or a part of a library specific to your environment. it is not supporting for my r2023a
Bharath Venkataraman
2023-7-16
I have updated my answer above - the hdlfft_data needed to be gathered from the Simulink model output logsout. This is now done in line 13.
Fayaz
2023-7-17
thank you so much sir. i have a question about the code, in line 3, you have converted the double to signed fixed point value and again in the simulink, you are using a convertion to fi(1,10,8). We can pass the double value to "signla from workspace" and in the converter, we can directly convert to fi(1,10,8) or else we canvert to fixed pint (1,10,8) directly in the script and pass it the"signal from workspace".if you dont mind, can you explain me the any special reason for it
Bharath Venkataraman
2023-7-17
You are right - we do not need to convert the values two times. You can remove one of the conversions.
Fayaz
2023-7-17
Ok,,,,,,,,,,
i did the same you have done. I used the conversion as fi(1,18,16) as this word length is preferable for FPGA implementation ( which is mentioned by the mathwork tutorial). I got real and imag errors respectively aroung 4. and 5. ,,, that is considerabely a huge value. what can i do for that sir?
Bharath Venkataraman
2023-7-17
I removed the data type conversion from the Simulink model and left it in line 3 of the script. Changing the data type to 1,18,16 and running the fft_compare script give max differences of ~2e-4.
Fayaz
2023-7-18
Still im getting the same answer. which is,
Max real diff is 4.434067
Max imag diff is 4.996368
my "fft_ou1" has big real value:
real(max(fft_out1)) = 4.366128658879322
so my point is, there should be a real value in the "hdlfft_valid_data_frame1" near to real part of "fft_out1", isnt it?but it is,"real(max(hdlfft_valid_data_frame1)) = -0.186767578125000"
imaginary part is fishy:
imag(max(fft_out1)) = 2.438102782136530
imag(max(hdlfft_valid_data_frame1)) = 0.608795166015625
but the difference shows around 4.996368, it should be something 2.438102782136530 - 0.608795166015625 =1.8
########## i will attach my files, if you dont mind can you look over it, and help me to fix the bug, i would be a huge help
Fayaz
2023-7-18
#############SIR ANOTHER HUGE HELP SIR.................
Sir,you are the only one responding my questions and helping me. You have given me guidance for the "NCO" opration process to make it work, but still i have confusion and not able to get the correct block system for that case of frequency shifting. I studied and tried up with applying "LUT-look up table". I dont know it is using a LUT is correct or not for the process, according the MATLAB script of frequency shifting,
fs_shift1 = 4;
fs_u = 30.72;
Reverse_NCO_out_20 = combined_carrier_shifted_20.*exp(-1i*2*pi*fs_shift1/fs_u*(1:length(combined_carrier_shifted_20)));
the length of "combined_carrier_shifted_20" is multiplied with phase, so in that case do we have to add a LUT? i dont know.
Sir im in the around the corner of submission of my undergraduate project and as im an undergraduate, have lack of knowledge about the MATLAB and not interacted much with it, not aware of advance things in MATALB because started use it for the final year project only. Its difficult to get good practice and knowledge within a short period with those high technical base documents available in matlab and cources are too expensive. So, sir kindly request you to consider and i would be much more grateful to you
Bharath Venkataraman
2023-7-21
编辑:Bharath Venkataraman
2023-7-21
I redid the calculation to calculate the fft on the multi-channel data. The differences are much smaller now.
Fayaz
2023-7-25
编辑:Fayaz
2023-7-30
% array = sin(0:2*pi/128:2*pi-2*pi/128); % 1x128 array
% array1 = repmat(array,1,4); % 1x512
array1 = fi(ARRAY,1,18,16); % fixed point
array2 = array1(:);
% Behavioral FFT
fft_out1 = fft(double(array1));
fft_out2 = fft_out1(:);
% Run HDL FFT model
open_system("FFTHDL_model.slx")
sim("FFTHDL_model.slx")
% Get output of HDLFFT model
hdlfft_data = squeeze(logsout.getElement('fft_data_out').Values.Data);
hdlfft_valid = squeeze(logsout.getElement('fft_vld_out').Values.Data);
hdlfft_valid_data = hdlfft_data(hdlfft_valid);
% Difference between HDL and behavioral output
last_idx = 10240;
fft_diff = fft_out2(1:last_idx)-hdlfft_valid_data(1:last_idx);
fprintf("Max real diff is %f\n", max(real(fft_diff)));
fprintf("Max imag diff is %f\n", max(imag(fft_diff)));
fft_diff = fft_out2(1:last_idx)-hdlfft_valid_data(1:last_idx);
in the above line you are calculating the difference etween 'fft_out2' which is doubel precision floating point value and 'hdlfft_valid_data' is fixed point value. Is that correct, two diffenret data types are there, isnt it?
please consider this ........................................
Fayaz
2023-7-25
#############SIR ANOTHER HUGE HELP SIR.................
Sir,you are the only one responding my questions and helping me. You have given me guidance for the "NCO" opration process to make it work, but still i have confusion and not able to get the correct block system for that case of frequency shifting. I studied and tried up with applying "LUT-look up table". I dont know it is using a LUT is correct or not for the process, according the MATLAB script of frequency shifting,
fs_shift1 = 4;
fs_u = 30.72;
Reverse_NCO_out_20 = combined_carrier_shifted_20.*exp(-1i*2*pi*fs_shift1/fs_u*(1:length(combined_carrier_shifted_20)));
the length of "combined_carrier_shifted_20" is multiplied with phase, so in that case do we have to add a LUT? i dont know.
Sir im in the around the corner of submission of my undergraduate project and as im an undergraduate, have lack of knowledge about the MATLAB and not interacted much with it, not aware of advance things in MATALB because started use it for the final year project only. Its difficult to get good practice and knowledge within a short period with those high technical base documents available in matlab and cources are too expensive. So, sir kindly request you to consider and i would be much more grateful to you
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)