信号基础知识

总是基础的知识老是忘,所以记录一下吧。

clc;close all;clear all; f0=10; fs=100;     %采样率 t=1/fs:1/fs:2;         %共两秒钟,共200个采样点。采样间隔T=1/100

y1=sin(2*pi*f0*t);

y2=square(2*pi*f0*t);

figure;

subplot(311); plot(t,y1); xlabel('time');ylabel('y1');title('y1=sin(2*pi*f0*t)---时域');

subplot(312); plot(t,y2); xlabel('time');ylabel('y2');title('y1=square(2*pi*f0*t)---时域');

noise=rand(1,200); subplot(313); plot(t,noise,'r'); xlabel('time');ylabel('noise');title('noise---时域');

%--------------------------------------------------------

z1=y1+noise;

z2=y2+noise;

figure;

subplot(211); plot(t,z1); xlabel('time');ylabel('z1');title('y1=sin(2*pi*f0*t)+noise---时域'); axis([0 0.5 0 2]);

subplot(212); plot(t,z2); xlabel('time');ylabel('y2');title('y1=square(2*pi*f0*t)+noise---时域'); axis([0 0.5 0 2]);

xiangguan_z1z2=xcorr(z1,z2);%%相关分析

juanji_z1z2=conv(z1,z2); %%卷积

figure;

subplot(311); plot(xiangguan_z1z2); title('相关性---z1z2');

subplot(312); plot(juanji_z1z2); title('卷积---z1z2');

subplot(313); plot(xiangguan_z1z2,'r');hold on;

plot(juanji_z1z2,'g');hold off;

legend('相关性---z1z2','卷积---z1z2');%卷积和相关不一样emmmm

原文地址:https://www.cnblogs.com/kiki--xiunai/p/10709911.html