how to plot y(t)

17 次查看(过去 30 天)
Anwin Kushal
Anwin Kushal 2021-1-22
编辑: VBBV 2022-11-13
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));

回答(2 个)

KSSV
KSSV 2021-1-22
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 个评论
Anwin Kushal
Anwin Kushal 2021-1-22
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 2022-11-13
编辑:VBBV 2022-11-13
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)

请先登录,再进行评论。


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

类别

Help CenterFile Exchange 中查找有关 Get Started with Signal Processing Toolbox 的更多信息

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by