You are on page 1of 19

Đề 1

%De 1 bai 1
data= struct([]);
data= struct('name',[],'birthday',[],'gender',[]);
data.name(1).name=['van'];
data.name(2).name=['minh'];
data.name(3).name=['thai'];
data.name(4).name=['lan'];
data.name(1).birthday=['30/04/1996'];
data.name(2).birthday=['1/1/1996'];
data.name(3).birthday=['2/2/1996'];
data.name(4).birthday=['3/3/1996'];
data.name(1).gender=['nam'];
data.name(2).gender=['nam'];
data.name(3).gender=['nam'];
data.name(4).gender=['nam'];
data.name(1).salary = [3000, 5000, 3.5000, 5000];
data.name(2).salary = [7000, 6000, 3.5000, 4000];
data.name(3).salary = [5000, 6000, 15000, 4000];
data.name(4).salary = [7000, 8000, 10000, 3000];
data.name(1).time = [1 2 3 4];
data.name(2).time = [1 2 3 4];
data.name(3).time = [1 2 3 4];
data.name(4).time = [1 2 3 4];
data.name(1).average = sum(data.name(1).salary)/ length(data.name(1).time);
data.name(2).average = sum(data.name(2).salary)/ length(data.name(2).time);
data.name(3).average = sum(data.name(3).salary)/ length(data.name(3).time);
data.name(4).average = sum(data.name(4).salary)/ length(data.name(4).time);
data.name(1)
data.name(2)
data.name(3)
data.name(4)

%De 1 bai 2
% tao ma tran A va B
A=[1 4 6; 3 6 2; 8 9 1];
B=[2 3 1; 6 4 3; 0 8 2];
% cau a
disp('Ma tran A1=A*B: ')
A1=A*B
disp('Ma tran A2=A/B: ')
A2=A/B

% cau b
disp('Ma tran logic A>B: ')
A3=A>B
disp('Ma tran logic A<B: ')
A4=A<B
disp('Ma tran logic A|B: ')
A5=A|B

%cau c
A6= reshape(A,1,9)
%De 1 bai 3
%Tinh nghiem phuong trinh bac 2 ax^2+bx+c=0
a=input('Nhap a = ')
b=input('Nhap b = ')
c=input('Nhap c = ')

delta=b*b-4*a*c;
if delta > 0
disp('Phuong trinh co 2 nghiem phan biet');
x1=(-b+sqrt(delta))/(2*a)
x2=(-b-sqrt(delta))/(2*a)
elseif delta == 0
disp('Phuong trinh co nghiem kep')
x1=x2== -b/(2*a)
else delta < 0
disp('Phuong trinh vo nghiem')
end

Đề 2
% de 2
% cau 1 khong lam cu the nh?ng l?nh gi?ng
%tao ma tran (2,2), bớt hàng bớt cột, nhân 2 ma trận
clc;
clear;
n1=input('nhap so hang cua ma tran A : ');
n2=input('nhap so cot cua ma tran A : ');
n3=input('nhap so hang cua ma tran B: ');
n4=input('nhap so cot cua ma tran B: ');
for i=1:n1
for j=1:n2
fprintf('A(%d,%d)= ',i,j);
A(i,j)=input(' ');
end
end

disp(A);
for i =1:n3
for j=1:n4
fprintf('B(%d,%d)= ', i,j);
B(i,j)=input(' ');
end
end
disp(B);
disp ( 'Xoa cot thu 2 trong ma tran A')
E3=A(:,2)
disp ( 'Xoa hang thu 1 trong ma tran B')
E4=B(1,:)
disp('Ma tran A2=A+B la : ');
A2=A+B

%cau 2 chưa đúng


clc
clear all

Tp=4; %chu ky xung


Tw=Tp/2;
N=3; %so chu ky xung
t=-Tp/2:0.001:Tp/2;
L=length(t);
a=[];b=[];c=[];time=[];time1=[];rect_t=[];tri_t=[];

