添加自生成波形测试

master
zcy 2024-10-30 02:39:35 +08:00
parent 37c7e00507
commit e1fdaaf9ac
29 changed files with 285 additions and 12 deletions

BIN
ModeS_Simulink_Decode.slxc Normal file

Binary file not shown.

BIN
ModeS_Simulink_libiio.slxc Normal file

Binary file not shown.

73
Untitled.m Normal file
View File

@ -0,0 +1,73 @@
% Test Tx DMA data output
amplitude = 2^15;
frequency = 0.30e6;
swv1 = dsp.SineWave(amplitude, frequency);
swv1.ComplexOutput = true;
swv1.SamplesPerFrame = 1e5;
swv1.SampleRate = 3e6;
y = swv1();
plot(real(y))
uri = 'ip:192.168.2.1';
fc = 1e9;
T=10e-3; %信号时宽
B=3e6; %信号带宽
fs=4*B; %采样频率
N=fix(T*fs); %采样点数
x = 0:T/N:T;
y= x(1:2:N); %采样x的奇数点
z=x(2:2:N);%采样x的偶数点
fi=10000*sin(2*pi*30000*y) + 10000*sin(2*pi*900000*y);
fq=10000*sin(2*pi*30000*z) + 10000*sin(2*pi*900000*z);
subplot(2,2,1)
plot(fi)
subplot(2,2,2)
plot(fq)
complexArray = fi + fq*1i;
complexArray = complexArray';
%% Tx set up
tx = adi.AD9361.Tx('uri',uri);
tx.CenterFrequency = fc;
tx.DataSource = 'DMA';
tx.EnableCyclicBuffers = true;
tx.AttenuationChannel0 = -20;
tx(complexArray);
%% Rx set up
rx = adi.AD9361.Rx('uri',uri);
rx.CenterFrequency = fc;
rx.SamplingRate = 1000833
%% Run
for k=1:10
valid = false;
while ~valid
[out, valid] = rx();
end
end
rx.release();
tx.release();
%% Plot
nSamp = length(out);
fs = tx.SamplingRate;
FFTRxData = fftshift(10*log10(abs(fft(out))));
df = fs/nSamp; freqRangeRx = (-fs/2:df:fs/2-df).'/1000;
subplot(1,2,2)
plot(freqRangeRx, FFTRxData);
xlabel('Frequency (kHz)');ylabel('Amplitude (dB)');grid on;

View File

@ -679,6 +679,7 @@ classdef libiio_if < handle
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function ret = writeAttributeString(obj, attr_name, str)
% Find the attribute
try
[ret, ch, attr] = findAttribute(obj, attr_name);
if(ret < 0)
return;
@ -692,6 +693,10 @@ classdef libiio_if < handle
else
calllib(obj.libname, 'iio_device_attr_write', obj.iio_dev, attr_name, str);
end
catch e
disp("error ",e)
end
end
end
end

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<MF0 version="1.1" packageUris="http://schema.mathworks.com/mf0/SlCache/19700101">
<slcache.FileAttributes type="slcache.FileAttributes" uuid="eb0bab66-1083-483b-b0a2-4b70471489cd">
<checksum>VFtF99vSvsCWQT3DC33ogPopY/EU2MB9X+ztRX0tkPyJIk22VJl2UuKDFAE/67uQWgN9IWAxaLNzfOMlT+LNUg==</checksum>
</slcache.FileAttributes>
</MF0>

Binary file not shown.

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<MF0 version="1.1" packageUris="http://schema.mathworks.com/mf0/SlCache/19700101">
<slcache.FileAttributes type="slcache.FileAttributes" uuid="d04eea90-2c62-4acd-b473-68139b218094">
<checksum>aLg/RUXejXaW8fNin2SGwVZLG/5ro5PG+yBxjklFR/1BBYs/xCj7Lk9CzTx9lqJPd57O5bml0GwA4NkC5cok4g==</checksum>
</slcache.FileAttributes>
</MF0>

Binary file not shown.

43
untitled2.m Normal file
View File

