一、初相为0的正弦信号和余弦信号
A=1;
f=5;
w=2*pi*f;
p=0;
%采样
T=1; %s %观测时间
fs=20*f; %Hz %采样频率
d=1/fs; %s %采样间隔
t=-T/2:d:T/2;
s1=sin(w*t+p);
s2=cos(w*t+p);
figure(1)
plot(t, s1, t, s2)
xlabel('时间/s');
ylabel('幅度');
axis([-0.6 0.6 -1.5 1.5]);
legend('初相为0的正弦信号','初相为0的余弦信号')
title('图1.1 初相为0的正弦信号和余弦信号')
二、初相为30的正弦信号和余弦信号
A=1;
f=5;
w=2*pi*f;
p=30;
%采样
T=1; %s %观测时间
fs=20*f; %Hz %采样频率
d=1/fs; %s %采样间隔
t=-T/2:d:T/2;
s1=sin(w*t+p);
s2=cos(w*t+p);
figure(1)
plot(t, s1, t, s2)
xlabel('时间/s');
ylabel('幅度');
axis([-0.6 0.6 -1.5 1.5]);
legend('初相为30的正弦信号','初相为30的余弦信号')
title('图1.2 初相为30的正弦信号和余弦信号')
三、 高斯白噪声、高斯有色噪声
fs=100;
T=20;
n=round(T*fs);
t=linspace(0,T,n);
y=wgn(1,n,0);
subplot(211)
plot(t,y);
axis([0 20 -4 4]);
title('高斯白噪声');
xlabel('t/s');
ylabel('幅度');
text(6,5.5,'图2.1 高斯白噪声与高斯色噪声')
x2=sin(t);
s=awgn(x2,10,'measured');
subplot(212)
plot(t,s);
title('高斯色噪声');
xlabel('t/s');
ylabel('幅度');
四、连续信号的加、减、乘法运算
x=linspace(-4*pi,4*pi,100);
y1=sin(x);
y2=cos(x);
y3=y1+y2;
y4=y1-y2;
y5=y1.*y2;
subplot(2,3,1)
plot(x,y1,'m');
axis([-10 10 -1.5 1.5]);
xlabel('时间/s');
title('y1=sin(x)')
subplot(2,3,2)
plot(x,y2,'m');
axis([-10 10 -1.5 1.5]);
xlabel('时间/s');
title('y2=cos(x)')
text(-10,2.05,'图2.2 连续信号的加、减、乘法运算')
subplot(2,3,4)
plot(x,y3,'b');
axis([-10 10 -1.5 1.5]);
xlabel('时间/s');
title('y3=y1+y2')
subplot(2,3,5)
plot(x,y4,'r');
axis([-10 10 -1.5 1.5]);
xlabel('时间/s');
title('y4=y1-y2')
subplot(2,3,6)
plot(x,y5,'c');
axis([-10 10 -1.5 1.5]);
xlabel('时间/s');
title('y5=y1.*y2')
subplot(2,3,6)
plot(x,y5,'c');
axis([-10 10 -1.5 1.5]);
xlabel('时间/s');
title('y5=y1.*y2')
五、离散信号的加、减、乘法运算
k=-20:20;
s1=sin(pi/6*k);
s2=cos(pi/6*k);
s3=s1+s2;
s4=s1-s2;
s5=s1.*s2;
subplot(2,3,1)
stem(k,s1,'.','m');
axis([-10 10 -1.5 1.5]);
xlabel('时间/s');
title('s1=sin(x)')
subplot(2,3,2)
stem(k,s2,'.','m');
axis([-10 10 -1.5 1.5]);
xlabel('时间/s');
title('s2=cos(x);')
text(-10,2.05,'图2.3 离散信号的加、减、乘法运算')
subplot(2,3,4)
stem(k,s3,'.','s');
axis([-10 10 -1.5 1.5]);
xlabel('时间/s');
title('s3=s1+s2')
subplot(2,3,5)
stem(k,s4,'.','r');
axis([-10 10 -1.5 1.5]);
xlabel('时间/s');
title('s4=s1-s2')
subplot(2,3,6)
stem(k,s5,'.','c');
axis([-10 10 -1.5 1.5]);
xlabel('时间/s');
title('s5=s1.*s2')
六、连续信号的翻转、移动、尺度变换
x=linspace(-4*pi,4*pi,100);
y1=sin(x);
y2=sin(-x);
y3=sin(x+10);
y4=sin(2*x);
subplot(2,2,1)
plot(x,y1,'m');
axis([-10 10 -1.5 1.5]);
xlabel('时间/s');
title('y1=sin(x)')
text(3.8,2.1,'图2.4 连续信号的翻转、移动、尺度变换')
subplot(2,2,2)
plot(x,y2,'r');
axis([-10 10 -1.5 1.5]);
xlabel('时间/s');
title('y2=sin(-x)')
subplot(2,2,3)
plot(x,y3,'b');
axis([-10 10 -1.5 1.5]);
xlabel('时间/s');
title('y3=sin(x+10)')
subplot(2,2,4)
plot(x,y4,'g');
axis([-10 10 -1.5 1.5]);
xlabel('时间/s');
title('y4=sin(2*x)')
七、离散信号的翻转、移动、尺度变换
k=-20:20;
s1=sin(pi/6*k);
s2=sin(-pi/6*k);
s3=sin(pi/6*k+30);
s4=sin(pi/4*k);
subplot(2,2,1)
stem(k,s1,'.','m');
axis([-10 10 -1.5 1.5]);
xlabel('时间/s');
title('s1=sin(pi/6*k)')
text(5,2.1,'图2.5 离散信号的翻转、移动、尺度变换')
subplot(2,2,2)
stem(k,s2,'.','g');
axis([-10 10 -1.5 1.5]);
xlabel('时间/s');
title('s2=sin(-pi/6*k)')
subplot(2,2,3)
stem(k,s3,'.','s');
axis([-10 10 -1.5 1.5]);
xlabel('时间/s');
title('s3=sin(pi/6*k+30)')
subplot(2,2,4)
stem(k,s4,'.','r');
axis([-20 20 -1.5 1.5]);
xlabel('时间/s');
title('s4=sin(pi/4*k)')
八、两个序列的卷积和
N1=1;N2=5;
A=ones(1,(N2-N1+1));
M1=1;M2=7;
B=ones(1,(M2-M1+1));
X1=N1+M1;X2=N2+M2;
for n=X1:X2
w=0;
for k=N1:N2
kk=k-N1+1;
t=n-k;
if t>=M1&&t<=M2
tt=t-M1+1;
w=w+A(kk)*B(tt);
end
end
nn=n-X1+1;
cc(nn)=w;
end
stem(cc)
axis([0 12 0 6]);
title('图4.1 两个序列的卷积和')
九、常用模拟信号的傅里叶变换——门函数
syms t w;
x=heaviside(t+0.5)-heaviside(t-0.5);
subplot(211);
fplot(x);
axis([-1 1 -0.5 1.5]);
title('时域')
grid on;
text(-0.4,1.9,'图5.1 门函数信号的傅里叶变换')
Fw=fourier(x,t,w);
subplot(212);
fplot(Fw);
axis([-30 30 -0.3 1.5]);
title('频谱');
grid on;
十、常用序列的傅里叶变换——矩形序列
n=-2:2;
k=-200:200;
w=(pi/100)*k;
xn = [1 1 1 1 1];
subplot(211);
stem(xn);
axis([-2 8 0 1.5]);
title('时域')
text(1,1.8,'图5.2 矩形序列的傅里叶变换')
subplot(212);
Xk=xn*(exp(-1i*pi/100)).^(n'*k);
plot(w/pi,magX);
axis([-2 2 0 6]);
title('频域')
十一、周期信号的合成
x0=-pi:0.01:pi;
sum=0;
for n0=1
p0=4*sin(n0*pi/2)*cos(n0*x0)/(n0*pi);
sum=sum+p0;
end
plot(x0,sum,'.');
hold on;
x1=-pi:0.01:pi;
sum=0;
for n1=1:1:5
p1=4*sin(n1*pi/2)*cos(n1*x0)/(n1*pi);
sum=sum+p1;
end
plot(x1,sum,':.');
hold on;
x2=-pi:0.01:pi;
sum=0;
for n2=1:1:20
p2=4*sin(n2*pi/2)*cos(n2*x2)/(n2*pi);
sum=sum+p2;
end
plot(x2,sum,'--');
hold on;
x3=-pi:0.01:pi;
sum=0;
for n3=1:1:150
p3=4*sin(n3*pi/2)*cos(n3*x3)/(n3*pi);
sum=sum+p3;
end
plot(x3,sum,'-');
hold on
legend('n=1','n=5','n=20','n=150')
title('图5.3 周期信号的合成')
结论:随着正弦波的叠加次数越来越多,最后形成的信号波会无限的逼近矩形波。
十二、常用序列的傅里叶变换——矩形序列(32点)
n=-16:16;
k=-200:200;
w=(pi/100)*k;
xn = ones(1,length(n));
subplot(211);
stem(xn);
axis([-5 40 0 1.5]);
title('时域')
text(5.5,1.8,'图5.2 矩形序列的傅里叶变换')
subplot(212);
Xk=xn*(exp(-1i*pi/100)).^(n'*k);
plot(w/pi,Xk);
axis([-2 2 -10 40]);
title('频域')
十三、时域采样定理
% 原始信号
t=0:0.01:40;
y=cos(pi/6*t);
subplot(221);
plot(t,y);
axis([0 8*pi -1.1 1.1]);
xlabel('t 单位:s');
title('f(t)');
text(20,1.5,'图6.2 时域采样定理')
% 原始信号的频谱
N = 300;
W = 2*pi*5;
k = -N:N;
w = k*W/N;
Y = 0.01*y*(exp(-j*t'*w));
Y = abs(Y);
subplot(222);
plot(w/pi,Y);
axis([-1 1 0 20]);
xlabel('ω 单位:π');
title('F(jω)');
% 原始信号进行抽样
fs = 1; % 采样频率
Ts = 1/fs; % 采样间隔
subplot(223);
plot(t,y,'b:'); % 包络
axis([0 8*pi -1.1 1.1]);
hold on;
t2 = 0:Ts:40;
y2 = cos(pi/6*t2);
stem(t2,y2,'.');
xlabel('t 单位:s');
title('fs(k)');
hold off;
% 抽样信号的频谱
subplot(224);
Y2 = Ts*y2*(exp(-j*t2'*w));
Y2 = abs(Y2);
plot(w/pi,Y2);
axis([-1 1 0 20]);
xlabel('ω 单位:π');
hold off;
title('Fs(jω)');
十四、时域采样定理 采样频率是信号最高频率8倍
% 原始信号
t=0:0.01:40;
y=cos(pi/6*t);
subplot(221);
plot(t,y);
axis([0 8*pi -1.1 1.1]);
xlabel('t 单位:s');
title('f(t)');
text(10,1.5,'图6.2 时域采样定理 采样频率是信号最高频率8倍');
% 原始信号的频谱
N = 300;
W = 2*pi*5;
k = -N:N;
w = k*W/N;
Y = 0.01*y*(exp(-j*t'*w));
Y = abs(Y);
subplot(222);
plot(w/pi,Y);
axis([-1 1 0 20]);
xlabel('ω 单位:π');
title('F(jω)');
% 原始信号进行抽样
fm = (pi/6)/(2*pi);
fs = 8*fm; % 采样频率
Ts = 1/fs; % 采样间隔
subplot(223);
plot(t,y,'b:'); % 包络
axis([0 8*pi -1.1 1.1]);
hold on;
t2 = 0:Ts:40;
y2 = cos(pi/6*t2);
stem(t2,y2,'.');
xlabel('t 单位:s');
title('fs(k)');
hold off;
% 抽样信号的频谱
subplot(224);
Y2 = Ts*y2*(exp(-j*t2'*w));
Y2 = abs(Y2);
plot(w/pi,Y2);
axis([-1 1 0 20]);
xlabel('ω 单位:π');
hold off;
title('Fs(jω)');
十五、时域采样定理 采样频率是信号最高频率0.8倍
% 原始信号
t=0:0.01:60;
y=cos(pi/6*t);
subplot(221);
plot(t,y);
axis([0 60 -1.1 1.1]);
xlabel('t 单位:s');
title('f(t)');
text(10,1.5,'图6.3 时域采样定理 采样频率是信号最高频率0.8倍')
% 原始信号的频谱
N = 300;
W = 2*pi*5;
k = -N:N;
w = k*W/N;
Y = 0.01*y*(exp(-j*t'*w));
Y = abs(Y);
subplot(222);
plot(w/pi,Y);
axis([-1 1 0 35]);
xlabel('ω 单位:π');
title('F(jω)');
% 原始信号进行抽样
fm = (pi/6)/(2*pi);
fs = 0.8*fm; % 采样频率
Ts = 1/fs; % 采样间隔
subplot(223);
tb=0:0.01:60;
yb=cos(pi/6*tb);
plot(tb,yb,'b:'); % 包络
axis([0 60 -1.1 1.1]);
hold on;
t2 = 0:Ts:60;
y2 = cos(pi/6*t2);
stem(t2,y2,'.','r');
axis([0 60 -1.1 1.1]);
xlabel('t 单位:s');
title('fs(k)');
hold off;
% 抽样信号的频谱
subplot(224);
Y2 = Ts*y2*(exp(-j*t2'*w));
Y2 = abs(Y2);
plot(w/pi,Y2);
axis([0 0.2 0 70]);
xlabel('ω 单位:π');
hold off;
title('Fs(jω)');
时域采样定理: 对连续信号进行等间隔采样形成采样信号,采样信号的频谱是原连续信号的频谱以采样频率为周期进行周期延拓。如果想要无失真地回复原连续信号,则采样频率需要大于二倍的中心频率,否则就会造成频谱混叠。
十六、AM信号的调制与解调
%% 原始信号
t=0:1/1600:0.1;
A=2;
fs=1600;
f0=100;
mt=cos(2*pi*f0*t);
subplot(621);
plot(t,mt);
axis([0 0.05 -1.1 1.1]);
xlabel('t 单位:s');
title('原始信号m(t)');
text(0.05,4,'图7.1 AM信号的调制与解调');
% 原始信号的频谱
Mt=fft(mt,4096);
Mt=abs(M_);
subplot(6,2,2);
plot(Mt);
axis([0 4300 0 100]);
xlabel('w 单位:pi');
title('M(jw)');
%% 发送信号
fc=300;
wc=2*pi*fc;
sam = (A+mt).*cos(wc*t);
subplot(623);
plot(t,sam);
grid on;
xlabel('t 单位:s');
title('发送信号时域s_A_M');
Sam=fft(sam,4096);
Sam=abs(Sam);
subplot(6,2,4);
plot(Sam);
axis([0 4300 0 200]);
xlabel('w 单位:pi');
ylabel('S(jw)');
%% 接收信号
x=wgn(1,161,-10);
ram=sam+x;
subplot(625);
plot(t,ram);
grid on;
xlabel('t 单位:s');
title('接收信号r_A_M');
Ram=fft(rt,4096);
Ram=abs(M_);
subplot(626);
plot(Ram);
axis([0 4300 0 200]);
xlabel('w 单位:pi');
title('发送信号频域R_A_M');
%% 相乘后ram_c
ram_c = si.*2.*cos(2*pi*fc*t);
subplot(627);
plot(t,ram_c);
xlabel('t 单位:s');
title('相乘器后信号ram_c');
Ram_c=fft(ram_c,4096);
Ram_c=abs(Ram_c);
subplot(628);
plot(Ram_c);
axis([0 4300 0 400]);
xlabel('w 单位:pi');
title('相乘器后信号频域Ram_c');
%% LPF
p1=fc-f0;
[k,Wn,beta,ftype]=kaiserord([p1 fc],[1 0],[0.05 0.01],fs);%数字低通过滤波器
window=kaiser(k+1,beta);%使用kaiser窗函数
b=fir1(k,Wn,ftype,window,'noscale');%
yam=filter(b,1,rct);
subplot(629);
plot(t,yam);
xlabel('t 单位:s');
title('相乘器后信号时域y_A_M');
Yam=fft(yam,4096);
Yam=abs(Yam);
subplot(6,2,10);
plot(Yam);
axis([0 4300 0 400]);
xlabel('w 单位:pi');
title('相乘器后信号频域Y_A_M');
%% mmt
mmt=yam-A;
subplot(6,2,11);
plot(t,mmt);
axis([0,0.05,-1,1]);
xlabel('t 单位:s');
title('输出信号时域mmt');
Mmt=fft(m_t,4096);
Mmt=abs(Mmt);
subplot(6,2,12);
plot(Mmt)
xlabel('w 单位:pi');
axis([0 4300 0 100]);
title('输出信号频域Mmt(jw)');
🥀这次实习挺水的 这些代码肯定是错误百出
仅供参考仅供参考仅供参考