%------xung vuong
T=Tp/2;
for i=1:L
if abs(t(i))<=T/2
a(i)=1;
else
a(i)=0;
end
end
%---------bien doi fourier
pho_rect=fftshift(abs(fft(a)));
pho_tri=fftshift(abs(fft(b)));
pho_exp=fftshift(abs(fft(exp_t)));

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d= randi(1,10 );
h=find(d==1);
for i=1:length(d)
if mod(i,2)==0
d(h(i))=-1;
else d(h(i))=1;
end
end
Tb=10;
R=1/Tb;
Timewindow=Tb*length(d);
fs=1000;
t=0:Tb/fs:Timewindow-Tb/fs;
for i=1:length(t)
if(mod(t(i),Tb)>=0.5*Tb)
y(i)=0;
else
k=floor(t(i)/Tb)+1;
y(i)=d(k);
end
end
plot(t,y,'linewidth',2);
axis([min(t) max(t) -1.5 1.5]);
grid on
%cau 2
clc
clear all

Tp=10; %chu ky xung


Tw=Tp/2;
N=5; %so chu ky xung
t=-Tp/2:0.001:Tp/2;
L=length(t);
a=[];b=[];c=[];time=[];time1=[];rect_t=[];tri_t=[];

%------xung vuong
T=Tp/2;
for i=1:L
if abs(t(i))<=T/2
a(i)=1;
else
a(i)=0;
end
end
for k=1:N
time=[time (k-1)*Tp+t];
% time1=[time1 (k-1)*Tp+t1];
rect_t=[rect_t a];
tri_t=[tri_t b];
end
exp_t=exp(-time);
%---------ve hinh
figure (1)
subplot (2,1,1)
plot(time,rect_t);

%subplot (3,1,2)
%plot(time1,tri_t);

subplot (2,1,2)
plot(time,exp_t);

%---------bien doi fourier


pho_rect=fftshift(abs(fft(a)));
pho_tri=fftshift(abs(fft(b)));
pho_exp=fftshift(abs(fft(exp_t)));

%------------ve pho
figure(2)
subplot(2,1,1)
plot(pho_rect)
%subplot(3,1,2)
%plot(pho_tri)
subplot(2,1,2)
plot(pho_exp)
%cau 2 RZ 50% với T0=10, N=5, biến đổi fourier, dáp ứng biên độ, đáp ứng
pha(Đúng)
clc
clear all

Tp=10; %chu ky xung


Tw=Tp/2;
N=5; %so chu ky xung
t=-Tp/2:0.001:Tp/2;
L=length(t);
a=[];b=[];c=[];time=[];time1=[];rect_t=[];tri_t=[];

%------xung vuong
T=Tp/2;
for i=1:L
if abs(t(i))<=T/2
a(i)=1;
else
a(i)=0;
end
end
for k=1:N
time=[time (k-1)*Tp+t];
% time1=[time1 (k-1)*Tp+t1];
rect_t=[rect_t a];
tri_t=[tri_t b];
end
exp_t=exp(-time);
figure (1)
subplot (2,1,1)
plot(time,rect_t);
subplot (2,1,2)
plot(time,exp_t);

%---------bien doi fourier


pho_rect=fftshift(abs(fft(a)));
pho_tri=fftshift(abs(fft(b)));
pho_exp=fftshift(abs(fft(exp_t)));

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d= randi(1,10 );
h=find(d==1);
for i=1:length(d)
if mod(i,2)==0
d(h(i))=-1;
else d(h(i))=1;
end
end
Tb=10;
R=1/Tb;
Timewindow=Tb*length(d);
fs=1000;
t=0:Tb/fs:Timewindow-Tb/fs;
for i=1:length(t)
if(mod(t(i),Tb)>=0.5*Tb)
y(i)=0;
else
k=floor(t(i)/Tb)+1;
y(i)=d(k);
end
end
plot(t,y,'linewidth',2);
axis([min(t) max(t) -1.5 1.5]);
grid on

%cau 3 khong chay (sai)


