how to plot y(t)

18 visualizaciones (últimos 30 días)
Anwin Kushal
Anwin Kushal el 22 de En. de 2021
Editada: VBBV el 13 de Nov. de 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));

Respuestas (2)

KSSV
KSSV el 22 de En. de 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 comentarios
Anwin Kushal
Anwin Kushal el 22 de En. de 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 el 13 de Nov. de 2022
Editada: VBBV el 13 de Nov. de 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)

Iniciar sesión para comentar.


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

Categorías

Más información sobre Get Started with Signal Processing Toolbox en Help Center y File Exchange.

Productos


Versión

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by