@ -0,0 +1,43 @@
clc;
clear all;
close all;
%%
fsc = 1.0e5; % signal frequency
fs = 2.0e6; % sampling frequency
fc = 1.0e10; % carrier frequency
t = [0:1/fs:0.01]; % time
% IQ imbalance parameters
phiDegree = 10; % phase imbalance in degrees
alpha = 1.3;% amplitude imbalance
avg=1;
k=1;
I_before_correction = cos(2*pi*fc*t)+avg;
Q_before_correction = (1+alpha)*cos(2*pi*fc*t+phiDegree*pi/180) +k;
signal_IQ_before = I_before_correction+Q_before_correction*1j;
figure(1);
pwelch(signal_IQ_before, [],[],[],fs);
title('Spectrum at Rx baseband after I/Q correction');
%求均值
I_before_correction =I_before_correction-mean(I_before_correction);
Q_before_correction=Q_before_correction -mean(Q_before_correction);
%估计参数
e = sqrt(mean(Q_before_correction.*Q_before_correction)/mean(I_before_correction.*I_before_correction))-1;
phi = -asin(mean(I_before_correction.*Q_before_correction)/sqrt(mean(I_before_correction.*I_before_correction)*mean(Q_before_correction.*Q_before_correction)));
%P矩阵求解
P = [1,0;tan(phi),1/((1+e)*cos(phi))];
%计算IQ
IQ = P*[I_before_correction;Q_before_correction];
%重组信号
I =IQ(1,:);
Q =IQ(2,:);
signal_IQ = Q+I*1j;
%图形绘制
figure();
pwelch(signal_IQ, [],[],[],fs);title('Spectrum at Rx baseband after I/Q correction');

25
untitled3.m Normal file
View File

@ -0,0 +1,25 @@
% 设置来样频率和来样时间fs = 1000;%梁样频率
Ts = 1/fs;% 采样时间
% 设置信号爹数
f=20000;%信号频率
A =1;% 信号幅度
%生成正张液信号
t= 0:0.001:10;%时间向量
x= A*sin(2*pi*f*t);%正弦浓信号
% 进行正交采样
y= x(1:2:end);%采样x的奇数点
z=x(2:2:end);%采样x的偶数点
% 绘制原始信号和来样信号
subplot(3,1,1);
plot(t,x);
title('原始信号');xlabel('时间(秒)');ylabel('幅度');
subplot(3,1,2);
stem(y);
title('奇数点采样信号');
xlabel('采样点');ylabel('幅度');
subplot(3,1,3);
stem(z);
title('偶数点采样信号');
xlabe1('采样点');ylabel('幅度');

46
untitled4.m Normal file
View File

@ -0,0 +1,46 @@
clear all;
close all;
clc;
%%%%%%%%%%%%%%%%%%%%%%%%%%%% 时域数字正交相干检波 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%********** 线性调频信号 ***********%%
T=10e-3; %信号时宽
B=30e4; %信号带宽
fs=4*B; %采样频率
f0=3/4*fs; %载频频率
N=fix(T*fs); %采样点数
t=(-N/2:N/2-1)/fs;
sr=cos(2*pi*f0*t+pi*(B/T).*t.^2); %sr是以fs=4B的采样频率采样后的数字信号
figure; plot(t*1e6,sr);
title('线性调频信号波形');
xlabel('t/us');
ylabel('sr');
%%********** 1.混频 **********%%
x_I=sr.*cos(2*pi*f0*t);
x_Q=-sr.*sin(2*pi*f0*t);
%%********** 2.低通滤波 **********%%
%使用Parks McClellan算法设计FIR滤波器:Fs=4B,截止频率为B/2过渡带宽度为B/10.
fl=200;
fbe=[0 (B/2)/(fs/2) (B/2+B/10)/(fs/2) 1];
Damps=[1 1 0 0];
b=firpm(fl,fbe,Damps);
figure;
freqz(b);
title('FIR滤波器的幅频和相频特性');
%使用由分子和分母系数 b 和 a=1 定义的有理传递函数对输入数据 x 进行滤波。
x_I_filter=filter(b,1, x_I );
figure;subplot(2,1,1); plot(t*1e6,x_I_filter);xlabel('t/us');ylabel('x_I_ filter');title('低通滤波后的I路信号');
x_Q_filter=filter(b,1, x_Q );
subplot(2,1,2); plot(t*1e6,x_Q_filter);xlabel('t/us');ylabel('x_Q_ filter');title('低通滤波后的Q路信号');
%%********** 3.抽样 **********%%
x_I_ex=x_I_filter(1:2:end);
figure; subplot(2,1,1);plot(t(1:2:end)*1e6,x_I_ex);xlabel('t/us');ylabel('x_I_ ex');title('抽样后的I路信号');
x_Q_ex=x_Q_filter(1:2:end);
subplot(2,1,2); plot(t(1:2:end)*1e6,x_Q_ex);xlabel('t/us');ylabel('x_Q_ ex');title('抽样后的Q路信号');
%%************ 4.合成 ***********%%
x_ex= x_I_ex+1j*x_Q_ex;
figure;
plot(t(1:2:end)*1e6,x_ex);
xlabel('t/us');
ylabel('x_ ex');title('正交下变频的最终合成信号');