V=randint(1,80);
id=1;
for i=1:10
for j=1:8
y(i,j)=V(id);
id=id+1;
end;
end;
y
V1=bi2de(y,'left-msb');
Đề 3
%De 3 bai 1: giai he phuong trinh sau
% cau a giải hệ sắp xếp
A=[5 4 1 -4; 1 -2 -8 1; -9 1 11 -23; 13 9 -21 -41];
B=[-9; -22; 34; 22];
disp('Nghiem cua he phuong trinh la: ')
X=inv(A)*B;
for i=1:length(X)
for j=i+1:length(X)
if(X(i)>X(j))
temp=X(i);
X(i)=X(j);
X(j)=temp;
end
end
end
disp('Nghiem he phuong sau khi duoc sap xem tu nho den lon la:')
X

% cau b
for i=1:length(X)
if (X(i)<0)
X(i)=0;
end
end
disp('Nghiem he phuong trinh: am thi bang 0, duong thi giu nguyen:')
X
%De 3 bai 2 ve xung tam giac, biến đổi fourier, đáp ứng xung- làm giống câu 2
đề 2 chỉ khác xung tam giác
%cau a
function[t,y]=xungtamgiac(To,fs,N)
%To chu ki xung
%fs tan so xung
%N: so luong xung co trong chuoi
To=10;
Tw=To/2;% do rong xung
N=5;
tN=N*To;%thoi gian quan sat
fs=1000;%tan so lay mau
Ts=1/fs;%thoi gian lay mau
y=[];
for t=0:Ts:tN
y1=1-abs((mod(t,To)-Tw)/Tw);
y=[y y1];
end
t=0:Ts:tN;
plot(t,y)
end

%De 3 bai 3 chuong trinh tinh dien tich


%cau a and cau b
a=input('Nhap a = ')
b=input('Nhap b = ')
r=input('Nhap r = ')
dientich=input('Nhap loai tinh dien tich: ')
switch(dientich)
case{1}
disp('Dien tich hinh chu nhat la: ')
S=a*b
case{2}
disp('Dien tich hinh vuong la: ')
S=a*a
case{3}
disp('Dien tich hinh tron la: ')
S=pi*r*r
otherwise
disp('Khong hop le')

end
Đề 4
%De 4 bai 1 dinh nghia cau truc data tương tự đề 1. Nhưng thiếu phần D tìm số
sinh vuên đạt điều kiện học bổng
data= struct([]);
data= struct('name',[],'birthday',[],'gender',[]);
data.name={'van','minh','thai','lan'};
data.birthday={'30/04/1996','1/1/1996','2/2/1996','3/3/1996'};
data.gender={'nam','nam','nam','nu'};
data.name=struct('name',[],'birthday',[],'gender',[]);
data.name(1).score = [10, 10, 9];
data.name(2).score = [9, 9, 10];
data.name(3).score = [8, 9, 8];
data.name(4).score = [9, 9, 8];
data.name(1).subject = [1 2 3];
data.name(2).subject = [1 2 3];
data.name(3).subject = [1 2 3];
data.name(4).subject = [1 2 3];
data.name(1).average = sum(data.name(1).score)/ length(data.name(1).subject);
data.name(2).average = sum(data.name(2).score)/ length(data.name(2).subject);
data.name(3).average = sum(data.name(3).score)/ length(data.name(3).subject);
data.name(4).average = sum(data.name(4).score)/ length(data.name(4).subject);
data

%De 4 bai 2 tao vecto A(1,30) va vecto cot B(30,1)


A=(1:30)
B=[30;29;28;27;26;25;24;23;22;21;20;19;18;17;16;15;14;13;12;11;10;9;8;7;6;5;4
;3;2;1]
%cau a
B=B'
%cau b
for i=1:length(A)
for j=1:length(B)
if(A(i)<B(i))
A(i)=0;
else
A(i)=A(i);
end
end
end
A

