필터 지우기
필터 지우기

plotting a multiple output function

조회 수: 4 (최근 30일)
Moussa Ihab
Moussa Ihab 2020년 5월 25일
댓글: Moussa Ihab 2020년 5월 26일
Hello!
I am quite new at Matlab
I have tried to plot a multiple output function but all i got is the first out put.
this is the code :
function [h, H] = myrct (t,f,beta)
% In optical communication systems, different linear pulse-shaping filters
% are used to generate continuous-time transmit signals. We can define
% these filters either through their impulse response hp(t) or their
% frequency response Hp( f )=F{hp(t)}, where F{ } stands for the Fourier
% transform.
% rct: Raised-cosine time domain (RCT-Filter)
% Time Domain
h = (1 + cos((pi./beta).*(abs(t)-(1-beta)/2)))/2;
h(abs(t)>(1+beta)/2) = 0;
h(abs(t)<(1-beta)/2) = 1;
h(abs(t)==1/2) = 1/2;
% Frequency Domain
% H = fftshift(fft(h),1);
H = sinc(f).*cos(pi.*beta.*f)./(1-(2*beta.*f).^2);
H(f == -0.5/beta) = sinc(1/(2*beta))*pi/4 ;
H(f == +0.5/beta) = sinc(1/(2*beta))*pi/4;
end
I tried to use :
figure
plot(myrct(t,f,beta))
hold on
It doesn't work and it plots only the first output 'h'.
i tried also
figure
plot(H)
hold on
but I got a msg of Unrecognized function or variable 'h'.
Here are the constants:
l=randi(50,1)
N=randi(50,1)
t=(-l*N/2:l*N/2-1)'/N;
f=(-l*N/2:l*N/2-1)'/l;
beta=rand(1)
please help me with this

채택된 답변

Geoff Hayes
Geoff Hayes 2020년 5월 25일
Moussa - rather than trying to calculate and plot the results of the myrct in one like like
plot(myrct(t,f,beta))
split this into two lines to make clear what the outputs are for myrct. Try
[h, H] = myrct(t,f,beta);
figure;
plot(h);
hold on;
plot(H);
or however you want to do this. If I recall correctly, if you just call the function without specifying the output parameters like
[h, H] = myrct(t,f,beta);
then myrct(t,f,beta) will just return the first output parameter, the h. Note also that you need to explicilty set the output parameters in order to be able to reference them. We do that with the above line of code. When you don't do that and then try to reference (later) h or H you will get an error like you mentioned above Unrecognized function or variable 'h'.
  댓글 수: 1
Moussa Ihab
Moussa Ihab 2020년 5월 26일
Thank you
it works very well

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by