26
untitled5.m Normal file
View File

@ -0,0 +1,26 @@
clear all;
close all;
clc;
%%%%%%%%%%%%%%%%%%%%%%%%%%%% 频域数字正交相干检波 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%********** 线性调频信号波形 **********%%
T=10e-6; %信号时宽
B=30e6; %信号带宽
fs=4*B; %采样频率
f0=3/4*fs; %载频频率
N=fix(T*fs); %采样点数
t=(-N/2:N/2-1)/fs;
sr=cos(2*pi*f0*t+pi*(B/T).*t.^2);
figure;
subplot(2,1,1);plot(t*1e6,sr); title('线性调频信号波形'); xlabel('t/us'); ylabel('sr');
%%********** 线性调频信号的频谱 **********%%
L=2^nextpow2(N);
Sf1=fftshift(abs(fft(sr,L)));
f=linspace(-fs/2,fs/2,L);
subplot(2,1,2);plot(f*1e-6,Sf1); title('线性调频信号频谱'); xlabel('f/MHz'); ylabel('Sf1');
%%********** 1.频谱搬移 **********%%
Sf=fftshift(abs(fft(sr.*exp(-1j*2*pi*f0.*t),L)));
figure;plot(f*1e-6,Sf); title('频谱搬移后的信号'); xlabel('f/MHz'); ylabel('Sf');
%%********** 2.频率滤波+抽取 **********%%
Sf_ex=[Sf(1:L/4),Sf(3/4*L+1:end)];
figure;plot(f(1:2:end)*1e-6,fftshift(Sf_ex)); title('滤波抽取后的信号'); xlabel('f/MHz'); ylabel('Sf_ ex');

17
untitled6.asv Normal file
View File

@ -0,0 +1,17 @@
T=10e-3; %信号时宽
B=3e6; %信号带宽
fs=4*B; %采样频率
N=fix(T*fs); %采样点数
x = 0:T/N:T;
f=sin(2*pi*300*x) + sin(2*pi*200*x);
plot(f)
y= x(1:2:N); %采样x的奇数点
z=x(2:2:N);%采样x的偶数点
I =

26
untitled6.m Normal file
View File

@ -0,0 +1,26 @@
T=10e-3; %信号时宽
B=3e6; %信号带宽
fs=4*B; %采样频率
N=fix(T*fs); %采样点数
x = 0:T/N:T;
f=sin(2*pi*300*x) + sin(2*pi*200*x);
y= x(1:2:N); %采样x的奇数点
z=x(2:2:N);%采样x的偶数点
fi=sin(2*pi*300*y) + sin(2*pi*200*y);
fq=sin(2*pi*300*z) + sin(2*pi*200*z);
subplot(2,2,1)
plot(fi)
subplot(2,2,2)
plot(fq)
complexArray = fi + fq*1i;
complexArray = complexArray';