|
x = [1 1 0 1 0 1 1 1 0 1 ]
m=10
P=0.5
% x=2*round(rand(1,m)+P-0.5)-1;
% % x = round(rand(1,m))
figure(5)
stem(x)
t0=300;
t=0:1/t0:length(x);
for i = 1:length(x)
if(x(i) ==1)
for j = 1 : t0/2;
y( t0/2 * (2 * i - 2) + j ) = 1;
y( t0/2 * (2 * i - 1) + j ) = 0;
end
else
for j = 1 : t0/2;
y( t0/2 * (2 * i - 2) + j ) = -1;
y( t0/2 * (2 * i - 1) + j ) = 0;
end
end
end
y = [y , x(i)];
M = max(y);
m = min(y);
figure(1)
plot(t,y);grid on;
axis([0,i,m-0.1,M+0.1])
Ts=1;
N=i;
N_sample=150;
dt = Ts/N_sample;
df = 1.0/(20.0*Ts);
t = -10*Ts:dt:10*Ts;
f = -2/Ts:df:2/Ts;
alpha = 0.2;
for n = 1:length(alpha)
for k = 1 : length(f)
if abs(f(k))>0.5*(1+alpha(n))/Ts
Xf(n,k) = 0;
elseif abs(f(k))<0.5*(1-alpha(n))/Ts
Xf(n,k) = Ts;
else
Xf(n,k) = 0.5*Ts*(1+cos(pi*Ts/(alpha(n))+eps)*(abs(f(k))-0.5*(1-alpha((n))/Ts)));
end
end
xt(n,:) = sinc(t/Ts).*(cos(alpha(n)*pi*t/Ts))./(1-4*alpha(n)^2*t.^2/Ts^2+eps);
end
figure(2);
plot(t,xt)
axis([-10 10 -0.5 1.1])
%
r = conv(y,xt)
figure(3)
plot(r)
這是代碼 |
|