%cau c
GTTB=sum(A)/length(A)
Phuongsai=(sum((1:30)-GTTB)^2)/length(A)

%De 4 bai 3
%Tinh nghiem phuong trinh bac 2 ax^2+bx+c=0
a=input('Nhap a = ')
b=input('Nhap b = ')
c=input('Nhap c = ')

delta=b*b-4*a*c;
if delta > 0
disp('Phuong trinh co 2 nghiem phan biet');
x1=(-b+sqrt(delta))/(2*a)
x2=(-b-sqrt(delta))/(2*a)
elseif delta == 0
disp('Phuong trinh co nghiem kep')
x1=x2== -b/(2*a)
else delta < 0
disp('Phuong trinh vo nghiem')

end

Đề 5
%De 5 bai 1: giai he phuong trinh sau
% cau a
A=[113 34 9 -4; 201 -29 -83 100; -93 51 11 -23; 132 94 -21 -41];
B=[319; -22; 140; 221];
disp('Nghiem cua he phuong trinh la: ')
X=A\B
for i=1:length(X)
for j=i+1:length(X)
if(X(i)<X(j))
temp=X(i);
X(i)=X(j);
X(j)=temp;
end
end
end
disp('Nghiem he phuong sau khi duoc sap xem tu lon ve be la:')
X

