how to plot y(t)

18 vues (au cours des 30 derniers jours)
Anwin Kushal
Anwin Kushal le 22 Jan 2021
Modifié(e) : VBBV le 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));

Réponses (2)

KSSV
KSSV le 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 commentaires
Anwin Kushal
Anwin Kushal le 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 le 13 Nov 2022
Modifié(e) : VBBV le 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)

Connectez-vous pour commenter.


Luan
Luan le 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

Catégories

En savoir plus sur Get Started with Signal Processing Toolbox dans Help Center et File Exchange

Produits


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by