diff --git a/ModeS_Simulink_Decode.slxc b/ModeS_Simulink_Decode.slxc new file mode 100644 index 0000000..febc21b Binary files /dev/null and b/ModeS_Simulink_Decode.slxc differ diff --git a/ModeS_Simulink_libiio.slxc b/ModeS_Simulink_libiio.slxc new file mode 100644 index 0000000..4d709e8 Binary files /dev/null and b/ModeS_Simulink_libiio.slxc differ diff --git a/Untitled.m b/Untitled.m new file mode 100644 index 0000000..8200bfa --- /dev/null +++ b/Untitled.m @@ -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; + diff --git a/libiio_if.m b/libiio_if.m index 73d86cd..d4ae244 100644 --- a/libiio_if.m +++ b/libiio_if.m @@ -679,18 +679,23 @@ classdef libiio_if < handle %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function ret = writeAttributeString(obj, attr_name, str) % Find the attribute - [ret, ch, attr] = findAttribute(obj, attr_name); - if(ret < 0) - return; - end - - % Write the attribute - if(ret > 0) - calllib(obj.libname, 'iio_channel_attr_write', ch, attr, str); - clear ch; - clear attr; - else - calllib(obj.libname, 'iio_device_attr_write', obj.iio_dev, attr_name, str); + try + [ret, ch, attr] = findAttribute(obj, attr_name); + if(ret < 0) + return; + end + + % Write the attribute + if(ret > 0) + calllib(obj.libname, 'iio_channel_attr_write', ch, attr, str); + clear ch; + clear attr; + else + calllib(obj.libname, 'iio_device_attr_write', obj.iio_dev, attr_name, str); + end + catch e + disp("error ",e) + end end end diff --git a/slprj/_jitprj/jitEngineAccessInfo.mat b/slprj/_jitprj/jitEngineAccessInfo.mat new file mode 100644 index 0000000..7706148 Binary files /dev/null and b/slprj/_jitprj/jitEngineAccessInfo.mat differ diff --git a/slprj/_jitprj/sRYGBkScZGOrzxV4LTGBbkH.l b/slprj/_jitprj/sRYGBkScZGOrzxV4LTGBbkH.l new file mode 100644 index 0000000..0c08d0d Binary files /dev/null and b/slprj/_jitprj/sRYGBkScZGOrzxV4LTGBbkH.l differ diff --git a/slprj/_jitprj/sRYGBkScZGOrzxV4LTGBbkH.mat b/slprj/_jitprj/sRYGBkScZGOrzxV4LTGBbkH.mat new file mode 100644 index 0000000..41ee913 Binary files /dev/null and b/slprj/_jitprj/sRYGBkScZGOrzxV4LTGBbkH.mat differ diff --git a/slprj/_jitprj/sb0XnXuN7qtoIdBaF7LWaDG.l b/slprj/_jitprj/sb0XnXuN7qtoIdBaF7LWaDG.l new file mode 100644 index 0000000..7fa5e5f Binary files /dev/null and b/slprj/_jitprj/sb0XnXuN7qtoIdBaF7LWaDG.l differ diff --git a/slprj/_jitprj/sb0XnXuN7qtoIdBaF7LWaDG.mat b/slprj/_jitprj/sb0XnXuN7qtoIdBaF7LWaDG.mat new file mode 100644 index 0000000..2e7a335 Binary files /dev/null and b/slprj/_jitprj/sb0XnXuN7qtoIdBaF7LWaDG.mat differ diff --git a/slprj/_jitprj/stIJuliJNnraVVaFr0TgD2.l b/slprj/_jitprj/stIJuliJNnraVVaFr0TgD2.l new file mode 100644 index 0000000..99a8dd5 Binary files /dev/null and b/slprj/_jitprj/stIJuliJNnraVVaFr0TgD2.l differ diff --git a/slprj/_jitprj/stIJuliJNnraVVaFr0TgD2.mat b/slprj/_jitprj/stIJuliJNnraVVaFr0TgD2.mat new file mode 100644 index 0000000..188c2c6 Binary files /dev/null and b/slprj/_jitprj/stIJuliJNnraVVaFr0TgD2.mat differ diff --git a/slprj/_sfprj/EMLReport/emlReportAccessInfo.mat b/slprj/_sfprj/EMLReport/emlReportAccessInfo.mat new file mode 100644 index 0000000..a26cdd5 Binary files /dev/null and b/slprj/_sfprj/EMLReport/emlReportAccessInfo.mat differ diff --git a/slprj/_sfprj/EMLReport/sb0XnXuN7qtoIdBaF7LWaDG.mat b/slprj/_sfprj/EMLReport/sb0XnXuN7qtoIdBaF7LWaDG.mat new file mode 100644 index 0000000..0cc8f79 Binary files /dev/null and b/slprj/_sfprj/EMLReport/sb0XnXuN7qtoIdBaF7LWaDG.mat differ diff --git a/slprj/_sfprj/ModeS_Simulink_Decode/_self/sfun/info/binfo.mat b/slprj/_sfprj/ModeS_Simulink_Decode/_self/sfun/info/binfo.mat new file mode 100644 index 0000000..b06ec2a Binary files /dev/null and b/slprj/_sfprj/ModeS_Simulink_Decode/_self/sfun/info/binfo.mat differ diff --git a/slprj/_sfprj/ModeS_Simulink_Decode/amsi_serial.mat b/slprj/_sfprj/ModeS_Simulink_Decode/amsi_serial.mat new file mode 100644 index 0000000..dca02ab Binary files /dev/null and b/slprj/_sfprj/ModeS_Simulink_Decode/amsi_serial.mat differ diff --git a/slprj/_sfprj/ModeS_Simulink_libiio/_self/sfun/info/binfo.mat b/slprj/_sfprj/ModeS_Simulink_libiio/_self/sfun/info/binfo.mat new file mode 100644 index 0000000..0ffd5e4 Binary files /dev/null and b/slprj/_sfprj/ModeS_Simulink_libiio/_self/sfun/info/binfo.mat differ diff --git a/slprj/_sfprj/ModeS_Simulink_libiio/amsi_serial.mat b/slprj/_sfprj/ModeS_Simulink_libiio/amsi_serial.mat new file mode 100644 index 0000000..682d75a Binary files /dev/null and b/slprj/_sfprj/ModeS_Simulink_libiio/amsi_serial.mat differ diff --git a/slprj/sim/varcache/ModeS_Simulink_Decode/checksumOfCache.mat b/slprj/sim/varcache/ModeS_Simulink_Decode/checksumOfCache.mat new file mode 100644 index 0000000..ff2004b Binary files /dev/null and b/slprj/sim/varcache/ModeS_Simulink_Decode/checksumOfCache.mat differ diff --git a/slprj/sim/varcache/ModeS_Simulink_Decode/tmwinternal/simulink_cache.xml b/slprj/sim/varcache/ModeS_Simulink_Decode/tmwinternal/simulink_cache.xml new file mode 100644 index 0000000..3c56f0b --- /dev/null +++ b/slprj/sim/varcache/ModeS_Simulink_Decode/tmwinternal/simulink_cache.xml @@ -0,0 +1,6 @@ + + + + VFtF99vSvsCWQT3DC33ogPopY/EU2MB9X+ztRX0tkPyJIk22VJl2UuKDFAE/67uQWgN9IWAxaLNzfOMlT+LNUg== + + \ No newline at end of file diff --git a/slprj/sim/varcache/ModeS_Simulink_Decode/varInfo.mat b/slprj/sim/varcache/ModeS_Simulink_Decode/varInfo.mat new file mode 100644 index 0000000..0053ce6 Binary files /dev/null and b/slprj/sim/varcache/ModeS_Simulink_Decode/varInfo.mat differ diff --git a/slprj/sim/varcache/ModeS_Simulink_libiio/checksumOfCache.mat b/slprj/sim/varcache/ModeS_Simulink_libiio/checksumOfCache.mat new file mode 100644 index 0000000..bb80bcb Binary files /dev/null and b/slprj/sim/varcache/ModeS_Simulink_libiio/checksumOfCache.mat differ diff --git a/slprj/sim/varcache/ModeS_Simulink_libiio/tmwinternal/simulink_cache.xml b/slprj/sim/varcache/ModeS_Simulink_libiio/tmwinternal/simulink_cache.xml new file mode 100644 index 0000000..03a1d6f --- /dev/null +++ b/slprj/sim/varcache/ModeS_Simulink_libiio/tmwinternal/simulink_cache.xml @@ -0,0 +1,6 @@ + + + + aLg/RUXejXaW8fNin2SGwVZLG/5ro5PG+yBxjklFR/1BBYs/xCj7Lk9CzTx9lqJPd57O5bml0GwA4NkC5cok4g== + + \ No newline at end of file diff --git a/slprj/sim/varcache/ModeS_Simulink_libiio/varInfo.mat b/slprj/sim/varcache/ModeS_Simulink_libiio/varInfo.mat new file mode 100644 index 0000000..e4238de Binary files /dev/null and b/slprj/sim/varcache/ModeS_Simulink_libiio/varInfo.mat differ diff --git a/untitled2.m b/untitled2.m new file mode 100644 index 0000000..d5e8d94 --- /dev/null +++ b/untitled2.m @@ -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'); + \ No newline at end of file diff --git a/untitled3.m b/untitled3.m new file mode 100644 index 0000000..0b2ae6b --- /dev/null +++ b/untitled3.m @@ -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('幅度'); \ No newline at end of file diff --git a/untitled4.m b/untitled4.m new file mode 100644 index 0000000..1e1ba88 --- /dev/null +++ b/untitled4.m @@ -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('正交下变频的最终合成信号'); diff --git a/untitled5.m b/untitled5.m new file mode 100644 index 0000000..85393a2 --- /dev/null +++ b/untitled5.m @@ -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'); diff --git a/untitled6.asv b/untitled6.asv new file mode 100644 index 0000000..3603559 --- /dev/null +++ b/untitled6.asv @@ -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 = + diff --git a/untitled6.m b/untitled6.m new file mode 100644 index 0000000..809ec67 --- /dev/null +++ b/untitled6.m @@ -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'; \ No newline at end of file