% cau b
for i=1:length(X)
if (X(i)<10)
X(i)=0;
end
end
disp('Nghiem he phuong trinh: nho hon 10 thi bang 0, giu nguyen cac ket qua
con lai:')
X

%De 5 bai 2 ve xung tam giac------ thieu dap ung bien do, dap ung pha lay ở
bài 2 đề 2
%cau a
%To chu ki xung
%fs tan so xung
%N: so luong xung co trong chuoi
To=2;
Tw=To/2;% do rong xung
N=5;
tN=N*To;%thoi gian quan sat
fs=1000;%tan so lay mau
Ts=1/fs;%thoi gian lay mau
y=[];

for t=0:Ts:tN
y1=2-abs((mod(t,To))/Tw);
y=[y y1];
end
t=0:Ts:tN;
plot(t,y)

%De 5 bai 3 tinh tich chap—cua xung tam giac va xung vuong
T0=4; % chu ki xung
%xung vuong
t1=[-T0:1:T0];
for i=1:length(t1)
if abs(t1(i))<=T0
w1(i)=1
else
w1(i)=0
end
end
%xung tam giac
t2=[-T0/2:0.5:T0/2];
for j=1:length(t2)
if abs(t2(j))<=(T0/2)
w2(j)=T0-2*abs(t2(j))
else
w2(j)=0
end
end

y=conv(w1,w2)
plot(y)

Đề 6
%De 6 bai 1 ve do thi ---cos(2pi10x) va E^(-x), chú thích, điểm tròn đỏ
clc;
clear all;
close all;

a = 0 ;
b= 10;
x = [a : 1 : b];
f1 = cos(2*pi*10*x) ;
f2 = exp(-x);
figure ;
subplot (2,1,1 );
plot (x, f1, '-or' );
xlabel('truc 0x')
ylabel('truc 0y')
title('Do thi ham f1=cos(2pi10x)');
hold on
subplot (2,1,2 );
plot (x, f2, '-or' );
xlabel('truc 0x')
ylabel('truc 0y')
title('Do thi ham f2=exp(-x)');

%De 6 bai 2 tao vec to--- còn thiếu 2 ý


A=(1:30);
for i=1:length(A)
V=(de2bi(A(i)))
end

%De 6 bai 3 giai phuong trinh bang phuong phap chia nua và du doan ban đầu
X=0 và X=2
function [ x ] = GPT( a,b,c,d,n,m,x0,x1 )
disp('Nhap he so phuong trinh a,b,c,d');
a=input('a =');
b=input('b =');
c=input('c =');
d=input('d =');
disp('Dai gia tri cua x (n<x<m):');
n=input('n =');
m=input('m =');
disp('Gia tri du doan ban dau x0,x1:');
x0=input('x0 =');
x1=input('x1 =');
fa=a*(x0^3)+b*(x0^2)+c*x0+d;
fb=a*(x1^3)+b*(x1^2)+c*x1+d;
if fa*fb>0
disp('Vo Nghiem');
end
while(x1-x0)>0.0001
x=(x0+x1)/2;
fx=a*(x^3)+b*(x^2)+c*x+d;
if sign(fa)==sign(fx)
x0=x;
fa=fx;
else
x1=x;
fb=fx;
end
end
end
Đề 7

%Bài 1 vẽ đồ thị hàm sô cos(2pi10x) và e^(-x)


figure ;
subplot (3,1,1 );
plot (x, f1);
xlabel('truc 0x')
ylabel('truc 0y')
title('Do thi ham f1=cos(2pi10x)');
hold on
subplot (3,1,2 );
plot (x, f2);
xlabel('truc 0x')
ylabel('truc 0y')
title('Do thi ham f2=exp(-x)');
hold on
subplot (3,1,3);
f3=f1.*f2;
plot(x, f3);
xlabel('truc 0x')
ylabel('truc 0y')
title('Do thi ham f3=f1*f2')

%Bai 2 tinh tich chap voi xung chu nhat va ham e mũ


clc
clear all

T0=8; %chu ky xung


N=3; %so chu ky xung
t=[-T0/2:0.5:T0/2];
L=length(t);
w0=2*pi/T0;
%cau a: tinh tich chap
%w1
T=T0/2;
for i=1:L
if abs(t(i))<=T0/2
w1(i)=1;
else
w1(i)=0;
end
end
%w2
w2=exp(t/T0);
t=[0:0.5:2]
%tich chap
y=conv(w1,w2);
%cau b: ve tin hieu thu duoc
plot(y);
%Bai 3 tinh tich phan tu 1 den 7
clc ;
clear all ;
close all ;

a=1;
b=7;
N=100;
delta_x=(b-a)/N;
result=0;
f =@(x) (x.^2)* exp(-x);
for k=1:N
x=a+(k-1/2)*delta_x;

sub_sum =f(x);
result=result+sub_sum*delta_x;
end;
disp('The result is : ' )
result

Đề 8
%Bai 1--- vẽ đồ thị các hàm cos, chú thích,…
clear all; close all
%cau a
t=[0 : 0.0001 : 0.5];
f1=cos(20*pi*t);
f2=cos(40*pi*t);
f3=cos(60*pi*t);
f4=cos(80*pi*t);
f5=f1+f2+f3+f4;
hold on
plot(t,f1,'--r');
plot(t,f2,'b');
plot(t,f3,'g');
plot(t,f4,'y');
plot(t,f1+f2+f3+f4,'r');
%cau b
xlabel('truc tung');
ylabel('truc hoanh');
legend('f1','f2','f3','f4','f1+f2+f3+f4')
%Bai 2---tính tích chập
clc
clear all

T0=8; %chu ky xung


N=3; %so chu ky xung
t=[-T0/2:0.5:T0/2];
L=length(t);
w0=2*pi/T0;

%------xung chu nhat


T=T0/2;
for i=1:L
if abs(t(i))<=T0/2
w1(i)=2;
else
w1(i)=0;
end
end
w2=3*sin(w0*t);
y=conv(w1,w2);
plot(y);

%Bai 3—tính tích phân theo phương pháp điểm giữa dạng function
function[t]= Bai3(a,b,N);
a=2; %can tren tich phan
b=-2; %can duoi tich phan
N=1; %so diem tinh tich phan
h=(b-a)/N;
temp= 3*(a+ h/2)^2 +1;

for k=2:N
xi= a + (k-1/2)*h;
temp = temp + (3*xi^2 +1);
end

t = temp*h;
end

Đề 9

%Bai 1---vẽ đồ thị hàm cos+ cos+…, vẽ phổ và đáp ứng biên độ
clear all; close all
%cau a
t=[0 : 0.0001 : 0.5];
f1=cos(20*pi*t);
f2=cos(40*pi*t);
f3=cos(60*pi*t);
f4=cos(80*pi*t);
f5=f1+f2+f3+f4;
hold on
figure(1)
plot(t,f1+f2+f3+f4,'r');
xlabel('truc tung');
ylabel('truc hoanh');
%cau b
figure(2)
plot(t,abs(f5));

%Bai 2 ---tìm nghiệm phương trình vi phân theo phương pháp euler với y(0)=0
và h=0,1
clc;
clear all;
a = -5;
r = 2;
h = 0.1;
y0 = 0;
f = @(t,y) r - a*cos(y);
k1 = 0; %Khoang thoi gian xet
k2 = 3;
t0 = k1;
n = (k2-k1)/h;
t(1) = t0;
y(1) = y0;
for i =1:n
t(i+1) = t(i) + h;
y1(i+1) = y(i)+h*f(t(i),y(i));
y(i+1) = y(i) + h/2*(f(t(i),y(i)) + f(t(i+1),y1(i+1)));
end

plot(t,y,'ro-','linewidth',2);
title('Euler bien doi','fontsize',15,'color','b');
legend('Nghiem theo Euler bien doi',1);
xlabel('t','fontsize',15,'color','b');
ylabel('Nghiem','fontsize',15,'color','b');
grid on

Đề 10
%Bai 1----vẽ đồ thị cos+ cos… vẽ phổ, đáp ứng biên độ
clear all; close all
%cau a
t=[0 : 0.0001 : 0.5];
f1=sin(20*pi*t);
f2=sin(40*pi*t);
f3=sin(60*pi*t);
f4=sin(80*pi*t);
f5=f1+f2+f3+f4;
hold on
figure(1)
plot(t,f1+f2+f3+f4,'r');
xlabel('truc tung');
ylabel('truc hoanh');
%cau b
figure(2)
plot(t,abs(f5));

%Bai 2 – VI PHÂN THEO EULER


clc;
clear all;
a = 5;
r = 2;
h = 0.1;
y0 = 0;
f = @(t,y) r - a*sin(y);
k1 = 0; %Khoang thoi gian xet
k2 = 3;
t0 = k1;
n = (k2-k1)/h;
t(1) = t0;
y(1) = y0;
for i =1:n
t(i+1) = t(i) + h;
y1(i+1) = y(i)+h*f(t(i),y(i));
y(i+1) = y(i) + h/2*(f(t(i),y(i)) + f(t(i+1),y1(i+1)));
end

plot(t,y,'ro-','linewidth',2);
title('Euler bien doi','fontsize',15,'color','b');
legend('Nghiem theo Euler bien doi',1);
xlabel('t','fontsize',15,'color','b');
ylabel('Nghiem','fontsize',15,'color','b');
grid on

Đề 11
%Bai 1 tạo một vecto(1,50) tính gia trị trung bình , phương sai,tạo vecto y
và chuyển y thành nhị phân--thiế phương sai

x=0+(5-0)*rand(1,50);
b=x(1:10);
hist(b);
tb=sum(x)/length(x);
z=(1:5);
y=floor(z);
y=y'
y=dec2bin(y)

%Bai 2---biểu diễn thành xung NRZ


data=[0 1 1 0 1 0 1 0];
fs=1000;
nrz=2*data-1;
for t=0:length(data)*fs-1
k = fix(t/fs)+1;
m(t+1)=nrz(k);
end
plot(m)
xlabel('time-ns')

Đề 12
%de 12—phương sai thiếu
%cau 1 có 1 ý

x=0+(3-0)*rand(1,50);
b=x(1:10);
hist(b);
tb=sum(x)/length(x);
z=(1:5);
y=floor(z);
y=y'
y=dec2bin(y)

%cau 2-RZ 50%


data=[0 1 1 0 1 0 1 0];
fs=1000;
for t=0:length(data)*fs-1
k = fix(t/fs)+1;
m(t+1)=data(k);
end
plot(m)
xlabel('time-ns')

Đề 15
%De 15 bai 1---tạo chuỗi bit dài 160 bit và điều chế QPSK
M=4;
x=randi (1,160,M);
h = modem.pskmod(M,pi/4);
h.symbolorder = 'gray';
y = modulate(h,x);
h=scatterplot(y,1,0,'or');
title('Cau b: Bieu do chom sao');grid;
figure;
plot(abs(y));
title('Cau a: Bieu dien bien do');grid;
%tự làm thiêu biểu diên biên độ

clear all; clc; close all;


M = 4;
% Tao chuoi tin hieu ngau nhien
data = randi([0 M-1], 1, 1000);
% Dieu che tin hieu su dung QPSK
modSignal = pskmod(data, M);
% Ve bieu do chom sao tin hieu
scatterplot(modSignal,1,0,'ro');

%De 15 bai 2
function y = raisedcosflt(x,Rb,Ts,beta)
% Function bo loc raised cosine
% x - input samples
% Rb - filter bandwidth
% Ts - sampling time
% beta - rolloff factor
% y - filtered output
Ns = length(x);
Tb = 1/Rb;
beta = beta*Rb;
% Frequency domain
f = [0:Ns/2-1 -Ns/2:-1]/(Ns*Ts);
Xf = fft(x);
Yf = zeros(size(Xf));
ind = (abs(f)<=(Rb/2-beta));
Yf(ind) = Xf(ind).*Tb;
ind = (abs(f)<=(Rb/2+beta)&abs(f)>(Rb/2-beta));
Yf(ind) = Xf(ind).*(Tb*cos(pi/(4*beta)*...
(abs(f(ind))-Rb/2+beta)).^2);
ind = (abs(f)>(Rb/2+beta));
Yf(ind) = Xf(ind).*0;
% Convert into time domain
y = ifft(Yf)./Tb;
t = [0:Ns-1]*Ts;
%p = sinc(Rb*t).*cos(2*pi*beta*t)./(1-(4*beta*t).^2);
p = (1-(cos(2*pi*t./T));
y = conv(x,p);

%%%%%%%%%%%%%%%%%%%%%%%%%%%

Đề16
%Bai 1
M=16;
x=randi (1,160,M);
h = modem.qammod(M);
h.symbolorder = 'gray';
y = modulate(h,x);
h=scatterplot(y,1,0,'or');
title('Cau b: Bieu do chom sao');grid;
figure;
plot(abs(y));
title('Cau a: Bieu dien bien do');grid;
%bai 2
function y = raisedcosflt(x,Rb,Ts,beta)
% Function bo loc raised cosine
% x - input samples
% Rb - filter bandwidth
% Ts - sampling time
% beta - rolloff factor
% y1 - filtered output
Ns = length(x);
Tb = 1/Rb;
beta = beta*Rb;
% Frequency domain
f = [0:Ns/2-1 -Ns/2:-1]/(Ns*Ts);
Xf = fft(x);
Yf = zeros(size(Xf));
ind = (abs(f)<=(Rb/2-beta));
Yf(ind) = Xf(ind).*Tb;
ind = (abs(f)<=(Rb/2+beta)&abs(f)>(Rb/2-beta));
Yf(ind) = Xf(ind).*(Tb*cos(pi/(4*beta)*...
(abs(f(ind))-Rb/2+beta)).^2);
ind = (abs(f)>(Rb/2+beta));
Yf(ind) = Xf(ind).*0;
% Convert into time domain
y1 = ifft(Yf)./Tb;
t = [0:Ns-1]*Ts;
%p = sinc(Rb*t).*cos(2*pi*beta*t)./(1-(4*beta*t).^2);
p = (1-(cos(2*pi*t./T));
y1 = conv(x,p);
plot(y1);

%th? l?u l?i r?i n?p raisedcoflt(y,500e6,100,0.5) xem sao, y là ??u vào l?y
t? bài 1

You might also like