clear;
close all;
s1=0.535*exp(1i*2*pi/3); s2=0.535*exp(1i*pi); s3=0.535*exp(1i*4*pi/3);
a1=-0.268-0.154*1i; a2=0.535; a3=-0.268+0.154*1i;
w=linspace(0,pi,200);
H1=a1./(2*((1-exp(-1i*w))/(1+exp(-1i*w)))-s1);
H2=a2./(2*((1-exp(-1i*w))/(1+exp(-1i*w)))-s2);
H3=a3./(2*((1-exp(-1i*w))/(1+exp(-1i*w)))-s3);
H=H1+H2+H3;
subplot(1,2,1);
plot(w/pi,abs(H));
ylabel('abs(H)');
xlabel('w/pi (rad/cycle)');
subplot(1,2,2);
plot(w/pi,20*log10(abs(H)));
ylabel('dB');
xlabel('w/pi (rad/cycle)');
My graph above gives me 2 blank graphs when I run the code and I don't know why, can anyone that is more experienced with matlab tell me why? Thanks in advance

댓글 수: 1

Sander Grosemans
Sander Grosemans 2021년 4월 19일
I found it has to do that H is just a value, while it is supposed to be a double. But I still don't know how to fix it

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

 채택된 답변

Star Strider
Star Strider 2021년 4월 19일

0 개 추천

Use element-wise division (./) instead of (/) and it works —
s1=0.535*exp(1i*2*pi/3); s2=0.535*exp(1i*pi); s3=0.535*exp(1i*4*pi/3);
a1=-0.268-0.154*1i; a2=0.535; a3=-0.268+0.154*1i;
w=linspace(0,pi,200);
H1=a1./(2*((1-exp(-1i*w))./(1+exp(-1i*w)))-s1);
H2=a2./(2*((1-exp(-1i*w))./(1+exp(-1i*w)))-s2);
H3=a3./(2*((1-exp(-1i*w))./(1+exp(-1i*w)))-s3);
H=H1+H2+H3;
subplot(1,2,1);
plot(w/pi,abs(H));
ylabel('abs(H)');
xlabel('w/pi (rad/cycle)');
subplot(1,2,2);
plot(w/pi,20*log10(abs(H)));
ylabel('dB');
xlabel('w/pi (rad/cycle)');
See the documentation on Array vs. Matrix Operations for an extended discussion. .

댓글 수: 2

Sander Grosemans
Sander Grosemans 2021년 4월 19일
Thank you so much it works! Wishing you and your family a good health in these difficult times
Star Strider
Star Strider 2021년 4월 19일
As always, my pleasure!
I wish you and your family the same!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품

릴리스

R2020a

질문:

2021년 4월 19일

댓글:

2021년 4월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by