基础知识
R1: Convolution of the sequence:
c(n)=∑_(m=-∞)^∞▒〖a(m)b(nm)〗
R2: Correlation of the sequence:
c(m)=∑_(n=- ∞)^∞▒〖a(n)b(nm)〗
Matlab计算卷积与相关
(1) For details, please refer to the fourth edition P53-P54 of "Digital Signal Processing Tutorial", Convolution and Correlation of Sequences.
(2) According to the definition of convolution, the convolution operation is divided into 4 steps:
Folding: Folding b(m) into b(-m) with the vertical axis of m=0 as the symmetry axis;
Shifting: Folding b(- m) Shift n, get b(nm), shift right when n>0, shift left when n<0;
Multiply: multiply b(-m) and a(m) at the same m corresponding value;
Add: Add all the products at m above, and this will get a c(n) under the value of n.
Use the above steps for different n to get all c(n) values. According to this idea (not using the existing Matlab function conv), the Matlab realization function of convolution is written.
Figure 1
Example of convolution process and results : calculation sequence a(-1)=1, a(0)=1, a(1)=1 (other elements are zero) and b(0)=2,b(1) =5, b(2)=1 (other elements are zero) convolution. The calculation process and results are shown in Figure 1.
分别利用自己编写的卷积函数与conv函数计算下列两个序列的卷积。
a(n)={-1, 0,8,9}
b(n)={2,5, (-2),7,10}
(1) Use the system's own conv function to calculate convolution
function result = conv_s(x,ux,h,uh)
x_len = length(x);
h_len = length(h);
result = conv(x,h); %直接用系统自带函数conv计算得到卷积
u = ux(1)+uh(1):ux(x_len)+uh(h_len) %求下标
(2) Calculate the convolution using the function written by yourself
function result = own_conv1(x,h,ux,uh)
x_len = length(x);
h_len = length(h);
%按照向量法—矩阵乘法进行卷积运算
h_set = zeros(x_len,h_len+x_len-1);
for i = 1:x_len
h_set(i,i:i+h_len-1) = h; %得到H矩阵
end
result = x*h_set; %向量相乘即完成了翻折,移位,相乘,相加四步操作得到卷积结果
u = ux(1)+uh(1):ux(x_len)+uh(h_len)
相关运算跟卷积运算不同,它没有翻褶这一个步骤,只有移位、相乘、相加三个步骤。模仿以上4步计算卷积的方法,分别计算上面两组序列的相关。
相关运算理论:
Shift: shift b(m) by n to get b(n+m), shift right when n>0, shift left when n<0;
multiply: put b(m) and a(m) at the same Multiply the corresponding values at m;
add: add up all the products at m above, and then get a c(n) under the value of n.
a(n)={-1, 0,8,9}
b(n)={2,5, (-2),7,10}
Theoretical calculation results:
correlation coefficient: rab=c(n)= {-10,-7,82,141,45,22,61,18}, interval: u=-3:4
(1) Related arithmetic functions written by yourself
function result = own_r_conv(x,ux,h,uh)
x_len = length(x);
h_len = length(h);
h_set = zeros(x_len,h_len+x_len-1);
%由于计算相关比卷积少了翻折,因此运算时在卷积运算基础上取消它的翻折操作
for i = 1:x_len
h_set(i,i+h_len-1:-1:i) = h;
end
result = x*h_set;
u = ux(1)+uh(1):ux(x_len)+uh(h_len)
- Application question: The working principle of radar
(1) Schematic diagram
The working process of radar can be divided into two parts: Assume that the sampling frequency is f_s=1⁄T_s =0.05MHz
(2) Transmit electromagnetic signals to the target
① Generate transmit signals
s(t) is a periodic square wave signal, the pulse width is T_p=100μs, the repetition period is T_r=1ms, and the signal of the main value period can be expressed as
(3) Receive target electromagnetic signal The
specific realization of matlab code is as follows:
%产生发射的方波信号
clear;close all;
T = 0.001;%方波周期为1ms,占空比为10%
fs = 0.4*10^6;%采样频率为0.4MHz
Ts = 1/fs;%采样周期为2.5微秒
t = 0:Ts:2*T-Ts;
sn = (square(2*pi*t/T,10)+1)/2;
n = 0:t(end)/Ts;
figure(1);
stem(n,sn);
xlabel('时间序号 n');
ylabel('振幅');
title('采样周期方波信号');
fc = 0.1*10^6;%载频频率为0.1MHz
wc = 2*pi*fc;
pn = exp(1i*wc*t);
figure(2);
stem(n,pn);
xlabel('时间序号 n');
ylabel('振幅');
title('载频信号');
xn = sn.*pn;
figure(3);
stem(n,xn);
xlabel('时间序号 n');
ylabel('振幅');
title('调制信号');
R= 150*10^3;%距离150km
c = 3*10^8;%光速
tn = 2*R*fs/c;%延时
tn = round(tn);%四舍五入
delta_n = [zeros(1,tn),1]*10;
x_n = conv(xn,delta_n);%点目标对电磁信号的作用
N = 0:length(x_n)-1;
figure(4);
stem(N,x_n);
xlabel('时间序号 n');
ylabel('振幅');
title('点目标对电磁信号的作用');
v1n = randn(1,length(x_n));%均值为0,方差为1的高斯白噪声
v2n = randn(1,length(x_n));
vn = (v1n+1i*v2n)/sqrt(2);%加性噪声
yn = x_n + vn;
figure(5);
stem(N,yn);
xlabel('时间序号 n');
ylabel('振幅');
title('经目标散射回到天线的电磁信号');
t = 0:Ts:(length(yn) - 1)*Ts;%长度与yn保持一致
p_n = exp(-1i*wc*t);
figure(6);
stem(N,p_n);
xlabel('时间序号 n');
ylabel('振幅');
title('解调信号');
zn = yn.*p_n;%解调后得到的信号
figure(7);
stem(N,zn);
xlabel('时间序号 n');
ylabel('振幅');
title('解调后得到的信号');