MATLAB Answers

plotting a multiple output function

6 views (last 30 days)
Moussa Ihab
Moussa Ihab on 25 May 2020
Commented: Moussa Ihab on 26 May 2020
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

  0 Comments

Sign in to comment.

Accepted Answer

Geoff Hayes
Geoff Hayes on 25 May 2020
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 Comment

Moussa Ihab
Moussa Ihab on 26 May 2020
Thank you
it works very well

Sign in to comment.

More Answers (0)

Products


Release

R2020a

Translated by