how to plot y(t)

19 views (last 30 days)
Anwin Kushal
Anwin Kushal on 22 Jan 2021
Edited: VBBV on 13 Nov 2022
Tell me what is wrong with my code ? i didnt get the expected graph
Root Raised Cosine Filter..
clc;clear all; close all;
fs=10;
Ts = 1/fs;
c = 10;
t = -1:0.01:1;
b=1;
T=1/fs;
Nt=-Ts/(2*b);
Pt=Ts/(2*b);
y=@(t) ((1/Ts)*(1+(b*((4/pi)-1)))) .*(t==0) + ((b/(Ts*sqrt(2))) * ( ((1+2/pi)*(sin(pi/(4*b)))) + ((1-(2/pi))*cos(pi/(4*b))) )) ...
.*((t==Nt) | (t==Pt)) + ((1/Ts).*((sin(pi*(t/Ts)*(1-b)) + (4*b*(t/Ts).*(cos(pi*(t/Ts)*(1+b))))) / (pi*(t/Ts).*(1-(4*b*(t/Ts)).^2)))) ...
.*((t~=Nt) & (t~=Pt) & (t~=0));
plot(t,y(t));

Answers (2)

KSSV
KSSV on 22 Jan 2021
Check the expressions thoroughly....not sure did I enter correct.
fs=10;
Ts = 1/fs;
c = 10;
t = -1:0.01:1;
b=1;
T=1/fs;
Nt=-Ts/(2*b);
Pt=Ts/(2*b);
h = zeros(size(t)) ;
for i = 1:length(t)
if t(i) ==0
h(i) = (1/Ts)*(1+(b*((4/pi)-1))) ;
elseif abs(t(i)) == Ts/(4*b)
h(i) = b/(Ts*sqrt(2))*((1+2/pi)*sin(pi/(4*b))+(1-2/pi)*cos(pi/(4*b))) ;
else
h(i) = 1/Ts*(sin(pi*t(i)/Ts*(1-b))+4*b*t(i)/Ts*cos(pi*t(i)/Ts*(1+b)))/(pi*t(i)/Ts*(1-(4*b*t(i)/Ts)^2)) ;
end
end
plot(t,h);
  3 Comments
Anwin Kushal
Anwin Kushal on 22 Jan 2021
above method works
but in this code output should be zero due to the condition but it say NaN why??
Nt=-Ts/(4*b);
Pt=Ts/(4*b);
t=0
h = zeros(size(t)) ;
h=@(t) (((1/Ts).*((sin(pi*(t/Ts)*(1-b)) + (4*b*(t/Ts).*(cos(pi*(t/Ts)*(1+b)))))...
/ (pi*(t/Ts).*(1-(4*b*(t/Ts)).^2)))) ).*(t~=0)
h(t)
output:
t = 0
h =
@(t)(((1/Ts).*((sin(pi*(t/Ts)*(1-b))+(4*b*(t/Ts).*(cos(pi*(t/Ts)*(1+b)))))/(pi*(t/Ts).*(1-(4*b*(t/Ts)).^2))))).*(t~=0)
ans = NaN
VBBV
VBBV on 13 Nov 2022
Edited: VBBV on 13 Nov 2022
h=@(t) (((1/Ts).*((sin(pi*(t/Ts)*(1-b)) + (4*b*(t/Ts).*(cos(pi*(t/Ts)*(1+b)))))...
./ (pi*(t/Ts).*(1-(4*b*(t/Ts)).^2)))) ).*(t~=0);
% ^^ ^^
% example
t = 0;
y = 1/t % a very large number which cannot be known
y = Inf
To get the desired output, you need to suppy the vector t using your anonymous function
fs=10;
Ts = 1/fs;
c = 10;
t = -1:0.01:1 % give this vector
t = 1×201
-1.0000 -0.9900 -0.9800 -0.9700 -0.9600 -0.9500 -0.9400 -0.9300 -0.9200 -0.9100 -0.9000 -0.8900 -0.8800 -0.8700 -0.8600 -0.8500 -0.8400 -0.8300 -0.8200 -0.8100 -0.8000 -0.7900 -0.7800 -0.7700 -0.7600 -0.7500 -0.7400 -0.7300 -0.7200 -0.7100
b=1;
T=1/fs;
Nt=-Ts/(4*b);
Pt=Ts/(4*b);
h = zeros(size(t)) ;
h=@(t) (((1/Ts).*((sin(pi*(t/Ts)*(1-b)) + (4*b*(t/Ts).*(cos(pi*(t/Ts)*(1+b)))))...
./ (pi*(t/Ts).*(1-(4*b*(t/Ts)).^2)))) ).*(t~=0)
h = function_handle with value:
@(t)(((1/Ts).*((sin(pi*(t/Ts)*(1-b))+(4*b*(t/Ts).*(cos(pi*(t/Ts)*(1+b)))))./(pi*(t/Ts).*(1-(4*b*(t/Ts)).^2))))).*(t~=0)
y = h(t);
idx = find(t == 0);
y(idx) = (1/Ts)*(1+(b*((4/pi)-1)));
plot(t,y)

Sign in to comment.


Luan
Luan on 13 Nov 2022
I am a new intow, would anyone show me how to plot
y(t)= 1/3(2e^-t+1-3e^-2t)
Thanks

Categories

Find more on Get Started with Signal Processing Toolbox in Help Center and File Exchange

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!