이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
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 (한국어)