Differences in Performance Between Simulink and Matlab FIRs

조회 수: 1 (최근 30일)
Ethan Mok
Ethan Mok 2019년 4월 20일
댓글: Bharath Venkataraman 2019년 5월 20일
I am building a BPSK recovery system in Simulink, with the end goal of using the HDL coder to implement it on an FPGA.
I designed the algorithm in MATLAB first, and it works fine. However, translating it to Simulink is giving me trouble.
One of my first steps is to filter my data, which I implemented in MATLAB as
filfir2=fir1(100,[0.000001 8e6/Fs*2]); % Fs=30e6
data = filter(filfir2,1,data); %where data is the raw signal
Implementing the same thing in Simulink however, using the Digital Filter Designer (a 100 tap Hamming window direct form FIR with the same cutoff parameters, resulting in the same Bode plot), gives very different results with the same data:
The orange trace is the data filtered through the Simulink block, and the blue trace is the data filtered through Matlab and brought into Simulink with a From Workspace block.
I also tried
1) Importing my Simulink filter into Matlab and using it in Matlab before sending the filtered data to Simulink
2) Importing my Matlab filter (as a dffir block) into Simulink
Both performed identically to the original Matlab filter (i.e the blue trace).
I am wondering if there is a sample time issue or something where the actual simulation is what's causing the issue?
Thanks!
Ethan M.
Screen Shot 2019-04-20 at 5.44.09 PM.png
Screen Shot 2019-04-20 at 5.43.34 PM.png

답변 (7개)

Bharath Venkataraman
Bharath Venkataraman 2019년 4월 22일
I suggest using the the Discrete FIR Filter block with the coefficients you used for MATLAB. If that works, it is the easiest way forward, including for HDL code generation.

Ethan Mok
Ethan Mok 2019년 4월 22일
That is exactly what I did the first time as my default option. However, the results were the same as I displayed above.

Bharath Venkataraman
Bharath Venkataraman 2019년 4월 24일
Could you please pass along a complete script that runs?
I think Fs=30e6 from your comments, but I do not have data defined.

Bharath Venkataraman
Bharath Venkataraman 2019년 4월 24일
Attached is a model where I have taken your coefficients and ran them through fitler and the FIR Filter block. The numbers seem pretty close.
x = randn(1024,1);
Fs=30e6;
filfir2=fir1(100,[0.000001 8e6/Fs*2]);
y = filter(filfir2,1,x);
out = sim('fir_filter_model_18a');
y2 = out.simout.Data(:);
max(abs(y-y2))
figure
plot(y,'y')
hold on
plot(y2,'--r')
hold off

Ethan Mok
Ethan Mok 2019년 5월 17일
Sorry for very late response.
Attached is a zip containing the simulink model and a comparison to the matlab filter I used, as well as the data I am using.
I am also unable to download the simulink model you attached? Clicking on it links me to a page of unintelligible garbage instead of downloading the model.
  댓글 수: 1
Bharath Venkataraman
Bharath Venkataraman 2019년 5월 17일
I will take a look at your model.
Right click on my model and chosse teh Save Target as option to download the model.

댓글을 달려면 로그인하십시오.


Ethan Mok
Ethan Mok 2019년 5월 17일
Part of the problem as well is that the data I am using is a signed 12 bit integer, and when I filter it in simulink, the filter output obviously saturates at the limits of that datatype since the filter has no gain.
While I now understand why the filter was saturating in Simulink, I still don't know why the one in Matlab worked out.

Ethan Mok
Ethan Mok 2019년 5월 17일
I had a hidden factor of 3 in my simulink model (Fs vs Ts) that screwed everything up. Actually making the sample rates equal made everything work (since the normalized cutoffs are now actually the same)
Thanks for all the help
  댓글 수: 1
Bharath Venkataraman
Bharath Venkataraman 2019년 5월 20일
That's great. I have a model here that also shows the numbers are close. Attaching a modified script that shows this.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Optimization에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by