信号处理与分析——matlab记录

一、绘制信号分析频谱

1.代码

% 生成测试信号
Fs = 3000;      % 采样频率
t = 0:1/Fs:1-1/Fs;   % 时间向量
x1 = 1*sin(2*pi*50*t)+ 1*sin(2*pi*60*t); % 信号1
x2 = 1*sin(2*pi*150*t)+1*sin(2*pi*270*t); % 信号2

% 绘制信号图
subplot(2,2,1);
plot(t,x1);
title('信号x1 1*sin(2*pi*50*t)+ 1*sin(2*pi*60*t)');
xlabel('时间 (s)');
ylabel('幅度');

subplot(2,2,2);
plot(t,x2);
title('信号x2 1*sin(2*pi*150*t)+1*sin(2*pi*270*t)');
xlabel('时间 (s)');
ylabel('幅度');

x3=x1.*x2;
x4=conv2(x1,x2);

% 计算FFT
N1 = length(x3);
X1 = fft(x3);
f1 = Fs*(0:(N1/2))/N1;

% 绘制FFT图
subplot(2,2,3);
plot(f1,abs(X1(1:N1/2+1)));
title('信号x1 × x2 的FFT变换');
xlabel('频率 (Hz)');
ylabel('幅度');

% 计算FFT
N2 = length(x4);
X2 = fft(x4);
f2 = Fs*(0:(N2/2))/N2;

% 绘制FFT图
subplot(2,2,4);
plot(f2,abs(X2(1:N2/2+1)));
title('信号x1 * x2 的FFT变换');
xlabel('频率 (Hz)');
ylabel('幅度');

2.现象

二、 绘制序列

FS=2000;%采样频率
T=0.1;%采样时间
t=0:1/FS:T-1/FS;%设置对应的步长
%t=linspace(0,T-1/FS,T/(1/FS));linspace也可以生成行向量来使用

A=2;
a=0.5;
f0=50;
x=A.*exp(-a.*t).*sin(2*pi*f0.*t);

figure(1);
plot(t,x,Color=[0 0.4470 0.7410],LineWidth=1.5);
xlabel('时间t','FontWeight','bold','FontSize',15);
ylabel('幅值','FontWeight','bold','FontSize',15);
title('此时序列的采样频率为2000,可以看出完美的还原了波形','FontWeight','bold','FontSize',15,'BackgroundColor','cyan')
hold on
stem(t,x,Color=[0.8500 0.3250 0.0980],LineWidth=0.9);
lgd1=legend({'原始信号','序列信号'},FontSize=14,FontWeight="bold",TextColor='blue');

figure(2);
plot(t,x,Color=[0 0.4470 0.7410],LineWidth=1.5);
xlabel('时间t','FontWeight','bold','FontSize',15);
ylabel('幅值','FontWeight','bold','FontSize',15);
title('此时序列的采样频率为1000,此时依然可以很好的还原波形','FontWeight','bold','FontSize',15,'BackgroundColor','cyan');
hold on
FS2=1000;%采样频率
T2=0.1;%采样时间
t2=0:1/FS2:T2-1/FS2;%设置对应的步长
x2=A.*exp(-a.*t2).*sin(2*pi*f0.*t2);
stem(t2,x2,Color=[0.8500 0.3250 0.0980],LineWidth=0.9);
lgd2=legend({'原始信号','序列信号'},FontSize=14,FontWeight="bold",TextColor='blue');


figure(3);
plot(t,x,Color=[0 0.4470 0.7410],LineWidth=1.5);
xlabel('时间t','FontWeight','bold','FontSize',15);
ylabel('幅值','FontWeight','bold','FontSize',15);
title('此时序列的采样频率为500,得到的信息变少了许多,这并不利于波形的分析','FontWeight','bold','FontSize',15,'BackgroundColor','cyan');
hold on
FS3=500;%采样频率
T3=0.1;%采样时间
t3=0:1/FS3:T3-1/FS3;%设置对应的步长
x3=A.*exp(-a.*t3).*sin(2*pi*f0.*t3);
stem(t3,x3,Color=[0.8500 0.3250 0.0980],LineWidth=0.9);
lgd3=legend({'原始信号','序列信号'},FontSize=14,FontWeight="bold",TextColor='blue');

figure(4);
plot(t,x,Color=[0 0.4470 0.7410],LineWidth=1.5);
xlabel('时间t','FontWeight','bold','FontSize',15);
ylabel('幅值','FontWeight','bold','FontSize',15);
title('此时序列的采样频率为250,此时可以看出,已经严重失真','FontWeight','bold','FontSize',15,'BackgroundColor','cyan');
hold on
FS4=250;%采样频率
T4=0.1;%采样时间
t4=0:1/FS4:T4-1/FS4;%设置对应的步长
x4=A.*exp(-a.*t4).*sin(2*pi*f0.*t4);
stem(t4,x4,Color=[0.8500 0.3250 0.0980],LineWidth=0.9);
lgd4=legend({'原始信号','序列信号'},FontSize=14,FontWeight="bold",TextColor='blue');

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值