├── .gitattributes ├── .gitignore ├── Carrier frequency estimation ├── carrier_estimate.m ├── f_offset_est.m ├── gen_AM.m └── main.m ├── DDC └── modulation IF DDC │ ├── CMA.m │ ├── C_f.m │ ├── DDC_filter.m │ ├── MaxSpectralDensity.m │ ├── SpectralSymmetryIndex.m │ ├── f_offset_est.m │ ├── gen_AM.m │ ├── gen_ASK2.m │ ├── gen_DPSK2.m │ ├── gen_FM.m │ ├── gen_FSK2.m │ ├── gen_MASK.m │ ├── gen_MFSK.m │ ├── gen_OQPSK.m │ ├── gen_PSK2.m │ ├── gen_QPSK.m │ ├── gen_pi4DQPSK.m │ ├── main.m │ ├── modulation_recognize.m │ ├── mu_a_42.m │ ├── mu_f_42.m │ ├── sigma_a.m │ ├── sigma_aa.m │ ├── sigma_af.m │ ├── sigma_ap.m │ └── sigma_dp.m ├── LICENSE ├── Modern Digital Signal Processing ├── Unclassified │ └── some task │ │ ├── chapter3 │ │ ├── 2-1.fig │ │ ├── 2-2.fig │ │ ├── 2-3.fig │ │ ├── chapter3-computer simulations.pdf │ │ ├── main.m │ │ ├── s3.m │ │ ├── s4_AR.m │ │ ├── s5MVDR.m │ │ ├── s6MUSIC.m │ │ ├── s7Root_MUSIC.m │ │ ├── s8ESPRIT.m │ │ └── 现代数字信号处理仿真实验报告模板.doc │ │ ├── chapter4 │ │ ├── chapter4-computer simulations.pdf │ │ ├── chapter4_1.m │ │ └── chapter4_2.m │ │ ├── chapter5 │ │ ├── M=16 tri.fig │ │ ├── M=16.mat │ │ ├── M=5 tri.fig │ │ ├── M=5.mat │ │ ├── MSE,M=16.fig │ │ ├── MSE,M=5.fig │ │ ├── adaptive_equalization_page191.m │ │ ├── chapter5-computer simulations.pdf │ │ ├── chapter5_2.m │ │ └── chapter5_3.m │ │ ├── chapter6 │ │ ├── 2.fig │ │ ├── chapter6-computer simulations.pdf │ │ ├── chapter6_1_1.m │ │ ├── chapter6_1_2.m │ │ ├── chapter6_2.m │ │ ├── chapter6_3.m │ │ └── untitled.fig │ │ ├── chapter7 │ │ ├── chapter7-computer simulations.pdf │ │ └── chapter7_1.m │ │ └── chapter8 │ │ ├── chapter8-computer simulations.pdf │ │ ├── chapter8_1.m │ │ ├── chapter8_2.m │ │ ├── chapter8_3.m │ │ └── page337_8_20.m └── 现代信号处理.xmind ├── Modulated signal ├── Basic │ ├── AM.m │ ├── ASK2.m │ ├── DDC_filter.m │ ├── DPSK2.m │ ├── DSB.m │ ├── FM.m │ ├── FSK2.m │ ├── GMSK │ │ ├── GMSK.m │ │ ├── g_t.m │ │ ├── plotPowerSpectrum.m │ │ └── plotSpectral.m │ ├── ISB.m │ ├── MASK.m │ ├── MFSK.m │ ├── MSK │ │ ├── MSK.m │ │ └── plotSpectral.m │ ├── OQPSK │ │ ├── OQPSK.m │ │ └── plotSpectral.m │ ├── PSK2.m │ ├── QAM │ │ ├── QAM.m │ │ ├── QAM2.m │ │ ├── QAM3.m │ │ ├── gen_gray_code.m │ │ └── plotSpectral.m │ ├── QPSK.m │ ├── SSB.m │ ├── pi4DQPSK │ │ ├── pi4DQPSK.m │ │ └── plotSpectral.m │ └── plotSpectral.m ├── KeyValue │ ├── GMSK.m │ ├── KeyStatisticalFeaturesFromTheCommunicationSignal.m │ ├── MSK.m │ ├── MSK_signal.txt │ ├── M_pq.m │ ├── MaxSpectralDensity.m │ ├── OQPSK.m │ ├── OQPSK_signal.txt │ ├── QAM.m │ ├── SpectralSymmetryIndex.m │ ├── bispecd.m │ ├── carrier_estimate.m │ ├── gen_data_file.m │ ├── gen_gray_code.m │ ├── modulation_recognize.m │ ├── mu_a_42.m │ ├── mu_f_42.m │ ├── pi4DQPSK.m │ ├── plotBispectra.m │ ├── plotSpectral.m │ ├── plotSquareSpectrum.m │ ├── sigma_a.m │ ├── sigma_aa.m │ ├── sigma_af.m │ ├── sigma_ap.m │ ├── sigma_dp.m │ └── test.m ├── Synchronizer │ ├── CarrierSynchronizer │ │ └── readme.md │ ├── SymbolSynchronizer test │ │ ├── Gardner_func.m │ │ ├── main.m │ │ ├── readme.md │ │ ├── reference │ │ │ ├── online 1 │ │ │ │ └── Gardner.m │ │ │ ├── online 2 │ │ │ │ └── gardner.m │ │ │ ├── online 3 │ │ │ │ └── main.m │ │ │ └── online 4 │ │ │ │ ├── fourTOtwo.m │ │ │ │ ├── judge.m │ │ │ │ ├── main.m │ │ │ │ └── twoTOfour.m │ │ ├── some paper │ │ │ └── Symbol Synchronization Techniques in Digital Communications │ │ │ │ ├── BPSK_Garder │ │ │ │ └── main.m │ │ │ │ └── Symbol Synchronization Techniques in Digital Communications.pdf │ │ └── symbol rate est │ │ │ └── online1 │ │ │ └── main.m │ └── online1 │ │ ├── Gardner_timing.m │ │ ├── System.m │ │ └── phase_frequence_recover.m ├── by_matlab_modulator │ ├── OQPSK │ │ └── main.m │ ├── desktop.ini │ └── test │ │ └── main.m ├── function │ ├── gen_AM.m │ ├── gen_ASK2.m │ ├── gen_OQPSK.m │ └── main.m └── raised_cosine │ ├── gen_rcos │ └── main.m │ └── main.m ├── README.md ├── Signals and Systems ├── CIC │ ├── main.m │ └── resample │ │ ├── main.m │ │ └── resample_CIC.m ├── HPF │ └── main.m ├── Half-Band filter │ ├── halfband.m │ └── main.m ├── Initial-value Theorem │ └── main.m ├── LPF │ └── main.m ├── Nyquist │ ├── Variable_Frequency.m │ ├── main.m │ └── mian2.m ├── decimation and interpolation │ ├── Interpolation.m │ └── decimation.m └── delta_n │ └── main.m ├── USRP └── sdr_help.md ├── Unclassified ├── Hilbert │ ├── envelope.m │ └── main.m ├── Spectrum │ └── Periodogram1.m ├── filter │ ├── main.m │ └── test.m ├── sample │ └── LowOrBandSample │ │ └── main.m └── 同步.xmind ├── Wavelet └── main.m ├── neural network └── BP │ ├── 42633797BP_neural_network_data_classification.rar │ ├── main.m │ └── 案例1 │ ├── BP.m │ ├── BPDLX.m │ ├── data1.mat │ ├── data2.mat │ ├── data3.mat │ └── data4.mat ├── noise ├── main.m ├── plotBispectra.m ├── plotPowerSpectrum.m ├── plotSpectral.m ├── plotSpectral2.m └── plotSquareSpectrum.m └── radar ├── BeamForming └── main.m ├── DOA ├── DOAByFFT │ └── main.m ├── MUSIC │ ├── DOAByMUSIC.m │ ├── doaMUSIC.m │ └── test.m └── readme.md ├── LFMradar ├── GspTest.m ├── baseLFM_Radar_PC_MTI_MTD.m └── genLFM.m ├── MatchFilter ├── genLFM.m └── test.m ├── PBR ├── main.m └── untitled.m ├── Range Doppler ├── RangeDoppler.m ├── main.m └── test.m ├── Space-Time Adaptive Processing └── test.m ├── beampattern ├── RectangularArrayBeamPattern.m ├── ULAbeamPattern1D.m ├── ULAbeamPattern2D.m └── readme.md └── clutter ├── clutterRayleigh.m ├── genLognormalDistributionRandTest.m ├── genRicianDistributionRandTest.m ├── genWeibullDistributionRandTest.m └── getPDF.m /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | *.asv 3 | Modulated signal/QAM/QAM3.m 4 | *.dat 5 | -------------------------------------------------------------------------------- /Carrier frequency estimation/carrier_estimate.m: -------------------------------------------------------------------------------- 1 | %carrier_estimate,page 267,(5-299),it only be used to estimate frequency of 2 | %signal which has symmetry spectrum 3 | %s:modulate signal 4 | %y:carrier frequency 5 | %fs:sample frequency 6 | function y=carrier_estimate(s,fs) 7 | S=fft(s)/length(s); 8 | N_half=length(s)/2; 9 | k=0:N_half-1; 10 | y=fs/length(s)*sum(abs(S(1:N_half)).^2.*k)/sum(abs(S(1:N_half)).^2); 11 | end -------------------------------------------------------------------------------- /Carrier frequency estimation/f_offset_est.m: -------------------------------------------------------------------------------- 1 | 2 | function f_offset=f_offset_est(s,fs,m) 3 | N=length(s); 4 | f=(-N/2:N/2-1)*(fs/N); 5 | S=abs(fftshift(fft(s.^m))); 6 | p_max=find(S==max(S)); 7 | f_offset=f(p_max)/m; 8 | end -------------------------------------------------------------------------------- /Carrier frequency estimation/gen_AM.m: -------------------------------------------------------------------------------- 1 | %Generating AM signal 2 | function [y_AM,I_AM,Q_AM]=gen_AM(A,fc,fs,L,m_a,v) 3 | %use orthogonal modulation generate modulated siganl 4 | %You can see the original signal v in the code. 5 | if nargin==0 6 | A=1; %%Ampltitude 7 | fc=1e4; %carrier frequency 8 | fs=1e5; %sample frequency 9 | L=10000; %length of signal 10 | m_a=0.3; %modulation index,|m_a|<1 11 | 12 | end 13 | T=1/fs; %sample time 14 | t=(0:L-1)*T; %time vector 15 | if nargin==0 16 | v=A*cos(2*pi*1000*t); %modulation signal 17 | end 18 | xs=sin(2*pi*fc*t); 19 | xc=cos(2*pi*fc*t); 20 | 21 | I_AM=A+m_a*v; 22 | Q_AM=0; 23 | y_AM=I_AM.*xc+Q_AM.*xs; 24 | 25 | 26 | -------------------------------------------------------------------------------- /Carrier frequency estimation/main.m: -------------------------------------------------------------------------------- 1 | clc 2 | clear all 3 | close all 4 | % parameter 5 | j=sqrt(-1); 6 | fc=1e4; %carrier frequency 7 | fs=1e5; %sample frequency 8 | Rs=1e3; %symbol rate of digital signal 9 | T=1/fs; %sample time 10 | L=10000; %length of signal 11 | t=(0:L-1)*T; %time vector 12 | ff=(-L/2:L/2-1)*(fs/L); %freq vector 13 | A=1; %%Ampltitude 14 | m_a=0.9; 15 | SNR=10; 16 | f0=Rs; %baseband frequency 17 | v=A*cos(2*pi*f0*t); 18 | 19 | [y_AM,I_AM,Q_AM]=gen_AM(A,fc,fs,L,m_a,v); 20 | f_est=carrier_estimate(v,fs) 21 | f_est=carrier_estimate(y_AM,fs) -------------------------------------------------------------------------------- /DDC/modulation IF DDC/CMA.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/DDC/modulation IF DDC/CMA.m -------------------------------------------------------------------------------- /DDC/modulation IF DDC/C_f.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/DDC/modulation IF DDC/C_f.m -------------------------------------------------------------------------------- /DDC/modulation IF DDC/DDC_filter.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/DDC/modulation IF DDC/DDC_filter.m -------------------------------------------------------------------------------- /DDC/modulation IF DDC/MaxSpectralDensity.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/DDC/modulation IF DDC/MaxSpectralDensity.m -------------------------------------------------------------------------------- /DDC/modulation IF DDC/SpectralSymmetryIndex.m: -------------------------------------------------------------------------------- 1 | %symmetrical characteristic of specturm ,page 261. 2 | function y=SpectralSymmetryIndex(s,fs,fc) 3 | Ns=length(s); 4 | %fc=carrier_estimate(s,fs); %Only when the carrier frequency 5 | %estimation is very accurate can 6 | %the following algorithm be implemented 7 | %fc=1e4; 8 | f_cn=round(fc*Ns/fs-1); 9 | S_abs=abs(fft(s))/Ns; 10 | P_L=sum(S_abs(1:f_cn).^2); 11 | P_U=sum(S_abs(1+f_cn+1:f_cn+f_cn+1).^2); 12 | P=(P_L-P_U)/(P_L+P_U); 13 | y=P; 14 | end -------------------------------------------------------------------------------- /DDC/modulation IF DDC/f_offset_est.m: -------------------------------------------------------------------------------- 1 | 2 | function f_offset=f_offset_est(s,fs,m) 3 | N=length(s); 4 | f=(-N/2:N/2-1)*(fs/N); 5 | S=abs(fftshift(fft(s.^m))); 6 | p_max=find(S==max(S)); 7 | f_offset=f(p_max)/m; 8 | end -------------------------------------------------------------------------------- /DDC/modulation IF DDC/gen_AM.m: -------------------------------------------------------------------------------- 1 | %Generating AM signal 2 | function [y_AM,I_AM,Q_AM]=gen_AM(A,fc,fs,L,m_a,v) 3 | %use orthogonal modulation generate modulated siganl 4 | %You can see the original signal v in the code. 5 | if nargin==0 6 | A=1; %%Ampltitude 7 | fc=1e4; %carrier frequency 8 | fs=1e5; %sample frequency 9 | L=10000; %length of signal 10 | m_a=0.3; %modulation index,|m_a|<1 11 | 12 | end 13 | T=1/fs; %sample time 14 | t=(0:L-1)*T; %time vector 15 | if nargin==0 16 | v=A*cos(2*pi*1000*t); %modulation signal 17 | end 18 | xs=sin(2*pi*fc*t); 19 | xc=cos(2*pi*fc*t); 20 | 21 | I_AM=A+m_a*v; 22 | Q_AM=zeros(1,length(I_AM))+0.0001; 23 | y_AM=I_AM.*xc+Q_AM.*xs; 24 | 25 | 26 | -------------------------------------------------------------------------------- /DDC/modulation IF DDC/gen_ASK2.m: -------------------------------------------------------------------------------- 1 | %Generating 2ASK signal 2 | function [y_2ask,I_ask,Q_ask]=gen_ASK2(A,fc,fs,Rs,L) 3 | %use orthogonal modulation generate modulated siganl 4 | %You can see the original signal v in the code. 5 | if nargin==0 6 | A=1; %%Ampltitude 7 | fc=1e4; %carrier frequency 8 | fs=1e5; %sample frequency 9 | Rs=1e3; %symbol rate of digital signal 10 | L=10000; %length of signal 11 | end 12 | T=1/fs; %sample time 13 | t=(0:L-1)*T; %time vector 14 | xs=sin(2*pi*fc*t); 15 | xc=cos(2*pi*fc*t); 16 | 17 | %2ASK 18 | % _________ ______ 19 | % signal | | | | 20 | %----------| |________| | so L/fs/T_ask is the length of a_n 21 | % <-T_ask-> 22 | %<-----------L points ---------------> 23 | T_ask=1/Rs; 24 | a_n=round(rand(1,round(L/(T_ask*fs)))); 25 | a_ask=repmat(a_n,round(T_ask*fs),1); 26 | a_ask=a_ask(:)'; 27 | size(xc) 28 | size(a_ask) 29 | %stairs(a_ask) %figure 2ask,unuse plot 30 | I_ask=0; 31 | Q_ask=a_ask; 32 | y_2ask=I_ask.*xc+Q_ask.*xs; 33 | y_2ask=A*y_2ask; 34 | end 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /DDC/modulation IF DDC/gen_DPSK2.m: -------------------------------------------------------------------------------- 1 | %Generating 2DPSK signal 2 | function [y_2dpsk,I_dpsk,Q_dpsk]=gen_DPSK2(A,fc,fs,Rs,L) 3 | %use orthogonal modulation generate modulated siganl 4 | %You can see the original signal v in the code. 5 | if nargin==0 6 | fc=1e4; %carrier frequency 7 | fs=1e5; %sample frequency 8 | Rs=2e3; %symbol rate of digital signal 9 | L=500; %length of signal 10 | A=1; %%Ampltitude 11 | end 12 | T=1/fs; %sample time 13 | t=(0:L-1)*T; %time vector 14 | xs=sin(2*pi*fc*t); 15 | xc=cos(2*pi*fc*t); 16 | 17 | T_dpsk=1/Rs; 18 | a_n=round(rand(1,round(L/(T_dpsk*fs)))); 19 | %2psk to 2dpsk 20 | for i=2:length(a_n) 21 | if a_n(i)==1 22 | a_n(i)=abs(a_n(i-1)-1); %if a_n=1 then 0->1,1->0 23 | else 24 | a_n(i)=a_n(i-1); 25 | end 26 | end 27 | a_n=2*(a_n>0)-1; %turn 0 of a_n to -1 28 | a_dpsk=repmat(a_n,T_dpsk*fs,1); 29 | a_dpsk=a_dpsk(:)'; 30 | I_dpsk=a_dpsk; 31 | Q_dpsk=0; 32 | y_2dpsk=A*(I_dpsk.*xc+Q_dpsk.*xs); 33 | -------------------------------------------------------------------------------- /DDC/modulation IF DDC/gen_FM.m: -------------------------------------------------------------------------------- 1 | %Generating FM signal 2 | function [y_fm,I_FM,Q_FM]=gen_FM(A,fc,fs,L) 3 | %use orthogonal modulation generate modulated siganl 4 | %You can see the original signal v in the code. 5 | if nargin==0 6 | fc=1e4; %carrier frequency 7 | fs=1e5; %sample frequency 8 | L=500; %length of signal 9 | A=1; %%Ampltitude 10 | end 11 | T=1/fs; %sample time 12 | t=(0:L-1)*T; %time vector 13 | 14 | v=A*cos(2*pi*1000*t); %modulation signal 15 | 16 | %FM 17 | K_omega=0.5; %freq offet index 18 | phi_fm=zeros(1,length(v)); 19 | for n=3:length(v) 20 | phi_fm(n)=K_omega/(2)*(v(1)+v(n)+2*sum(v(2:n-1))); 21 | end 22 | y_fm=A*cos(2*pi*fc.*t+phi_fm); 23 | I_FM=cos(phi_fm); 24 | Q_FM=-sin(phi_fm); 25 | 26 | -------------------------------------------------------------------------------- /DDC/modulation IF DDC/gen_FSK2.m: -------------------------------------------------------------------------------- 1 | %Generating FM signal 2 | function [y_fsk,I_FSK,Q_FSK]=gen_FSK2(A,fc,fs,Rs,L) 3 | %use orthogonal modulation generate modulated siganl 4 | %You can see the original signal v in the code. 5 | if nargin==0 6 | fc=1e4; %carrier frequency 7 | fs=1e5; %sample frequency 8 | Rs=5e3; %symbol rate of digital signal 9 | L=1000; %length of signal 10 | fc1=1.1e4; %|fc1-fc|Rs 12 | A=1; %%Ampltitude 13 | end 14 | T=1/fs; %sample time 15 | t=(0:L-1)*T; %time vector 16 | xs=sin(2*pi*fc*t); 17 | xc=cos(2*pi*fc*t); 18 | 19 | 20 | xs1=sin(2*pi*fc1*t); 21 | xc1=cos(2*pi*fc1*t); 22 | T_fsk=1/Rs; 23 | a_n=round(rand(1,round(L/(T_fsk*fs)))); 24 | a_fsk1=repmat(a_n,T_fsk*fs,1); 25 | a_fsk1=a_fsk1(:)'; 26 | a_fsk2=a_fsk1<1; %0->1,1->0 27 | 28 | 29 | I_fsk1=0; 30 | Q_fsk1=a_fsk1; 31 | I_fsk2=0; 32 | Q_fsk2=a_fsk2; 33 | y_fsk=I_fsk1.*xc+Q_fsk1.*xs+I_fsk2.*xc1+Q_fsk2.*xs1; %equal to add two ask 34 | y_fsk=A*y_fsk; 35 | I_FSK=[I_fsk1;I_fsk2]; 36 | Q_FSK=[Q_fsk1;Q_fsk2]; 37 | 38 | 39 | -------------------------------------------------------------------------------- /DDC/modulation IF DDC/gen_MASK.m: -------------------------------------------------------------------------------- 1 | %Generating MASK signal 2 | function [y_mask,I_mask,Q_mask]=gen_MASK(A,fc,fs,Rs,L,M) 3 | %use orthogonal modulation generate modulated siganl 4 | %You can see the original signal v in the code. 5 | if nargin==0 6 | fc=1e4; %carrier frequency 7 | fs=1e5; %sample frequency 8 | Rs=2e3; %symbol rate of digital signal 9 | L=1000; %length of signal 10 | A=1; %%Ampltitude 11 | M=4; %M-ary 12 | end 13 | T=1/fs; %sample time 14 | t=(0:L-1)*T; %time vector 15 | 16 | %v=A*cos(2*pi*1000*t); %modulation signal 17 | xs=sin(2*pi*fc*t); 18 | xc=cos(2*pi*fc*t); 19 | 20 | 21 | T_mask=1/Rs; 22 | 23 | a_n=round((M-1)*rand(1,round(L/(T_mask*fs))))*(1/M); %region 0 to 1 by 1/M. 24 | a_mask=repmat(a_n,T_mask*fs,1); 25 | a_mask=a_mask(:)'; 26 | %stairs(a_mask) %figure mask,unuse plot 27 | I_mask=0; 28 | Q_mask=a_mask; 29 | y_mask=A*(I_mask.*xc+Q_mask.*xs); 30 | 31 | 32 | -------------------------------------------------------------------------------- /DDC/modulation IF DDC/gen_MFSK.m: -------------------------------------------------------------------------------- 1 | %Generating FM signal 2 | function [y_MFSK,I_mfsk,Q_mfsk]=gen_MFSK(A,fc,fs,Rs,L,M) 3 | %use orthogonal modulation generate modulated siganl 4 | %You can see the original signal v in the code. 5 | if nargin==0 6 | fc=1e4; %carrier frequency 7 | fs=1e5; %sample frequency 8 | Rs=2e3; %symbol rate of digital signal 9 | L=500; %length of signal 10 | A=1; %%Ampltitude 11 | M=4; 12 | end 13 | T=1/fs; %sample time 14 | t=(0:L-1)*T; %time vector 15 | 16 | 17 | %fc_M=(1:M)*5e3; %M groups of carrier frequency 18 | fc_M=(1:M)*fc; 19 | xsM=sin(2*pi*fc_M'*t); 20 | xcM=cos(2*pi*fc_M'*t); 21 | T_MFSK=1/Rs; 22 | a_n=round((M-1)*rand(1,round(L/(T_MFSK*fs))))*(1/M); 23 | a_mfsk=repmat(a_n,T_MFSK*fs,1); 24 | a_mfsk=a_mfsk(:)'; 25 | %stairs(a_mfsk) 26 | a_mfsk_M=zeros(M,L); 27 | for i=1:M 28 | a_mfsk_M(i,:)=(a_mfsk==(i-1)/M); 29 | end 30 | I_mfsk=0; 31 | Q_mfsk=a_mfsk_M; 32 | y_MFSK=I_mfsk.*xcM+Q_mfsk.*xsM; 33 | y_MFSK=A*sum(y_MFSK,1); 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /DDC/modulation IF DDC/gen_OQPSK.m: -------------------------------------------------------------------------------- 1 | function [OQPSK_signal,s_complex,s,t,f]=gen_OQPSK(A,fc,fs,Rs,N) 2 | %OQPSK 3 | if nargin==0 4 | A=1; %amplitude 5 | Rs=10e2; %bit ratio 6 | N=1000; %Number of bits to process 7 | fc=10e3; %carrier frequency 8 | fs=10e4; %sample frequency 9 | end 10 | 11 | Ts=1/Rs; 12 | T=1/fs; 13 | t=(0:(round(N*Ts/T)-1))*T; 14 | L=length(t); 15 | f=(-L/2:L/2-1)*(fs/L); 16 | r=round(Ts/T); 17 | 18 | a=rand(1,N)>0.5; %bit symbol 19 | 20 | %% serial-to-paralle 21 | Idata=a(1:2:end); 22 | Idata=repmat(Idata,2,1); 23 | Idata=Idata(:)'; 24 | 25 | Qdata=a(2:2:end); 26 | Qdata=repmat(Qdata,2,1); 27 | Qdata=Qdata(:)'; 28 | 29 | %% Qdata delay one bit 30 | Qdata=[0,Qdata(1:end-1)]; 31 | 32 | %% Gray coded 33 | % 00->0->5pi/4 34 | % 01->1->7pi/4 35 | % 10->2->3pi/4 36 | % 11->3-> pi/4 37 | two_bits_decimal = [2,1]*[Qdata;Idata]; 38 | phase_code=pi*[5/4,7/4,3/4,1/4]; 39 | phi=phase_code(two_bits_decimal+1); 40 | 41 | phi_sample=repmat(phi,r,1); 42 | phi_sample=phi_sample(:)'; 43 | 44 | %% constellation 45 | j=sqrt(-1); 46 | s=cos(phi)+sin(phi)*j; 47 | 48 | %% carrier wave 49 | xc=cos(2*pi*fc*t); 50 | xs=sin(2*pi*fc*t); 51 | 52 | %% OQPSK 53 | 54 | OQPSK_signal=A*(cos(phi_sample).*xc-sin(phi_sample).*xs); 55 | 56 | s_complex=cos(phi_sample)+sin(phi_sample)*j; 57 | s_complex=A*s_complex; 58 | end -------------------------------------------------------------------------------- /DDC/modulation IF DDC/gen_PSK2.m: -------------------------------------------------------------------------------- 1 | %Generating 2psk signal 2 | function [y_2psk,I_psk,Q_psk]=gen_PSK2(A,fc,fs,Rs,L) 3 | %use orthogonal modulation generate modulated siganl 4 | %You can see the original signal v in the code. 5 | if nargin==0 6 | fc=5e3; %carrier frequency 7 | fs=1e5; %sample frequency 8 | Rs=1e3; %symbol rate of digital signal 9 | L=1000; %length of signal 10 | A=1; %%Ampltitude 11 | end 12 | T=1/fs; %sample time 13 | t=(0:L-1)*T; %time vector 14 | 15 | 16 | xs=sin(2*pi*fc*t); 17 | xc=cos(2*pi*fc*t); 18 | 19 | T_psk=1/Rs; 20 | a_n=round(rand(1,round(L/(T_psk*fs)))); 21 | a_n=2*(a_n>0)-1; 22 | a_psk=repmat(a_n,T_psk*fs,1); 23 | a_psk=a_psk(:)'; 24 | 25 | I_psk=a_psk; 26 | Q_psk=0; 27 | y_2psk=A*(I_psk.*xc+Q_psk.*xs); 28 | figure(1) 29 | plot(y_2psk) 30 | -------------------------------------------------------------------------------- /DDC/modulation IF DDC/gen_QPSK.m: -------------------------------------------------------------------------------- 1 | %Generating QPSK signal 2 | function [y_qpsk,I_QPSK,Q_QPSK]=gen_QPSK(A,fc,fs,Rs,L) 3 | %use orthogonal modulation generate modulated siganl 4 | %You can see the original signal v in the code. 5 | if nargin==0 6 | fc=1e4; %carrier frequency 7 | fs=1e5; %sample frequency 8 | Rs=2e3; %symbol rate of digital signal 9 | L=500; %length of signal 10 | 11 | A=1; %%Ampltitude 12 | end 13 | T=1/fs; %sample time 14 | t=(0:L-1)*T; %time vector 15 | xs=sin(2*pi*fc*t); 16 | xc=cos(2*pi*fc*t); 17 | 18 | T_qpsk=1/Rs; 19 | a_2n=round(rand(1,2*round(L/(T_qpsk*fs)))); 20 | phi_qpsk=[0 pi/2 pi 3*pi/2]; 21 | qpsk_code=[0,0;0,1;1,1;1,0]; 22 | I_QPSK=zeros(1,length(a_2n)/2); 23 | Q_QPSK=zeros(1,length(a_2n)/2); 24 | for i=1:length(a_2n)/2 25 | if a_2n(2*i-1:2*i)==qpsk_code(1,:) 26 | I_QPSK(i)=cos(phi_qpsk(1)); 27 | Q_QPSK(i)=-sin(phi_qpsk(1)); 28 | elseif a_2n(2*i-1:2*i)==qpsk_code(2,:) 29 | I_QPSK(i)=cos(phi_qpsk(2)); 30 | Q_QPSK(i)=-sin(phi_qpsk(2)); 31 | elseif a_2n(2*i-1:2*i)==qpsk_code(3,:) 32 | I_QPSK(i)=cos(phi_qpsk(3)); 33 | Q_QPSK(i)=-sin(phi_qpsk(3)); 34 | else 35 | I_QPSK(i)=cos(phi_qpsk(4)); 36 | Q_QPSK(i)=-sin(phi_qpsk(4)); 37 | end 38 | end 39 | I_QPSK=repmat(I_QPSK,T_qpsk*fs,1); 40 | I_QPSK=I_QPSK(:)'; 41 | Q_QPSK=repmat(Q_QPSK,T_qpsk*fs,1); 42 | Q_QPSK=Q_QPSK(:)'; 43 | y_qpsk=A*(I_QPSK.*xc+Q_QPSK.*xs); 44 | 45 | 46 | -------------------------------------------------------------------------------- /DDC/modulation IF DDC/gen_pi4DQPSK.m: -------------------------------------------------------------------------------- 1 | % pi/4DQPSK 2 | function [pi4DQPSK,s_complex,s,t,f]=gen_pi4DQPSK(A,fc,fs,Rs,N) 3 | if nargin==0 4 | A=1; %amplitude 5 | Rs=10e2; %bit ratio 6 | N=1000; %Number of bits to process 7 | fc=10e3; %carrier frequency 8 | fs=10e4; %sample frequency 9 | end 10 | 11 | Ts=1/Rs; 12 | T=1/fs; 13 | t=(0:(round(N*Ts/T)-1))*T; 14 | L=length(t); 15 | f=(-L/2:L/2-1)*(fs/L); 16 | r=round(Ts/T); 17 | 18 | a=rand(1,N)>0.5; %bit symbol 19 | 20 | %% serial-to-paralle 21 | Idata=a(1:2:end); 22 | Idata=repmat(Idata,2,1); 23 | Idata=Idata(:)'; 24 | 25 | Qdata=a(2:2:end); 26 | Qdata=repmat(Qdata,2,1); 27 | Qdata=Qdata(:)'; 28 | 29 | %% Qdata delay one bit 30 | Qdata=[0,Qdata(1:end-1)]; 31 | 32 | %% Gray coded 33 | % 00->0-> pi/4 34 | % 01->1-> 3pi/4 35 | % 10->2-> -pi/4 36 | % 11->3->-3pi/4 37 | two_bits_decimal = [2,1]*[Qdata;Idata]; 38 | phase_code=pi*[1/4,3/4,-1/4,-3/4]; 39 | phi=phase_code(two_bits_decimal+1); 40 | phi=cumsum(phi); 41 | %From here only the phase jump of pi/4 and 3pi/4 can be seen. 42 | 43 | phi_sample=repmat(phi,r,1); 44 | phi_sample=phi_sample(:)'; 45 | %% constellation 46 | j=sqrt(-1); 47 | s=cos(phi)+sin(phi)*j; 48 | %aaa=sum((cos(phi)>=-0.1)&(cos(phi)<=0.1))+sum((cos(phi)>=-1.1)&(cos(phi)<=-0.9))+sum((cos(phi)>=0.9)&(cos(phi)<=1.1)) 49 | 50 | %% carrier wave 51 | xc=cos(2*pi*fc*t); 52 | xs=sin(2*pi*fc*t); 53 | 54 | %% pi4DQPSK 55 | pi4DQPSK=A*(cos(phi_sample).*xc-sin(phi_sample).*xs); 56 | s_complex=cos(phi_sample)+sin(phi_sample)*j; 57 | s_complex=A*s_complex; 58 | end 59 | -------------------------------------------------------------------------------- /DDC/modulation IF DDC/main.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/DDC/modulation IF DDC/main.m -------------------------------------------------------------------------------- /DDC/modulation IF DDC/modulation_recognize.m: -------------------------------------------------------------------------------- 1 | %my code can't achieve modulate recognize if uses threshold in book 2 | function modulation_recognize(s,Rs,fc,fs) 3 | %A:analog,D:digital %range %maybe right 4 | tA_sigma_dp=pi/6; %pi/6 % 5 | tD_sigma_dp=pi/6.5; %pi/6.5-pi/2.5 % 6 | tAD_sigma_dp=1; %pi/6 % 1 7 | tA_P_SSB=0.5; %0.5-0.99 % 8 | tA_P_VSB=0.55; %0.55-0.6 % 9 | tAD_P_SSB=0.6; %0.6-0.9 % 10 | tAD_P_VSB=1; %0.5-0.7 %1 11 | tA_sigma_ap=pi/6.5; %pi/6.5-pi/2.5 % 12 | tD_sigma_ap=pi/5.5; %pi/5.5 % 13 | tAD_sigma_ap=pi/5.5; %pi/5.5 % 14 | t_sigma_a_2psk=0.1; %0.125-0.4 %0.1 15 | t_sigma_a_4psk=0.15; %0.15 %haven't test 16 | tA_gamma_max=5.5; %5.5-6 % 17 | tD_gamma_max=4; %4 % 18 | tAD_gamma_max=0.1; %2-2.5 %0.1 19 | tAD_mu_a_42=2.15; %2.15 % 20 | tAD_mu_f_42=2; %2.03 % 21 | tD_AD_sigma_aa=0.25; %0.25 % 22 | tD_AD_sigma_af=1.5; %0.4 %1.5 23 | 24 | a_t=1; 25 | Ysigma_dp=sigma_dp(s,a_t,fs,fc,2) 26 | Ysigma_ap=sigma_ap(s,a_t,fs,fc,2) 27 | Ymu_f_42=mu_f_42(s,fs,Rs,2) 28 | Ymu_a_42=mu_a_42(s,2) %not use func in book 29 | Ysigma_a=sigma_a(s,0.2,2) %there threshold I take 0.2 by test 30 | Ysigma_af=sigma_af(s,a_t,fs,Rs,2) 31 | Ysigma_aa=sigma_aa(s,2) 32 | Ygamma_max=MaxSpectralDensity(s,2) 33 | YP=SpectralSymmetryIndex(s,fs,fc) 34 | 35 | if Ysigma_dp>tAD_sigma_dp 36 | if abs(YP)>tAD_P_SSB 37 | if YP>0 38 | display('LSB'); 39 | else 40 | display('USB'); 41 | end 42 | else 43 | if Ysigma_aptAD_gamma_max 51 | if Ysigma_atAD_mu_f_42 58 | if Ysigma_af>tD_AD_sigma_af %I have changed logic 59 | display('4FSK'); 60 | else 61 | display('2FSK'); 62 | end 63 | else 64 | display('FM'); 65 | end 66 | end 67 | end 68 | end 69 | else 70 | if abs(YP)tD_AD_sigma_aa %I have changed logic 75 | display('4ASK'); 76 | else 77 | display('2ASK'); 78 | end 79 | end 80 | else 81 | display('VSB'); 82 | end 83 | end -------------------------------------------------------------------------------- /DDC/modulation IF DDC/mu_a_42.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/DDC/modulation IF DDC/mu_a_42.m -------------------------------------------------------------------------------- /DDC/modulation IF DDC/mu_f_42.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/DDC/modulation IF DDC/mu_f_42.m -------------------------------------------------------------------------------- /DDC/modulation IF DDC/sigma_a.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/DDC/modulation IF DDC/sigma_a.m -------------------------------------------------------------------------------- /DDC/modulation IF DDC/sigma_aa.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/DDC/modulation IF DDC/sigma_aa.m -------------------------------------------------------------------------------- /DDC/modulation IF DDC/sigma_af.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/DDC/modulation IF DDC/sigma_af.m -------------------------------------------------------------------------------- /DDC/modulation IF DDC/sigma_ap.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/DDC/modulation IF DDC/sigma_ap.m -------------------------------------------------------------------------------- /DDC/modulation IF DDC/sigma_dp.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/DDC/modulation IF DDC/sigma_dp.m -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 LHesperus 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Modern Digital Signal Processing/Unclassified/some task/chapter3/2-1.fig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/Modern Digital Signal Processing/Unclassified/some task/chapter3/2-1.fig -------------------------------------------------------------------------------- /Modern Digital Signal Processing/Unclassified/some task/chapter3/2-2.fig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/Modern Digital Signal Processing/Unclassified/some task/chapter3/2-2.fig -------------------------------------------------------------------------------- /Modern Digital Signal Processing/Unclassified/some task/chapter3/2-3.fig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/Modern Digital Signal Processing/Unclassified/some task/chapter3/2-3.fig -------------------------------------------------------------------------------- /Modern Digital Signal Processing/Unclassified/some task/chapter3/chapter3-computer simulations.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/Modern Digital Signal Processing/Unclassified/some task/chapter3/chapter3-computer simulations.pdf -------------------------------------------------------------------------------- /Modern Digital Signal Processing/Unclassified/some task/chapter3/main.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/Modern Digital Signal Processing/Unclassified/some task/chapter3/main.m -------------------------------------------------------------------------------- /Modern Digital Signal Processing/Unclassified/some task/chapter3/s3.m: -------------------------------------------------------------------------------- 1 | clear all 2 | close all 3 | j=sqrt(-1); 4 | L=10; %time of sim 5 | N=2^8; %length of signal 6 | M=64; %max delay 7 | n=0:N-1; 8 | f=[0.15,0.17,0.26]; 9 | 10 | for ii=1:L 11 | phi_k=2*pi*rand(1,3); %phase [0 2pi] 12 | a=rand(1,3); 13 | a=[2 2 3]; 14 | a_k=a.*exp(j*phi_k); %|a_k|? 15 | 16 | s_1=a_k(1)*exp(j*2*pi*f(1)*n); 17 | s_2=a_k(2)*exp(j*2*pi*f(2)*n); 18 | s_3=a_k(3)*exp(j*2*pi*f(3)*n); 19 | s_n=[s_1;s_2;s_3]; 20 | v_1=awgn(s_1,20,'measured'); 21 | v_2=awgn(s_2,25,'measured'); 22 | v_3=awgn(s_3,30,'measured'); 23 | v=[v_1;v_2;v_3]; 24 | u=sum(s_n+v); %signal 25 | 26 | 27 | %r_1(m)=1/N*\sum{n=0}{N-1}u_N(n)*u_N_*(n-m) |m|<=N-1 28 | 29 | m=-M+1:M-1; %delay of two signal 30 | %figure 31 | %r_1=conv(u,u)/N; 32 | %r_1=zeros(1,size(m)); 33 | r_1_m=0; 34 | for mm=1:size(m,2); 35 | if m(mm)>=0 36 | for nn=m(mm)+1:N 37 | %r_1_m=r_1_m+conj(u(nn))*u(nn-m(mm)); 38 | r_1_m=r_1_m+u(nn)*conj(u(nn-m(mm))); 39 | end 40 | else 41 | for nn=1:N+m(mm); 42 | r_1_m=r_1_m+u(nn)*conj(u(nn-m(mm))); 43 | end 44 | end 45 | 46 | r_1(mm)=r_1_m/N; 47 | r_1_m=0; 48 | 49 | end 50 | %figure 51 | % r_1=r_1(m(1)+N:m(end)+N)/max(r_1); 52 | % plot(abs(fft(r_1))) 53 | r_1=r_1/max(r_1); 54 | w_len=100; 55 | for w=1:w_len 56 | S_BT(w) = sum(r_1.*exp(-j*2*pi*((w-w_len/2)/w_len).*m(1:end))); 57 | end 58 | S_BT=abs(S_BT)/max(abs(S_BT)); 59 | %figure 60 | %plot(-0.5:1/w_len:0.5-1/w_len,log10(S_BT)) 61 | %title('BT') 62 | 63 | [peak_value,peak_pos]=findpeaks(log10(S_BT)); 64 | f1_pos=find(peak_value==max(peak_value)); 65 | peak_value(f1_pos)=-100; 66 | f2_pos=find(peak_value==max(peak_value)); 67 | peak_value(f2_pos)=-100; 68 | f3_pos=find(peak_value==max(peak_value)); 69 | f_est=[peak_pos(f1_pos),peak_pos(f2_pos),peak_pos(f3_pos)]; 70 | f_est=f_est*(1/w_len)-0.5; 71 | f_est=sort(f_est) 72 | e1=f_est-f; 73 | 74 | 75 | L1=(N-M/2)/(M/2); 76 | 77 | for w=1:w_len 78 | for ii=1:L1 79 | S_per(ii,w) = abs(sum(u((ii-1)/2*M+1:(ii+1)/2*M).*exp(-j*2*pi*((w-w_len/2)/w_len).*(0:M-1)))).^2; 80 | end 81 | end 82 | S_per=S_per/M; 83 | S_per=sum(S_per)/L1; 84 | S_per=S_per/max(S_per); 85 | %figure 86 | %plot(-0.5:1/w_len:0.5-1/w_len,log10(S_per)) 87 | %title('Welch') 88 | 89 | [peak_value,peak_pos]=findpeaks(log10(S_per)); 90 | f1_pos=find(peak_value==max(peak_value)); 91 | peak_value(f1_pos)=-100; 92 | f2_pos=find(peak_value==max(peak_value)); 93 | peak_value(f2_pos)=-100; 94 | f3_pos=find(peak_value==max(peak_value)); 95 | f_est=[peak_pos(f1_pos),peak_pos(f2_pos),peak_pos(f3_pos)]; 96 | f_est=f_est*(1/w_len)-0.5; 97 | f_est=sort(f_est); 98 | e2=f_est-f; 99 | end 100 | e(1,:)=sum(abs(e1).^2)/L; 101 | e(2,:)=sum(abs(e2).^2)/L; 102 | 103 | -------------------------------------------------------------------------------- /Modern Digital Signal Processing/Unclassified/some task/chapter3/s4_AR.m: -------------------------------------------------------------------------------- 1 | clear all 2 | close all 3 | j=sqrt(-1); 4 | L=100; %time of sim 5 | N=2^8; %length of signal 6 | M=8; %max delay 7 | n=0:N-1; 8 | f=[0.15,0.17,0.26]; 9 | 10 | %for ii=1:L 11 | phi_k=2*pi*rand(1,3); %phase [0 2pi] 12 | a=rand(1,3); 13 | a=[2 2 3]; 14 | a_k=a.*exp(j*phi_k); %|a_k|? 15 | 16 | s_1=a_k(1)*exp(j*2*pi*f(1)*n); 17 | s_2=a_k(2)*exp(j*2*pi*f(2)*n); 18 | s_3=a_k(3)*exp(j*2*pi*f(3)*n); 19 | s_n=[s_1;s_2;s_3]; 20 | v_1=awgn(s_1,20,'measured'); 21 | v_2=awgn(s_2,25,'measured'); 22 | v_3=awgn(s_3,30,'measured'); 23 | v=[v_1;v_2;v_3]; 24 | u=sum(s_n+v); %signal 25 | 26 | 27 | %r_1(m)=1/N*\sum{n=0}{N-1}u_N(n)*u_N_*(n-m) |m|<=N-1 28 | 29 | m=-M+1:M; %delay of two signal 30 | %figure 31 | %r_1=conv(u,u)/N; 32 | %r_1=zeros(1,size(m)); 33 | r_1_m=0; 34 | for mm=1:size(m,2); 35 | if m(mm)>=0 36 | for nn=m(mm)+1:N 37 | r_1_m=r_1_m+conj(u(nn))*u(nn-m(mm)); 38 | % r_1_m=r_1_m+u(nn)*conj(u(nn-m(mm))); 39 | end 40 | else 41 | for nn=1:N+m(mm); 42 | r_1_m=r_1_m+u(nn)*conj(u(nn-m(mm))); 43 | end 44 | end 45 | 46 | r_1(mm)=r_1_m/N; 47 | r_1_m=0; 48 | 49 | end 50 | %figure 51 | % r_1=r_1(m(1)+N:m(end)+N)/max(r_1); 52 | % plot(abs(fft(r_1))) 53 | r_1=r_1/max(r_1); 54 | 55 | p=8; 56 | for aa=1:p 57 | for bb=aa:p 58 | R_p(aa,bb)=r_1(aa-bb+M); 59 | end 60 | end 61 | R_p=R_p+R_p'-diag(r_1(M)*ones(1,p)); 62 | 63 | r_p=-conj(r_1(1+M:p+M)'); 64 | theta_p=-inv(R_p)*r_p; 65 | sigma_2=sum([1 conj(theta_p')].*conj(r_1(M:M+p))); 66 | 67 | w_len=100; 68 | for w=1:w_len 69 | 70 | S_AR(w)=sigma_2/(abs(1+sum(conj(theta_p').*exp(-j*2*pi*( (w-w_len/2)/w_len).* (1:p) ) ) )^2); 71 | end 72 | S_AR=abs(S_AR)/max(abs(S_AR)); 73 | [peak_value,peak_pos]=findpeaks(log10(S_AR)); 74 | f1_pos=find(peak_value==max(peak_value)); 75 | peak_value(f1_pos)=-100; 76 | f2_pos=find(peak_value==max(peak_value)); 77 | peak_value(f2_pos)=-100; 78 | f3_pos=find(peak_value==max(peak_value)); 79 | 80 | f_est=[peak_pos(f1_pos),peak_pos(f2_pos),peak_pos(f3_pos)]; 81 | f_est=f_est*(1/w_len)-0.5; 82 | f_est=sort(f_est); 83 | %plot(-0.5:1/w_len:0.5-1/w_len,log10(S_AR)) 84 | plot(0:1/w_len:0.5-1/w_len,log10(S_AR(w_len/2+1:end))) 85 | title('AR') 86 | %end -------------------------------------------------------------------------------- /Modern Digital Signal Processing/Unclassified/some task/chapter3/s5MVDR.m: -------------------------------------------------------------------------------- 1 | clear all 2 | close all 3 | j=sqrt(-1); 4 | L=100; %time of sim 5 | N=2^8; %length of signal 6 | M=32; %max delay 7 | n=0:N-1; 8 | f=[0.15,0.17,0.26]; 9 | 10 | %for ii=1:L 11 | phi_k=2*pi*rand(1,3); %phase [0 2pi] 12 | a=rand(1,3); 13 | a=[1 2 3]; 14 | a_k=a.*exp(j*phi_k); %|a_k|? 15 | 16 | s_1=a_k(1)*exp(j*2*pi*f(1)*n); 17 | s_2=a_k(2)*exp(j*2*pi*f(2)*n); 18 | s_3=a_k(3)*exp(j*2*pi*f(3)*n); 19 | s_n=[s_1;s_2;s_3]; 20 | v_1=awgn(s_1,20,'measured'); 21 | v_2=awgn(s_2,25,'measured'); 22 | v_3=awgn(s_3,30,'measured'); 23 | v=[v_1;v_2;v_3]; 24 | u=sum(s_n+v); %signal 25 | 26 | 27 | %r_1(m)=1/N*\sum{n=0}{N-1}u_N(n)*u_N_*(n-m) |m|<=N-1 28 | 29 | m=-M+1:M; %delay of two signal 30 | %figure 31 | %r_1=conv(u,u)/N; 32 | %r_1=zeros(1,size(m)); 33 | r_1_m=0; 34 | for mm=1:size(m,2); 35 | if m(mm)>=0 36 | for nn=m(mm)+1:N 37 | r_1_m=r_1_m+conj(u(nn))*u(nn-m(mm)); 38 | % r_1_m=r_1_m+u(nn)*conj(u(nn-m(mm))); 39 | end 40 | else 41 | for nn=1:N+m(mm); 42 | r_1_m=r_1_m+u(nn)*conj(u(nn-m(mm))); 43 | end 44 | end 45 | 46 | r_1(mm)=r_1_m/N; 47 | r_1_m=0; 48 | 49 | end 50 | %figure 51 | % r_1=r_1(m(1)+N:m(end)+N)/max(r_1); 52 | % plot(abs(fft(r_1))) 53 | r_1=r_1/max(r_1); 54 | 55 | M=8; 56 | for aa=1:M 57 | for bb=aa:M 58 | R(aa,bb)=r_1(aa-bb+M); 59 | end 60 | end 61 | R=R+R'-diag(r_1(M)*ones(1,M)); 62 | invR= inv(R); 63 | 64 | w_len=100; 65 | for w=1:w_len 66 | a_w=exp(-j*2*pi*( (w-w_len/2)/w_len)*(0:M-1)); 67 | P_MVDR(w)=1/abs(((a_w)*invR*(a_w'))); 68 | end 69 | P_MVDR=abs(P_MVDR)/max(abs(P_MVDR)); 70 | %[peak_value,peak_pos]=findpeaks(log10(S_AR)); 71 | %f1_pos=find(peak_value==max(peak_value)); 72 | %peak_value(f1_pos)=-100; 73 | %f2_pos=find(peak_value==max(peak_value)); 74 | %peak_value(f2_pos)=-100; 75 | %f3_pos=find(peak_value==max(peak_value)); 76 | % 77 | %f_est=[peak_pos(f1_pos),peak_pos(f2_pos),peak_pos(f3_pos)]; 78 | %f_est=f_est*(1/w_len)-0.5; 79 | %f_est=sort(f_est); 80 | figure 81 | %plot(-0.5:1/w_len:0.5-1/w_len,log10(P_MVDR)) 82 | plot(0:1/w_len:0.5-1/w_len,log10(P_MVDR(w_len/2+1:end))) 83 | title('MVDR') 84 | %end -------------------------------------------------------------------------------- /Modern Digital Signal Processing/Unclassified/some task/chapter3/s6MUSIC.m: -------------------------------------------------------------------------------- 1 | clear all 2 | close all 3 | j=sqrt(-1); 4 | L=100; %time of sim 5 | N=2^8; %length of signal 6 | M=32; %max delay 7 | n=0:N-1; 8 | k=2 9 | f=[0.15,0.17]%,0.26, 0.35]; 10 | 11 | %for ii=1:L 12 | phi_k=2*pi*rand(1,2); %phase [0 2pi] 13 | a=rand(1,3); 14 | a=[1 2 ]; 15 | a_k=a.*exp(j*phi_k); %|a_k|? 16 | 17 | s_1=a_k(1)*exp(j*2*pi*f(1)*n); 18 | s_2=a_k(2)*exp(j*2*pi*f(2)*n); 19 | %s_3=a_k(3)*exp(j*2*pi*f(3)*n); 20 | % s_4=a_k(4)*exp(j*2*pi*f(4)*n); 21 | s_n=[s_1;s_2];%;s_3;s_4]; 22 | v_1=awgn(s_1,20,'measured'); 23 | v_2=awgn(s_2,25,'measured'); 24 | %v_3=awgn(s_3,30,'measured'); 25 | % v_4=awgn(s_4,30,'measured'); 26 | v=[v_1;v_2];%;v_3;v_4]; 27 | u=sum(v); %signal 28 | 29 | 30 | %r_1(m)=1/N*\sum{n=0}{N-1}u_N(n)*u_N_*(n-m) |m|<=N-1 31 | 32 | m=-M+1:M; %delay of two signal 33 | %figure 34 | %r_1=conv(u,u)/N; 35 | %r_1=zeros(1,size(m)); 36 | r_1_m=0; 37 | for mm=1:size(m,2); 38 | if m(mm)>=0 39 | for nn=m(mm)+1:N 40 | r_1_m=r_1_m+conj(u(nn))*u(nn-m(mm)); 41 | % r_1_m=r_1_m+u(nn)*conj(u(nn-m(mm))); 42 | end 43 | else 44 | for nn=1:N+m(mm); 45 | r_1_m=r_1_m+u(nn)*conj(u(nn-m(mm))); 46 | end 47 | end 48 | 49 | r_1(mm)=r_1_m/N; 50 | r_1_m=0; 51 | 52 | end 53 | %figure 54 | % r_1=r_1(m(1)+N:m(end)+N)/max(r_1); 55 | % plot(abs(fft(r_1))) 56 | 57 | r_1=r_1/max(r_1); 58 | 59 | M=8; 60 | for aa=1:M 61 | for bb=aa:M 62 | R(aa,bb)=r_1(aa-bb+M); 63 | end 64 | end 65 | R=R+R'-diag(r_1(M)*ones(1,M)); 66 | [eig_vector,eig_value]=eig(R); 67 | % eig_value=abs(eig_value); 68 | eig_value=diag(eig_value) 69 | for kk=1:M-k 70 | eig_max(kk)=find(eig_value==min(eig_value)); 71 | eig_value(eig_max(kk))=1000; 72 | G(:,kk)=eig_vector(:,eig_max(kk)); 73 | end 74 | 75 | w_len=1000; 76 | for w=1:w_len 77 | a_w=exp(-j*2*pi*( (w-w_len/2)/w_len)*(0:M-1)); 78 | %aGGa(w)=abs( (a_w)*G*G'*(a_w')); 79 | % min_aGGa(w)=find(aGGa==min(aGGa(w))); 80 | P_MUSIC(w)=1/abs( (a_w)*G*G'*(a_w')); 81 | %P_MVDR(w)=1/abs((conj(a_w)*invR*conj(a_w'))); 82 | end 83 | P_MUSIC=abs(P_MUSIC)/max(abs(P_MUSIC)); 84 | [peak_value,peak_pos]=findpeaks(log10(P_MUSIC)); 85 | 86 | for kk=1:k 87 | fk_pos(kk)=find(peak_value==max(peak_value)); 88 | peak_value(fk_pos(kk))=-100; 89 | angle(a_w(fk_pos(kk))) 90 | f_est(kk)=peak_pos(fk_pos(kk)); 91 | end 92 | f_est=sort(f_est)*(1/w_len)-0.5; 93 | figure 94 | %plot(-0.5:1/w_len:0.5-1/w_len,log10(P_MUSIC)) 95 | plot(0:1/w_len:0.5-1/w_len,log10(P_MUSIC(w_len/2+1:end))) 96 | title('MUSIC') 97 | %end -------------------------------------------------------------------------------- /Modern Digital Signal Processing/Unclassified/some task/chapter3/s7Root_MUSIC.m: -------------------------------------------------------------------------------- 1 | clear all 2 | close all 3 | j=sqrt(-1); 4 | L=100; %time of sim 5 | N=2^8; %length of signal 6 | M=32; %max delay 7 | n=0:N-1; 8 | k=3 9 | f=[0.15,0.17,0.26]; 10 | 11 | %for ii=1:L 12 | phi_k=2*pi*rand(1,3); %phase [0 2pi] 13 | a=rand(1,3); 14 | a=[1 2 3]; 15 | a_k=a.*exp(j*phi_k); %|a_k|? 16 | 17 | s_1=a_k(1)*exp(j*2*pi*f(1)*n); 18 | s_2=a_k(2)*exp(j*2*pi*f(2)*n); 19 | s_3=a_k(3)*exp(j*2*pi*f(3)*n); 20 | s_n=[s_1;s_2;s_3]; 21 | v_1=awgn(s_1,20,'measured'); 22 | v_2=awgn(s_2,25,'measured'); 23 | v_3=awgn(s_3,30,'measured'); 24 | v=[v_1;v_2;v_3]; 25 | u=sum(v); %signal 26 | 27 | 28 | %r_1(m)=1/N*\sum{n=0}{N-1}u_N(n)*u_N_*(n-m) |m|<=N-1 29 | 30 | m=-M+1:M; %delay of two signal 31 | %figure 32 | %r_1=conv(u,u)/N; 33 | %r_1=zeros(1,size(m)); 34 | r_1_m=0; 35 | for mm=1:size(m,2); 36 | if m(mm)>=0 37 | for nn=m(mm)+1:N 38 | r_1_m=r_1_m+conj(u(nn))*u(nn-m(mm)); 39 | % r_1_m=r_1_m+u(nn)*conj(u(nn-m(mm))); 40 | end 41 | else 42 | for nn=1:N+m(mm); 43 | r_1_m=r_1_m+u(nn)*conj(u(nn-m(mm))); 44 | end 45 | end 46 | 47 | r_1(mm)=r_1_m/N; 48 | r_1_m=0; 49 | 50 | end 51 | %figure 52 | % r_1=r_1(m(1)+N:m(end)+N)/max(r_1); 53 | % plot(abs(fft(r_1))) 54 | 55 | r_1=r_1/max(r_1); 56 | 57 | M=8; 58 | for aa=1:M 59 | for bb=aa:M 60 | R(aa,bb)=r_1(aa-bb+M); 61 | end 62 | end 63 | R=R+R'-diag(r_1(M)*ones(1,M)); 64 | [eig_vector,eig_value]=eig(R); 65 | % eig_value=abs(eig_value); 66 | eig_value=diag(eig_value) 67 | for kk=1:M-k 68 | eig_max(kk)=find(eig_value==min(eig_value)); 69 | eig_value(eig_max(kk))=1000; 70 | G(:,kk)=eig_vector(:,eig_max(kk)); 71 | end 72 | 73 | w_len=1000; 74 | for w=1:w_len 75 | a_w=exp(-j*2*pi*( (w-w_len/2)/w_len)*(0:M-1)); 76 | P_MUSIC(w)=1/abs( (a_w)*G*G'*(a_w')); 77 | %P_MVDR(w)=1/abs((conj(a_w)*invR*conj(a_w'))); 78 | end 79 | P_MUSIC=abs(P_MUSIC)/max(abs(P_MUSIC)); 80 | [peak_value,peak_pos]=findpeaks(log10(P_MUSIC)); 81 | 82 | for kk=1:k 83 | fk_pos(kk)=find(peak_value==max(peak_value)); 84 | peak_value(fk_pos(kk))=-100; 85 | f_est(kk)=peak_pos(fk_pos(kk)); 86 | end 87 | f_est=sort(f_est)*(1/w_len)-0.5; 88 | figure 89 | plot(-0.5:1/w_len:0.5-1/w_len,log10(P_MUSIC)) 90 | 91 | %end -------------------------------------------------------------------------------- /Modern Digital Signal Processing/Unclassified/some task/chapter3/s8ESPRIT.m: -------------------------------------------------------------------------------- 1 | clear all 2 | close all 3 | j=sqrt(-1); 4 | L=100; %time of sim 5 | N=2^8; %length of signal 6 | M=32; %max delay 7 | n=0:N-1; 8 | k=3 9 | f=[0.15,0.17,0.26]; 10 | 11 | %for ii=1:L 12 | phi_k=2*pi*rand(1,3); %phase [0 2pi] 13 | a=rand(1,3); 14 | a=[1 2 3]; 15 | a_k=a.*exp(j*phi_k); %|a_k|? 16 | 17 | s_1=a_k(1)*exp(j*2*pi*f(1)*n); 18 | s_2=a_k(2)*exp(j*2*pi*f(2)*n); 19 | s_3=a_k(3)*exp(j*2*pi*f(3)*n); 20 | s_n=[s_1;s_2;s_3]; 21 | v_1=awgn(s_1,20,'measured'); 22 | v_2=awgn(s_2,25,'measured'); 23 | v_3=awgn(s_3,30,'measured'); 24 | v=[v_1;v_2;v_3]; 25 | u=sum(v); %signal 26 | 27 | 28 | %r_1(m)=1/N*\sum{n=0}{N-1}u_N(n)*u_N_*(n-m) |m|<=N-1 29 | 30 | m=-M+1:M; %delay of two signal 31 | %figure 32 | %r_1=conv(u,u)/N; 33 | %r_1=zeros(1,size(m)); 34 | r_1_m=0; 35 | for mm=1:size(m,2); 36 | if m(mm)>=0 37 | for nn=m(mm)+1:N 38 | r_1_m=r_1_m+conj(u(nn))*u(nn-m(mm)); 39 | % r_1_m=r_1_m+u(nn)*conj(u(nn-m(mm))); 40 | end 41 | else 42 | for nn=1:N+m(mm); 43 | r_1_m=r_1_m+u(nn)*conj(u(nn-m(mm))); 44 | end 45 | end 46 | 47 | r_1(mm)=r_1_m/N; 48 | r_1_m=0; 49 | 50 | end 51 | %figure 52 | % r_1=r_1(m(1)+N:m(end)+N)/max(r_1); 53 | % plot(abs(fft(r_1))) 54 | 55 | r_1=r_1/max(r_1); 56 | 57 | M=8; 58 | for aa=1:M 59 | for bb=aa:M 60 | R(aa,bb)=r_1(aa-bb+M); 61 | end 62 | end 63 | R=R+R'-diag(r_1(M)*ones(1,M)); 64 | [eig_vector,eig_value]=eig(R); 65 | % eig_value=abs(eig_value); 66 | eig_value=diag(eig_value) 67 | for kk=1:M-k 68 | eig_max(kk)=find(eig_value==min(eig_value)); 69 | eig_value(eig_max(kk))=1000; 70 | G(:,kk)=eig_vector(:,eig_max(kk)); 71 | end 72 | 73 | w_len=1000; 74 | for w=1:w_len 75 | a_w=exp(-j*2*pi*( (w-w_len/2)/w_len)*(0:M-1)); 76 | P_MUSIC(w)=1/abs( (a_w)*G*G'*(a_w')); 77 | %P_MVDR(w)=1/abs((conj(a_w)*invR*conj(a_w'))); 78 | end 79 | P_MUSIC=abs(P_MUSIC)/max(abs(P_MUSIC)); 80 | [peak_value,peak_pos]=findpeaks(log10(P_MUSIC)); 81 | 82 | for kk=1:k 83 | fk_pos(kk)=find(peak_value==max(peak_value)); 84 | peak_value(fk_pos(kk))=-100; 85 | f_est(kk)=peak_pos(fk_pos(kk)); 86 | end 87 | f_est=sort(f_est)*(1/w_len)-0.5; 88 | figure 89 | plot(-0.5:1/w_len:0.5-1/w_len,log10(P_MUSIC)) 90 | 91 | %end -------------------------------------------------------------------------------- /Modern Digital Signal Processing/Unclassified/some task/chapter3/现代数字信号处理仿真实验报告模板.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/Modern Digital Signal Processing/Unclassified/some task/chapter3/现代数字信号处理仿真实验报告模板.doc -------------------------------------------------------------------------------- /Modern Digital Signal Processing/Unclassified/some task/chapter4/chapter4-computer simulations.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/Modern Digital Signal Processing/Unclassified/some task/chapter4/chapter4-computer simulations.pdf -------------------------------------------------------------------------------- /Modern Digital Signal Processing/Unclassified/some task/chapter4/chapter4_1.m: -------------------------------------------------------------------------------- 1 | clc 2 | clear all 3 | close all 4 | 5 | N=16; 6 | L=10000; %signal length 7 | n=(0:L-1); 8 | phi=2*pi*rand; %Initial phase 9 | s=sin(2*pi/N*n+phi); 10 | d=2*cos(2*pi/N*n+phi); 11 | 12 | sigma_v_2=2; %noise power 13 | sigma_s=mean(s.^2);%signal power 14 | SNR=10*log10(sigma_s/sigma_v_2); 15 | 16 | u=awgn(s,SNR,'measured'); 17 | %figure 18 | %plot(s) 19 | %figure 20 | %plot(u) 21 | 22 | for m=0:L-1 23 | r_n(m+1)=sum(conj(u(1:L-m)).*u(m+1:L))/L; 24 | end 25 | 26 | % p(-n) 27 | for m=0:L-1 28 | p_neg_n(m+1)=sum(u(1:L-m).*conj(d(m+1:L)))/L; 29 | end 30 | 31 | R=[r_n(1) r_n(2);r_n(2)' r_n(1)]; 32 | p=[p_neg_n(1) p_neg_n(2)]'; 33 | w0=inv(R)*p 34 | w_0=linspace(-10,10,100); 35 | w_1=linspace(-10,10,100); 36 | for ii=1:length(w_0) 37 | for jj=1:length(w_1) 38 | w=[w_0(ii);w_1(jj)]; 39 | J_w(ii,jj)=mean(d.^2)-2*conj(p)'*w+conj(w)'*R*w; 40 | end 41 | end 42 | [w_0,w_1] = meshgrid(linspace(-10,10,100)); 43 | figure 44 | surf(w_0,w_1,J_w) 45 | xlabel('w_0') 46 | ylabel('w_1') 47 | zlabel('MSE') 48 | J_min=mean(d.^2)-conj(p)'*w0 49 | 50 | w=zeros(2,1); 51 | [V,D] = eig(R); 52 | lamada_max=max(diag(D)); 53 | mu_max=2/lamada_max; 54 | mu=0.1 ; 55 | for ii=1:100 56 | w(:,ii+1)=w(:,ii)+mu*(p-R*w(:,ii)); 57 | J(ii)=mean(d.^2)-conj(p)'*w(:,ii); 58 | end 59 | figure 60 | plot(J) 61 | xlabel('Iteration times') 62 | ylabel('J(n)') 63 | 64 | figure 65 | plot(w(1,:)) 66 | hold on 67 | plot(w(2,:)) 68 | %axis([0,100,-2,1]) 69 | legend('w_0','w_1') -------------------------------------------------------------------------------- /Modern Digital Signal Processing/Unclassified/some task/chapter4/chapter4_2.m: -------------------------------------------------------------------------------- 1 | clc 2 | clear all 3 | close all 4 | j=sqrt(-1); 5 | N=4; 6 | % 512,1024,2048,4096 7 | L=4096 ; %signal length 8 | sigma_v_2=0.0731; %noise power 9 | for nn=1:100 10 | v=sqrt(sigma_v_2)*randn(1,L); 11 | b=1; 12 | a=[1 -0.975 0.95]; 13 | z=filtic(b,a,[0 0]); 14 | u=filter(b,a,v,z); 15 | 16 | sigma_u_2=mean(u.^2); 17 | for m=0:L-1 18 | r_n(m+1)=sum(conj(u(1:L-m)).*u(m+1:L))/L; 19 | end 20 | R=[r_n(1) r_n(2);r_n(2)' r_n(1)]; 21 | for m=0:L-1 22 | p_neg_n(m+1)=sum(u(1:L-m).*conj(u(m+1:L)))/L; 23 | end 24 | p=[p_neg_n(1) p_neg_n(2)]'; 25 | [V,D] = eig(R); 26 | lamada_max=max(diag(D)) 27 | lamada_min=min(diag(D)); 28 | lamada_av=mean(diag(D)); 29 | mu_max=2/lamada_max; 30 | mu=0.01 31 | tao_av=1/(2*mu*lamada_av); 32 | M=2/(4*tao_av); 33 | X_R=lamada_max/lamada_min; 34 | %% LMS 35 | w=zeros(2,L); 36 | w_se=zeros(2,L); 37 | w_sr=zeros(2,L); 38 | w_ss=zeros(2,L); 39 | w_nlms=zeros(2,L); 40 | 41 | 42 | d_est=zeros(1,L); 43 | d_se_est=zeros(1,L); 44 | d_sr_est=zeros(1,L); 45 | d_ss_est=zeros(1,L); 46 | d_nlms_est=zeros(1,L); 47 | 48 | e=zeros(1,L); 49 | e_se=zeros(1,L); 50 | e_sr=zeros(1,L); 51 | e_ss=zeros(1,L); 52 | e_nlms=zeros(1,L); 53 | u=[0 0 u]; 54 | for ii=2:L 55 | %% LMS 56 | w(:,ii+1)=w(:,ii)+mu*conj(u(ii:-1:ii-1)')*conj(e(ii)); 57 | d_est(ii+1)=w(:,ii+1)'*conj(u(ii+1:-1:ii)'); 58 | e(ii+1)=u(ii+2)-d_est(ii+1); 59 | 60 | %% sign-error LMS 61 | csgn_e(ii)=sign(real(conj(e_se(ii))))+sign(imag(conj(e_se(ii))))*j; 62 | w_se(:,ii+1)=w_se(:,ii)+mu*conj(u(ii:-1:ii-1)')*csgn_e(ii); 63 | d_se_est(ii+1)=w_se(:,ii+1)'*conj(u(ii+1:-1:ii)'); 64 | e_se(ii+1)=u(ii+2)-d_se_est(ii+1); 65 | 66 | %% sign regressor LMS 67 | w_sr(:,ii+1)=w_sr(:,ii)+mu*sign(conj(u(ii:-1:ii-1)'))*e_sr(ii); 68 | d_sr_est(ii+1)=w_sr(:,ii+1)'*conj(u(ii+1:-1:ii)'); 69 | e_sr(ii+1)=u(ii+2)-d_sr_est(ii+1); 70 | %% sign-sign LMS 71 | w_ss(:,ii+1)=w_ss(:,ii)+mu*sign(conj(u(ii:-1:ii-1)'))*sign(e_ss(ii)); 72 | d_ss_est(ii+1)=w_ss(:,ii+1)'*conj(u(ii+1:-1:ii)'); 73 | e_ss(ii+1)=u(ii+2)-d_ss_est(ii+1); 74 | %% NLMS 75 | w_nlms(:,ii+1)=w_nlms(:,ii)+mu/(0.001+norm(u(ii:-1:ii-1),2))*conj(u(ii:-1:ii-1)')*conj(e_nlms(ii)); 76 | d_nlms_est(ii+1)=w_nlms(:,ii+1)'*conj(u(ii+1:-1:ii)'); 77 | e_nlms(ii+1)=u(ii+2)-d_nlms_est(ii+1); 78 | 79 | J(nn,ii-1)=mean(u.^2)-conj(p)'*w(:,ii); 80 | J_se(nn,ii-1)=mean(u.^2)-conj(p)'*w_se(:,ii); 81 | J_sr(nn,ii-1)=mean(u.^2)-conj(p)'*w_sr(:,ii); 82 | J_ss(nn,ii-1)=mean(u.^2)-conj(p)'*w_ss(:,ii); 83 | J_nlms(nn,ii-1)=mean(u.^2)-conj(p)'*w_nlms(:,ii); 84 | end 85 | end 86 | figure 87 | plot(J(end,:)) 88 | hold on 89 | plot(mean(J)); 90 | xlabel('Iteration times') 91 | ylabel('J_n') 92 | legend('typical', 'mean') 93 | title('LMS'); 94 | 95 | figure 96 | plot(J_se(end,:)) 97 | hold on 98 | plot(mean(J_se)); 99 | xlabel('Iteration times') 100 | ylabel('J_n') 101 | legend('typical', 'mean') 102 | title('sign-error LMS'); 103 | 104 | figure 105 | plot(J_sr(end,:)) 106 | hold on 107 | plot(mean(J_sr)); 108 | xlabel('Iteration times') 109 | ylabel('J_n') 110 | legend('typical', 'mean') 111 | title('sign regressor LMS'); 112 | 113 | figure 114 | plot(J_ss(end,:)) 115 | hold on 116 | plot(mean(J_ss)); 117 | xlabel('Iteration times') 118 | legend('typical', 'mean') 119 | title('sign-sign LMS'); 120 | 121 | figure 122 | plot(J_nlms(end,:)) 123 | hold on 124 | plot(mean(J_nlms)); 125 | xlabel('Iteration times') 126 | ylabel('J_n') 127 | legend('typical', 'mean') 128 | title('NLMS'); 129 | %figure 130 | %plot(w(1,:)) 131 | %hold on 132 | %plot(w(2,:)) 133 | % 134 | %figure 135 | %plot(w_se(1,:)) 136 | %hold on 137 | %plot(w_se(2,:)) 138 | % 139 | %figure 140 | %plot(w_sr(1,:)) 141 | %hold on 142 | %plot(w_sr(2,:)) 143 | % 144 | %figure 145 | %plot(w_ss(1,:)) 146 | %hold on 147 | %plot(w_ss(2,:)) 148 | 149 | 150 | %figure 151 | %plot(w_nlms(1,:)) 152 | %hold on 153 | %plot(w_nlms(2,:)) 154 | %xlabel('Iteration times') 155 | 156 | 157 | %% AR power spectrum 158 | u=u(3:end); 159 | for m=0:L-1 160 | r_n(m+1)=sum(conj(u(1:L-m)).*u(m+1:L))/L; 161 | end 162 | J_min=r_n(1)-r_n(2:3)*w(:,end); 163 | a=[1 -w(:,end)']; 164 | omg=2*pi*(-0.5:0.01:0.5); 165 | for ww=1:size(omg,2) 166 | S_AR(ww)=J_min/abs(a*exp(-j*(0:2)*omg(ww))'); 167 | end 168 | figure 169 | plot(omg/2/pi,S_AR) 170 | xlabel('\omega /2 pi') 171 | ylabel('S_{AR}') 172 | a1=0.975; 173 | a2=-0.95; 174 | (1-a2)/(1+a2)*(0.0731/((1-a2)^2-a1^2)) -------------------------------------------------------------------------------- /Modern Digital Signal Processing/Unclassified/some task/chapter5/M=16 tri.fig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/Modern Digital Signal Processing/Unclassified/some task/chapter5/M=16 tri.fig -------------------------------------------------------------------------------- /Modern Digital Signal Processing/Unclassified/some task/chapter5/M=16.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/Modern Digital Signal Processing/Unclassified/some task/chapter5/M=16.mat -------------------------------------------------------------------------------- /Modern Digital Signal Processing/Unclassified/some task/chapter5/M=5 tri.fig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/Modern Digital Signal Processing/Unclassified/some task/chapter5/M=5 tri.fig -------------------------------------------------------------------------------- /Modern Digital Signal Processing/Unclassified/some task/chapter5/M=5.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/Modern Digital Signal Processing/Unclassified/some task/chapter5/M=5.mat -------------------------------------------------------------------------------- /Modern Digital Signal Processing/Unclassified/some task/chapter5/MSE,M=16.fig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/Modern Digital Signal Processing/Unclassified/some task/chapter5/MSE,M=16.fig -------------------------------------------------------------------------------- /Modern Digital Signal Processing/Unclassified/some task/chapter5/MSE,M=5.fig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/Modern Digital Signal Processing/Unclassified/some task/chapter5/MSE,M=5.fig -------------------------------------------------------------------------------- /Modern Digital Signal Processing/Unclassified/some task/chapter5/adaptive_equalization_page191.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/Modern Digital Signal Processing/Unclassified/some task/chapter5/adaptive_equalization_page191.m -------------------------------------------------------------------------------- /Modern Digital Signal Processing/Unclassified/some task/chapter5/chapter5-computer simulations.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/Modern Digital Signal Processing/Unclassified/some task/chapter5/chapter5-computer simulations.pdf -------------------------------------------------------------------------------- /Modern Digital Signal Processing/Unclassified/some task/chapter5/chapter5_2.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/Modern Digital Signal Processing/Unclassified/some task/chapter5/chapter5_2.m -------------------------------------------------------------------------------- /Modern Digital Signal Processing/Unclassified/some task/chapter5/chapter5_3.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/Modern Digital Signal Processing/Unclassified/some task/chapter5/chapter5_3.m -------------------------------------------------------------------------------- /Modern Digital Signal Processing/Unclassified/some task/chapter6/2.fig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/Modern Digital Signal Processing/Unclassified/some task/chapter6/2.fig -------------------------------------------------------------------------------- /Modern Digital Signal Processing/Unclassified/some task/chapter6/chapter6-computer simulations.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/Modern Digital Signal Processing/Unclassified/some task/chapter6/chapter6-computer simulations.pdf -------------------------------------------------------------------------------- /Modern Digital Signal Processing/Unclassified/some task/chapter6/chapter6_1_1.m: -------------------------------------------------------------------------------- 1 | clc 2 | clear all 3 | close all 4 | 5 | j=sqrt(-1); 6 | %% gen signal 7 | f=[0.15 0.25 0.30]'; 8 | N=100; %length of signal 9 | M=6; % filter order 10 | SNR=[20 25 30]'; 11 | sigma_v=1; %noise power 12 | test_N=100; 13 | for test=1:test_N 14 | v_n=sqrt(sigma_v/2)*randn(1,N)+j*sqrt(sigma_v/2)*randn(1,N);% complex gauss noise 15 | a_k=sqrt(10.^(SNR/10)*sigma_v);%ampltitude of envelope 16 | 17 | n=(0:N-1); 18 | phi_k=2*pi*rand(1,3)'; 19 | s_k=a_k.*exp(j*2*pi*f*n+phi_k); 20 | u_n=sum(s_k)+v_n; 21 | u_n=u_n.'; 22 | 23 | %% SVD 24 | A=zeros(N-M+1,M); 25 | for ii=1:N-M+1 26 | A(ii,:)=u_n(M-1+ii:-1:ii)'; 27 | end 28 | [U,S,V]=svd(A); 29 | invphi=V*inv(S'*S)*V'; 30 | 31 | %% MVDR 32 | w_n=1000; 33 | w=2*pi*(-0.5:1/w_n:0.5); 34 | a=exp(-j*(0:M-1)'*w); 35 | 36 | for ww=1:length(w) 37 | P_mvdr(ww)=1/(a(:,ww)'*invphi*a(:,ww)); 38 | end 39 | P_mvdr=abs(P_mvdr/max(abs(P_mvdr))); 40 | 41 | [pks,locs]=findpeaks(P_mvdr); 42 | [a,b]=sort(pks); 43 | f_est=sort(w(locs(b(end:-1:end-2))))/(2*pi); 44 | err(test,:)=(f_est'-f).^2; 45 | end 46 | err=sum(err)/test_N; 47 | figure 48 | plot(w/(2*pi),10*log10(P_mvdr)); 49 | ylabel('normalized MVDR /dB') 50 | xlabel('\omega / 2\pi') 51 | title('P_{MVDR}') -------------------------------------------------------------------------------- /Modern Digital Signal Processing/Unclassified/some task/chapter6/chapter6_1_2.m: -------------------------------------------------------------------------------- 1 | clc 2 | clear all 3 | close all 4 | 5 | j=sqrt(-1); 6 | %% gen signal 7 | f=[0.15 0.25 0.30]'; 8 | N=500; %length of signal 9 | M=6; % filter order 10 | SNR=[20 25 30]'; 11 | sigma_v=1; %noise power 12 | test_N=500; 13 | w_test=0; 14 | xi_test=0; 15 | for test=1:test_N 16 | v_n=sqrt(sigma_v/2)*randn(1,N)+j*sqrt(sigma_v/2)*randn(1,N);% complex gauss noise 17 | a_k=sqrt(10.^(SNR/10)*sigma_v);%ampltitude of envelope 18 | 19 | n=(0:N-1); 20 | phi_k=2*pi*rand(1,3)'; 21 | s_k=a_k.*exp(j*(2*pi*f*n+phi_k)); 22 | u_n=sum(s_k)+v_n; 23 | u_n=u_n.'; 24 | 25 | %% Observation Matrix 26 | A=zeros(N,M); 27 | u_n=[zeros(M-1,1);u_n]; 28 | for mm=1:M 29 | A(:,mm)=u_n(M+1-mm:1:N+M-mm)'; 30 | end 31 | 32 | %% RLS 33 | lambda=0.95; 34 | delta=0.05; 35 | I=diag(ones(1,M)); 36 | P=1/delta*I; 37 | w_est=zeros(M,N); 38 | d=u_n(M+1:end); 39 | xi=zeros(1,N-2); 40 | for nn=2:N-1 41 | k=1/lambda * P *A(nn,:)'/ ( 1+1/lambda*A(nn,:)*P*A(nn,:)' ); 42 | xi(nn)=d(nn)-w_est(:,nn-1)'*A(nn,:)'; 43 | w_est(:,nn)=w_est(:,nn-1)+k*conj(xi(nn)); 44 | P=1/lambda*P-1/lambda*k*A(nn,:)*P; 45 | end 46 | w_test=w_test+w_est; 47 | 48 | xi_test=xi_test+xi; 49 | 50 | end 51 | w_test=w_test/test_N; 52 | xi_test=xi_test/test_N; 53 | w_n=1000; 54 | w=2*pi*(-0.5:1/w_n:0.5); 55 | aw=exp(-j*(1:M)'*w); 56 | for ii=1:N-10 57 | sigma=abs(xi_test(ii+1)).^2; 58 | a_k=-conj(w_test(:,ii+1)); 59 | for ww=1:length(w) 60 | S_AR(ww)=sigma/(1+a_k.'*aw(:,ww))^2; 61 | end 62 | S_AR=abs(S_AR); 63 | [pks,locs]=findpeaks(S_AR); 64 | if(size(locs,2)>=3) 65 | [a,b]=sort(pks); 66 | f_est=sort(w(locs(b(end:-1:end-2))))/(2*pi); 67 | err(:,ii)=(f_est'-sort(f)).^2; 68 | else 69 | f_est=[0.5 0.5 0.5]; 70 | err(:,ii)=(f_est'-sort(f)).^2; 71 | end 72 | end 73 | figure 74 | plot(10*log10(abs(xi_test).^2)) 75 | 76 | figure 77 | subplot(3,1,1) 78 | plot(10*log10(err(1,:))) 79 | xlabel('Iteration times') 80 | ylabel('MSE') 81 | title('learning curve of signal 1 ') 82 | subplot(3,1,2) 83 | plot(10*log10(err(2,:))) 84 | xlabel('Iteration times') 85 | ylabel('MSE') 86 | title('learning curve of signal 2 ') 87 | subplot(3,1,3) 88 | plot(10*log10(err(3,:))) 89 | xlabel('Iteration times') 90 | ylabel('MSE') 91 | title('learning curve of signal 3 ') 92 | 93 | 94 | 95 | figure 96 | plot(w/(2*pi),10*log10(S_AR)) 97 | ylabel('normalized Power Spectrum /dB') 98 | xlabel('\omega / 2\pi') 99 | title('S_{AR}') 100 | 101 | figure 102 | semilogy((abs(xi_test).^2)) -------------------------------------------------------------------------------- /Modern Digital Signal Processing/Unclassified/some task/chapter6/chapter6_2.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/Modern Digital Signal Processing/Unclassified/some task/chapter6/chapter6_2.m -------------------------------------------------------------------------------- /Modern Digital Signal Processing/Unclassified/some task/chapter6/chapter6_3.m: -------------------------------------------------------------------------------- 1 | clc 2 | clear all 3 | close all 4 | j=sqrt(-1); 5 | 6 | L=200 ; %signal length 7 | sigma_v_2=0.0731; %noise power 8 | 9 | test_N=100; 10 | w_test=0; 11 | xi_test=0; 12 | for test=1:test_N 13 | v=sqrt(sigma_v_2)*randn(1,L); 14 | b=1; 15 | a=[1 -0.975 0.95]; 16 | w_theory=-conj(a(2:end)).'; 17 | %a=[1 0.99]; 18 | z=filtic(b,a,[0 0]); 19 | u=filter(b,a,v,z); 20 | 21 | %% 22 | n0=1; %n0 Step Linear Prediction 23 | M=2; 24 | d=u(n0+1:end); %Expectations correspond 25 | u1=[zeros(1,M-1) u]; 26 | A=zeros(L,M); 27 | for k=1:L 28 | A(k,:)=u1(M-1+k:-1:k); 29 | end 30 | 31 | 32 | %% RLS 33 | delta=0.004; 34 | lambda=0.99; 35 | w_est=zeros(M,L-n0); 36 | xi=zeros(L,1); 37 | P=1/delta*eye(M); 38 | for nn=1:L-n0 39 | k=1/lambda * P *A(nn,:)'/ ( 1+1/lambda*A(nn,:)*P*A(nn,:)' ); 40 | xi(nn)=d(nn)-w_est(:,nn)'*A(nn,:)'; 41 | w_est(:,nn+1)=w_est(:,nn)+k*conj(xi(nn)); 42 | P=1/lambda*P-1/lambda*k*A(nn,:)*P; 43 | end 44 | w_test=w_test+w_est; 45 | w_err=abs(w_est-w_theory); 46 | xi_test=xi_test+abs(xi); 47 | end 48 | w_test=w_test/test_N; 49 | w_err=w_err/test_N; 50 | w_err=w_err.^2; 51 | xi_test=xi_test/test_N; 52 | w_test(:,end) 53 | figure 54 | plot(w_test(1,:)) 55 | hold on 56 | plot(w_test(2,:)) 57 | title('100 times average learning curve ') 58 | legend('w1', 'w2'); 59 | xlabel('Iteration times') 60 | ylabel('Weight') 61 | 62 | figure 63 | plot(w_est(1,:)) 64 | hold on 65 | plot(w_est(2,:)) 66 | legend('typical w1', 'typical w2'); 67 | title('Typical learning curve') 68 | xlabel('Iteration times') 69 | ylabel('Weight') 70 | 71 | figure 72 | MSE=xi_test.^2; 73 | semilogy(MSE) 74 | title('RLS learning curve') 75 | xlabel('Iteration times') 76 | 77 | figure 78 | semilogy(w_err(1,:)) 79 | hold on 80 | semilogy(w_err(2,:)) 81 | -------------------------------------------------------------------------------- /Modern Digital Signal Processing/Unclassified/some task/chapter6/untitled.fig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/Modern Digital Signal Processing/Unclassified/some task/chapter6/untitled.fig -------------------------------------------------------------------------------- /Modern Digital Signal Processing/Unclassified/some task/chapter7/chapter7-computer simulations.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/Modern Digital Signal Processing/Unclassified/some task/chapter7/chapter7-computer simulations.pdf -------------------------------------------------------------------------------- /Modern Digital Signal Processing/Unclassified/some task/chapter7/chapter7_1.m: -------------------------------------------------------------------------------- 1 | clc 2 | clear all 3 | close all 4 | 5 | %% parameter 6 | M=2; 7 | L=2000; 8 | b=1; 9 | a=[1 -0.975 0.95]; 10 | w_theory=-conj(a(2:end)).'; 11 | sigma_v_2=0.0731; 12 | test_N=100; 13 | x_test=0; 14 | err_test=0; 15 | for test=1:test_N 16 | v=randn(1,L); 17 | z=filtic(b,a,[0 0]); 18 | u=filter(b,a,v,z); 19 | 20 | J_min=0.005; 21 | 22 | %% 23 | u1=[zeros(1,M-1) u]; 24 | U=zeros(M,L); 25 | for nn=1:L 26 | U(:,nn)=u1(M-1+nn:-1:nn); 27 | end 28 | w=zeros(1,M).'; 29 | 30 | %% kalman 31 | Q_2=J_min; 32 | P=eye(M); 33 | x_est=zeros(M,L); 34 | z=u(2:end); 35 | for nn=1:L-1 36 | C=U(:,nn).'; 37 | A=C*P*C'+Q_2; 38 | K=P*C'*inv(A); 39 | alpha(nn)=z(nn)-C*x_est(:,nn); 40 | x_est(:,nn+1)=x_est(:,nn)+K*alpha(nn); 41 | P=(eye(M)-K*C)*P; 42 | 43 | end 44 | err=abs(x_est-w_theory); 45 | %err=abs(alpha); 46 | x_test=x_test+x_est; 47 | err_test=err_test+err; 48 | end 49 | x_test=x_test/test_N; 50 | err_test=err_test/test_N; 51 | err_test=err_test.^2; 52 | x_test(:,end) 53 | figure 54 | plot(x_test(1,:)) 55 | hold on 56 | plot(x_test(2,:)) 57 | ylabel('Weight') 58 | xlabel('Iteration times') 59 | legend('w1', 'w2') 60 | title('Kalman learning curve') 61 | 62 | figure 63 | semilogy(err_test(1,:)) 64 | hold on 65 | semilogy(err_test(2,:)) 66 | ylabel('MSE') 67 | xlabel('Iteration times') 68 | legend('w1', 'w2') 69 | title('Kalman learning curve') 70 | -------------------------------------------------------------------------------- /Modern Digital Signal Processing/Unclassified/some task/chapter8/chapter8-computer simulations.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/Modern Digital Signal Processing/Unclassified/some task/chapter8/chapter8-computer simulations.pdf -------------------------------------------------------------------------------- /Modern Digital Signal Processing/Unclassified/some task/chapter8/chapter8_1.m: -------------------------------------------------------------------------------- 1 | % problem : how to compute MSE, 2 | clc 3 | clear all 4 | close all 5 | 6 | %%parameter 7 | j=sqrt(-1); 8 | M=16; %Number of elements 9 | K=2; %number of source 10 | d=0.5; % lambda/2 11 | theta=[-20 30]*pi/180; %DOA 12 | SNR_theta=[10 30]; 13 | L=128; %number of snapshot 14 | 15 | 16 | %% N test 17 | test_N=100; 18 | for test=1:test_N 19 | %% gen signal 20 | S=10.^(SNR_theta/20)'.*exp(j*2*pi*rand(K,L)); 21 | A=exp(-j*(0:M-1)'.*2*pi*d*sin(theta)); 22 | N=randn(M,L)+randn(M,L)*j; %gauss noise 23 | X=A*S+N; 24 | 25 | %% MUSIC 26 | R=X*X'/L; 27 | [V,D]=eig(R); 28 | [B,I] = sort(diag(D)); 29 | G=V(:,I(1:end-K)); 30 | 31 | %theta_range=(-90:0.1:90)*pi/180; 32 | theta_range=(-pi/2:pi/1000:pi/2); 33 | for tt=1:length(theta_range) 34 | a=exp(-j*2*pi*d*[0:M-1]'*sin(theta_range(tt))); 35 | P_MUSIC(tt)=1./(a'*(G*G')*a); 36 | end 37 | P_MUSIC=abs(P_MUSIC/max(abs(P_MUSIC))); 38 | P_MUSIC=10*log10(P_MUSIC); 39 | [pks,locs]=findpeaks(P_MUSIC); 40 | [a,b]=sort(pks); 41 | theta_est=theta_range(locs(b(end-K+1:end))); 42 | theta_est=sort(theta_est); 43 | err(:,tt)=theta_est-sort(theta); 44 | end 45 | MSE=mean(err.^2,2); 46 | 47 | figure 48 | plot(theta_range/pi*180,P_MUSIC) 49 | title('P_{MUSIC}') 50 | xlabel('\theta / \circ') 51 | ylabel('Normalized spatial spectrum /dB') -------------------------------------------------------------------------------- /Modern Digital Signal Processing/Unclassified/some task/chapter8/chapter8_2.m: -------------------------------------------------------------------------------- 1 | clc 2 | clear all 3 | close all 4 | 5 | %% parameter 6 | j=sqrt(-1); 7 | M=16; %Number of elements 8 | K=2; %number of source 9 | d=0.5; % lambda/2 10 | theta=[-20 30]*pi/180; %DOA 11 | SNR_theta=[0 0]; 12 | L=128; %number of snapshot 13 | 14 | 15 | %% N test 16 | test_N=100; 17 | for test=1:test_N 18 | %% gen signal 19 | S=10.^(SNR_theta/10)'.*exp(j*2*pi*rand(K,L)); 20 | A=exp(-j*(0:M-1)'.*2*pi*d*sin(theta)); 21 | N=randn(M,L)+randn(M,L)*j; %gauss noise 22 | X=A*S+N; 23 | 24 | %% TLS-ESPRIT 25 | R=X*X'/L; 26 | [V,D]=eigs(R); 27 | [B,I] = sort(diag(D)); 28 | G=V(:,I(end-K+1:end)); 29 | S1=G(1:M-1,:); 30 | S2=G(2:M,:); 31 | S12=[S1 S2]; 32 | [V,~]=eigs(S12'*S12); % eigs ,not eig 33 | U12=V(1:K,K+1:end); 34 | U22=V(K+1:end,K+1:end); 35 | phi_TLS=-U12*inv(U22); 36 | % phi_TLS=S1\S2; % ESPRIT 37 | [V,D]=eigs(phi_TLS); 38 | e_jphi=diag(D); 39 | theta_est= asin(-angle(e_jphi)/(d*2*pi))/pi*180; 40 | theta_est=sort(theta_est); 41 | err(:,test)=abs(theta_est-(theta/pi*180).'); 42 | end 43 | MSE=mean(mean(err.^2)); 44 | -------------------------------------------------------------------------------- /Modern Digital Signal Processing/Unclassified/some task/chapter8/chapter8_3.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/Modern Digital Signal Processing/Unclassified/some task/chapter8/chapter8_3.m -------------------------------------------------------------------------------- /Modern Digital Signal Processing/Unclassified/some task/chapter8/page337_8_20.m: -------------------------------------------------------------------------------- 1 | clc 2 | clear 3 | close all 4 | 5 | %% parameter 6 | j=sqrt(-1); 7 | M=8; %Number of elements 8 | K=2; %number of source 9 | d=0.5; % lambda/2 10 | theta=[0 30]*pi/180; %DOA 11 | kk=1; %Signals of interest 12 | SNR_theta=[20 20]; 13 | L=1024; %number of snapshot 14 | 15 | %% 16 | S=10.^(SNR_theta/20)'.*exp(j*2*pi*rand(K,L)); 17 | A=exp(-j*(0:M-1)'.*2*pi*d*sin(theta)); 18 | N=randn(M,L)+randn(M,L)*j; %gauss noise 19 | X=A*S+N; 20 | 21 | %% beam-space MUSIC 22 | B=M; 23 | m=0; 24 | W=exp(-j*pi*(0:M-1).'.*(0:M-1)*2/M); 25 | T=1/sqrt(M) *W(:,m+1:m+B); 26 | Y=T'*X; 27 | 28 | Ry_hat=Y*Y'/L; 29 | [V,D]=eig(Ry_hat); 30 | [aa,bb]=sort(diag(D)); 31 | G=V(:,bb(M-K:-1:M-B+1)); 32 | theta_range=(-90:0.1:90)*pi/180; 33 | for tt=1:length(theta_range) 34 | a=exp(-j*2*pi*d*(0:M-1).'.*sin(theta_range(tt))); 35 | a=T'*a; 36 | P_BS_MUSIC(tt)=1/(a'*G*G'*a); 37 | end 38 | P_BS_MUSIC=10*log10(abs(P_BS_MUSIC)); 39 | figure 40 | plot(theta_range/pi*180,P_BS_MUSIC); 41 | title('P_{BS-MUSIC}') 42 | xlabel('\theta / \circ') 43 | ylabel('Normalized spatial spectrum /dB') -------------------------------------------------------------------------------- /Modern Digital Signal Processing/现代信号处理.xmind: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/Modern Digital Signal Processing/现代信号处理.xmind -------------------------------------------------------------------------------- /Modulated signal/Basic/AM.m: -------------------------------------------------------------------------------- 1 | %Generating AM signal 2 | clc 3 | clear all; 4 | close all; 5 | %use orthogonal modulation generate modulated siganl 6 | %You can see the original signal v in the code. 7 | fc=1e4; %carrier frequency 8 | fs=1e5; %sample frequency 9 | T=1/fs; %sample time 10 | L=10000; %length of signal 11 | t=(0:L-1)*T; %time vector 12 | A=1; %%Ampltitude 13 | v=A*cos(2*pi*1000*t); %modulation signal 14 | xs=sin(2*pi*fc*t); 15 | xc=cos(2*pi*fc*t); 16 | 17 | %AM 18 | m_a=0.3; %modulation index,|m_a|<1 19 | I_AM=A+m_a*v; 20 | Q_AM=0; 21 | y_AM=I_AM.*xc+Q_AM.*xs; 22 | figure(1) 23 | plot(y_AM) 24 | title('m_a=0.3'); 25 | figure(2) 26 | plotSpectral(y_AM,fs) 27 | 28 | m_a=0.5; 29 | I_AM=A+m_a*v; 30 | Q_AM=0; 31 | y_AM=I_AM.*xc+Q_AM.*xs; 32 | figure(3) 33 | plot(y_AM) 34 | title('m_a=0.5'); 35 | 36 | m_a=0.7; 37 | I_AM=A+m_a*v; 38 | Q_AM=0; 39 | y_AM=I_AM.*xc+Q_AM.*xs; 40 | figure(4) 41 | plot(y_AM) 42 | title('m_a=1'); 43 | 44 | ff=(-L/2:L/2-1)*(fs/L); 45 | f_offset=0.001*fc 46 | [I,Q]=DDC_filter(fs,fc+f_offset,4000,10,y_AM); 47 | figure 48 | subplot(2,1,1) 49 | plot(I) 50 | subplot(2,1,2) 51 | plot(Q) 52 | IQ=I+Q*j; 53 | figure 54 | subplot(2,1,1) 55 | plot(abs(IQ)) 56 | subplot(2,1,2) 57 | plot(angle(IQ)./pi*180) 58 | figure 59 | plot(ff,abs(fftshift(fft(IQ)))) 60 | IQ_adjust=IQ.*exp(-j*2*pi*f_offset*t); 61 | hold on 62 | plot(ff,abs(fftshift(fft(IQ_adjust)))) 63 | legend('IQ','IQ_adjust') 64 | figure 65 | subplot(2,1,1) 66 | plot(real(IQ_adjust)) 67 | subplot(2,1,2) 68 | plot(imag(IQ_adjust)) 69 | 70 | figure 71 | subplot(2,1,1) 72 | plot(abs(IQ_adjust)) 73 | subplot(2,1,2) 74 | plot(angle(IQ_adjust)./pi*180) 75 | -------------------------------------------------------------------------------- /Modulated signal/Basic/ASK2.m: -------------------------------------------------------------------------------- 1 | %Generating 2ASK signal 2 | clc 3 | clear all; 4 | close all; 5 | %use orthogonal modulation generate modulated siganl 6 | %You can see the original signal v in the code. 7 | fc=1e4; %carrier frequency 8 | fs=1e5; %sample frequency 9 | Rs=1e3; %symbol rate of digital signal 10 | T=1/fs; %sample time 11 | L=10000; %length of signal 12 | t=(0:L-1)*T; %time vector 13 | A=1; %%Ampltitude 14 | v=A*cos(2*pi*1000*t); %modulation signal 15 | xs=sin(2*pi*fc*t); 16 | xc=cos(2*pi*fc*t); 17 | 18 | %2ASK 19 | % _________ ______ 20 | % signal | | | | 21 | %----------| |________| | so L/fs/T_ask is the length of a_n 22 | % <-T_ask-> 23 | %<-----------L points ---------------> 24 | T_ask=1/Rs; 25 | a_n=round(rand(1,round(L/(T_ask*fs)))); 26 | a_ask=repmat(a_n,T_ask*fs,1); 27 | a_ask=a_ask(:)'; 28 | %stairs(a_ask) %figure 2ask,unuse plot 29 | I_ask=0; 30 | Q_ask=a_ask; 31 | y_2ask=I_ask.*xc+Q_ask.*xs; 32 | figure(1) 33 | plot(y_2ask);title('y_ask') 34 | figure(2) 35 | plotSpectral(y_2ask,fs) 36 | 37 | y_2ask=awgn(y_2ask,10,'measured'); 38 | 39 | ff=(-L/2:L/2-1)*(fs/L); 40 | f_offset=0.001*fc 41 | [I,Q]=DDC_filter(fs,fc+f_offset,4000,15,y_2ask); 42 | figure 43 | subplot(2,1,1) 44 | plot(I);title('DDC I') 45 | subplot(2,1,2) 46 | plot(Q);title('DDC Q') 47 | IQ=I+Q*j; 48 | figure 49 | subplot(2,1,1) 50 | plot(abs(IQ));title('abs(IQ)') 51 | subplot(2,1,2) 52 | plot(angle(IQ)./pi*180);title('angle DDC IQ') 53 | figure 54 | Y=abs(fftshift(fft(IQ))); 55 | plot(ff,Y);title('spectrum of DDC IQ') 56 | 57 | %% 58 | % 59 | IQ_adjust=IQ.*exp(j*2*pi*f_offset*t); 60 | hold on 61 | Y_adjust=abs(fftshift(fft(IQ_adjust))); 62 | plot(ff,Y_adjust);title('Y_adjust') 63 | f_adjust=ff(find(Y_adjust==max(Y_adjust))) 64 | legend('IQ','IQ_adjust') 65 | figure 66 | subplot(2,1,1) 67 | plot(real(IQ_adjust));title('I Y_adjust') 68 | subplot(2,1,2) 69 | plot(imag(IQ_adjust));title('Q Y_adjust') 70 | 71 | figure 72 | subplot(2,1,1) 73 | plot(abs(IQ_adjust));title('abs IQ adjust') 74 | subplot(2,1,2) 75 | plot(angle(IQ_adjust)./pi*180);title('ansgle IQ adjust') -------------------------------------------------------------------------------- /Modulated signal/Basic/DDC_filter.m: -------------------------------------------------------------------------------- 1 | function [I,Q]=DDC_filter(fs,fc,fpass,f_order,in) 2 | len=size(in,2); 3 | t=(0:len-1)/fs; 4 | NCO_I=cos(2*pi*fc*t); 5 | NCO_Q=-sin(2*pi*fc*t); 6 | y_i=NCO_I.*in; 7 | y_q=NCO_Q.*in; 8 | [b,a] = butter(f_order,2*fpass/fs,'low'); 9 | figure 10 | freqz(b,a) 11 | I = filter(b,a,y_i); 12 | Q = filter(b,a,y_q); 13 | end -------------------------------------------------------------------------------- /Modulated signal/Basic/DPSK2.m: -------------------------------------------------------------------------------- 1 | %Generating 2DPSK signal 2 | clc 3 | clear all; 4 | close all; 5 | %use orthogonal modulation generate modulated siganl 6 | %You can see the original signal v in the code. 7 | fc=1e4; %carrier frequency 8 | fs=1e5; %sample frequency 9 | Rs=2e3; %symbol rate of digital signal 10 | T=1/fs; %sample time 11 | L=500; %length of signal 12 | t=(0:L-1)*T; %time vector 13 | A=1; %%Ampltitude 14 | v=A*cos(2*pi*1000*t); %modulation signal 15 | xs=sin(2*pi*fc*t); 16 | xc=cos(2*pi*fc*t); 17 | 18 | T_dpsk=1/Rs; 19 | a_n=round(rand(1,round(L/(T_dpsk*fs)))); 20 | %2psk to 2dpsk 21 | for i=2:length(a_n) 22 | if a_n(i)==1 23 | a_n(i)=abs(a_n(i-1)-1); %if a_n=1 then 0->1,1->0 24 | else 25 | a_n(i)=a_n(i-1); 26 | end 27 | end 28 | a_n=2*(a_n>0)-1; %turn 0 of a_n to -1 29 | a_dpsk=repmat(a_n,T_dpsk*fs,1); 30 | a_dpsk=a_dpsk(:)'; 31 | %stairs(a_dpsk) 32 | I_dpsk=a_dpsk; 33 | Q_dpsk=0; 34 | y_2dpsk=I_dpsk.*xc+Q_dpsk.*xs; 35 | figure(1) 36 | plot(y_2dpsk) 37 | 38 | figure(2) 39 | plotSpectral(y_2dpsk,fs) 40 | -------------------------------------------------------------------------------- /Modulated signal/Basic/DSB.m: -------------------------------------------------------------------------------- 1 | %Generating DSB signal 2 | clc 3 | clear all; 4 | close all; 5 | %use orthogonal modulation generate modulated siganl 6 | %You can see the original signal v in the code. 7 | fc=1e4; %carrier frequency 8 | fs=1e5; %sample frequency 9 | T=1/fs; %sample time 10 | L=200; %length of signal 11 | t=(0:L-1)*T; %time vector 12 | A=1; %%Ampltitude 13 | v=A*cos(2*pi*1000*t); %modulation signal 14 | xs=sin(2*pi*fc*t); 15 | xc=cos(2*pi*fc*t); 16 | 17 | %FM 18 | I_DSB=v; 19 | Q_DSB=0; 20 | y_DSB=I_DSB.*xc+Q_DSB.*xs; 21 | figure(1) 22 | plot(y_DSB) 23 | title('DSB'); 24 | figure(2) 25 | plotSpectral(y_DSB,fs) 26 | -------------------------------------------------------------------------------- /Modulated signal/Basic/FM.m: -------------------------------------------------------------------------------- 1 | %Generating FM signal 2 | clc 3 | clear all; 4 | close all; 5 | %use orthogonal modulation generate modulated siganl 6 | %You can see the original signal v in the code. 7 | fc=1e4; %carrier frequency 8 | fs=1e5; %sample frequency 9 | T=1/fs; %sample time 10 | L=500; %length of signal 11 | t=(0:L-1)*T; %time vector 12 | A=1; %%Ampltitude 13 | v=A*cos(2*pi*1000*t); %modulation signal 14 | xs=sin(2*pi*fc*t); 15 | xc=cos(2*pi*fc*t); 16 | 17 | %FM 18 | K_omega=0.5; %freq offet index 19 | phi_fm=zeros(1,length(v)); 20 | for n=3:length(v) 21 | phi_fm(n)=K_omega/(2)*(v(1)+v(n)+2*sum(v(2:n-1))); 22 | end 23 | y_fm=cos(2*pi*fc.*t+phi_fm); 24 | figure(1) 25 | plot(y_fm) 26 | title('K_omega=0.3'); 27 | figure(2) 28 | plotSpectral(y_fm,fs) 29 | -------------------------------------------------------------------------------- /Modulated signal/Basic/FSK2.m: -------------------------------------------------------------------------------- 1 | %Generating FM signal 2 | clc 3 | clear all; 4 | close all; 5 | %use orthogonal modulation generate modulated siganl 6 | %You can see the original signal v in the code. 7 | fc=1e4; %carrier frequency 8 | fs=1e5; %sample frequency 9 | Rs=5e3; %symbol rate of digital signal 10 | T=1/fs; %sample time 11 | L=1000; %length of signal 12 | t=(0:L-1)*T; %time vector 13 | A=1; %%Ampltitude 14 | v=A*cos(2*pi*1000*t); %modulation signal 15 | xs=sin(2*pi*fc*t); 16 | xc=cos(2*pi*fc*t); 17 | 18 | fc1=1.1e4; %|fc1-fc|Rs 20 | xs1=sin(2*pi*fc1*t); 21 | xc1=cos(2*pi*fc1*t); 22 | T_fsk=1/Rs; 23 | a_n=round(rand(1,round(L/(T_fsk*fs)))); 24 | a_fsk1=repmat(a_n,T_fsk*fs,1); 25 | a_fsk1=a_fsk1(:)'; 26 | a_fsk2=a_fsk1<1; %0->1,1->0 27 | %stairs(a_fsk1) 28 | I_fsk1=0; 29 | Q_fsk1=a_fsk1; 30 | I_fsk2=0; 31 | Q_fsk2=a_fsk2; 32 | y_fsk=I_fsk1.*xc+Q_fsk1.*xs+I_fsk2.*xc1+Q_fsk2.*xs1; %equal to add two ask 33 | figure(1) 34 | plot(y_fsk) 35 | figure(2) 36 | plotSpectral(y_fsk,fs) 37 | -------------------------------------------------------------------------------- /Modulated signal/Basic/GMSK/GMSK.m: -------------------------------------------------------------------------------- 1 | %% Gaussian Filtered Minimum Shift keying-GMSK 2 | 3 | clc 4 | clear 5 | close all 6 | 7 | Rs=1e3; %bit ratio 8 | Ts=1/Rs; 9 | N=10; %Number of bits to process 10 | fc=40e2; %carrier frequency 11 | fs=10e4; %sample frequency 12 | T=1/fs; 13 | t=(0:(round(N*Ts/T)-1))*T; 14 | ts=(0:N-1)*Ts; 15 | r=round(Ts/T); 16 | 17 | %% Orthogonal carrier wave 18 | xc=cos(2*pi*fc*t); 19 | xs=sin(2*pi*fc*t); 20 | 21 | %% Gaussian Filter 22 | %BTs=100000; 23 | BTs=0.3; 24 | B=BTs/Ts; 25 | 26 | 27 | %alpha=sqrt(log(2)/2)/B; 28 | %h=sqrt(pi)/alpha*exp(-(pi/alpha*t).^2); 29 | 30 | 31 | %I couldn't do it with h convolution, and then I used qunc function. 32 | g_t=qfunc(2*pi*B*(t-Ts/2-4.5*Ts)/sqrt(log(2)))-qfunc(2*pi*B*(t+Ts/2-4.5*Ts)/sqrt(log(2)));%4,5Ts is used to display all g_t 33 | figure 34 | plot(t/Ts,g_t) 35 | title('Rectangular impulse response of Gauss filter') 36 | legend('BT=0.3') 37 | xlabel('t/Tb') 38 | ylabel('g(t)') 39 | grid on 40 | 41 | %% gengerate bit sequence 42 | a=2*(rand(1,N)>0.5)-1; 43 | a=[1,1,-1,1,-1,-1,1,1,-1,1] %%test signal 44 | %a=[1,1,1,-1,-1,1,1,1,-1,-1,-1,-1,-1,-1,-1] 45 | %a=[1,1,1,-1,-1,1,1,1,-1,-1] 46 | a_sample=repmat(a,r,1); 47 | a_sample=a_sample(:)'; 48 | 49 | figure 50 | plot(t/Ts,a_sample) 51 | xlabel('t/Tb') 52 | ylabel('a(t)') 53 | grid on 54 | %% conv 55 | a_fil=conv(a_sample,g_t)/r;%I can't explain it here./r,It seems right. 56 | a_fil=a_fil(round(4.5*Ts/T):end);%Make up for the delays(4.5Ts) previously used 57 | figure 58 | plot((0:length(a_fil)-1)*T/Ts,a_fil) 59 | title('filtered signal') 60 | xlabel('t/Tb') 61 | 62 | 63 | %% additive phase 64 | for ii=1:length(t) 65 | theta(ii)=pi/(2*Ts)*T*trapz(a_fil(1:ii)); 66 | end 67 | figure 68 | %Although the trend is right, the peak value is getting smaller and I don't know what the problem is. 69 | plot(t/Ts,theta/pi); 70 | title('additive phase of GMSK') 71 | xlabel('t/Tb') 72 | ylabel('/\pi') 73 | 74 | theta1=wrapToPi(theta); 75 | figure 76 | 77 | plot(t/Ts,theta1/pi); 78 | title('additive phase of GMSK [0,2\pi]') 79 | xlabel('t/Tb') 80 | ylabel('/\pi') 81 | %% GMSK 82 | s=cos(theta).*xc-sin(theta).*xs; 83 | figure 84 | plot(t/Ts,s) 85 | title('GMSK') 86 | xlabel('t/Tb') 87 | %% Spectral 88 | figure 89 | plotSpectral(s,fs); -------------------------------------------------------------------------------- /Modulated signal/Basic/GMSK/g_t.m: -------------------------------------------------------------------------------- 1 | %impulse response 2 | clc 3 | clear 4 | 5 | 6 | Rs=1e3; %bit ratio 7 | Ts=1/Rs; 8 | N=10; %Number of bits to process 9 | fc=40e2; %carrier frequency 10 | fs=10e4; %sample frequency 11 | T=1/fs; 12 | t=(0:(round(N*Ts/T)-1))*T; 13 | ts=(0:N-1)*Ts; 14 | r=round(Ts/T); 15 | 16 | %% Gaussian Filter 17 | BTs=[0.1,0.3,0.5,1.0,10000]; 18 | B=BTs/Ts; 19 | 20 | %alpha=sqrt(log(2)/2)/B; 21 | %h=sqrt(pi)/alpha*exp(-(pi/alpha*t).^2); 22 | 23 | %I couldn't do it with h convolution, and then I used qunc function. 24 | gt=qfunc(2*pi*B'*(t-Ts/2-4.5*Ts)/sqrt(log(2)))-qfunc(2*pi*B'*(t+Ts/2-4.5*Ts)/sqrt(log(2)));%4,5Ts is used to display all g_t 25 | for ii =1:length(B) 26 | plot(t/Ts,gt(ii,:)) 27 | hold on 28 | end 29 | title('Rectangular impulse response of Gauss filter') 30 | legend('BT=0.1','BT=0.3','BT=0.5','BT=1.0','BT=10000') 31 | xlabel('t/Tb') 32 | ylabel('g(t)') 33 | grid on -------------------------------------------------------------------------------- /Modulated signal/Basic/GMSK/plotPowerSpectrum.m: -------------------------------------------------------------------------------- 1 | %plot Power Spectral 2 | %signal:row vector 3 | %fs:sample rate 4 | function [f,power_spectrum]=plotPowerSpectrum(signal,fs) 5 | NFFT = 2^nextpow2(size(signal,2)); 6 | Y=fft(signal,NFFT)/size(signal,2); 7 | Y_shift=fftshift(Y); 8 | f = fs/2*linspace(-1,1,NFFT) ; 9 | power_spectrum=2*abs(Y_shift).^2; 10 | plot(f,power_spectrum); 11 | xlabel('Hz'); 12 | end -------------------------------------------------------------------------------- /Modulated signal/Basic/GMSK/plotSpectral.m: -------------------------------------------------------------------------------- 1 | %plot Spectral 2 | %signal:row vector 3 | %fs:sample rate 4 | function [f,Y1]=plotSpectral(signal,fs) 5 | NFFT = 2^nextpow2(size(signal,2)); 6 | Y=fft(signal,NFFT)/size(signal,2); 7 | f = fs/2*linspace(0,1,NFFT/2+1) ; 8 | Y1=2*abs(Y(1:NFFT/2+1)); 9 | plot(f,Y1); 10 | xlabel('Hz'); 11 | end -------------------------------------------------------------------------------- /Modulated signal/Basic/ISB.m: -------------------------------------------------------------------------------- 1 | %Generating ISB signal 2 | clc 3 | clear all; 4 | close all; 5 | %use orthogonal modulation generate modulated siganl 6 | %You can see the original signal v in the code. 7 | fc=1e4; %carrier frequency 8 | fs=1e5; %sample frequency 9 | T=1/fs; %sample time 10 | L=500; %length of signal 11 | t=(0:L-1)*T; %time vector 12 | A=1; %%Ampltitude 13 | v=A*cos(2*pi*1000*t); %modulation signal 14 | xs=sin(2*pi*fc*t); 15 | xc=cos(2*pi*fc*t); 16 | 17 | 18 | %ISB(LSB and USB have different information) 19 | v_L=cos(2*pi*200*t); 20 | I_ISB=v+v_L; 21 | Q_ISB=imag(hilbert(v))-imag(hilbert(v_L)); 22 | y_ISB=I_ISB.*xc+Q_ISB.*xs; 23 | 24 | figure(1) 25 | plot(y_ISB) 26 | 27 | figure(2) 28 | plotSpectral(y_ISB,fs) 29 | -------------------------------------------------------------------------------- /Modulated signal/Basic/MASK.m: -------------------------------------------------------------------------------- 1 | %Generating MASK signal 2 | clc 3 | clear all; 4 | close all; 5 | %use orthogonal modulation generate modulated siganl 6 | %You can see the original signal v in the code. 7 | fc=1e4; %carrier frequency 8 | fs=1e5; %sample frequency 9 | Rs=2e3; %symbol rate of digital signal 10 | T=1/fs; %sample time 11 | L=1000; %length of signal 12 | t=(0:L-1)*T; %time vector 13 | A=1; %%Ampltitude 14 | v=A*cos(2*pi*1000*t); %modulation signal 15 | xs=sin(2*pi*fc*t); 16 | xc=cos(2*pi*fc*t); 17 | 18 | 19 | T_mask=1/Rs; 20 | M=4; %M-ary 21 | a_n=round((M-1)*rand(1,round(L/(T_mask*fs))))*(1/M); %region 0 to 1 by 1/M. 22 | a_mask=repmat(a_n,T_mask*fs,1); 23 | a_mask=a_mask(:)'; 24 | %stairs(a_mask) %figure mask,unuse plot 25 | I_mask=0; 26 | Q_mask=a_mask; 27 | y_mask=I_mask.*xc+Q_mask.*xs; 28 | 29 | figure(1) 30 | plot(y_mask) 31 | 32 | figure(2) 33 | plotSpectral(y_mask,fs) 34 | -------------------------------------------------------------------------------- /Modulated signal/Basic/MFSK.m: -------------------------------------------------------------------------------- 1 | %Generating FM signal 2 | clc 3 | clear all; 4 | close all; 5 | %use orthogonal modulation generate modulated siganl 6 | %You can see the original signal v in the code. 7 | fc=1e4; %carrier frequency 8 | fs=1e5; %sample frequency 9 | T=1/fs; %sample time 10 | Rs=2e3; %symbol rate of digital signal 11 | L=500; %length of signal 12 | t=(0:L-1)*T; %time vector 13 | A=1; %%Ampltitude 14 | v=A*cos(2*pi*1000*t); %modulation signal 15 | xs=sin(2*pi*fc*t); 16 | xc=cos(2*pi*fc*t); 17 | 18 | %FM 19 | M=4; 20 | fc_M=(1:M)*5e3; %M groups of carrier frequency 21 | xsM=sin(2*pi*fc_M'*t); 22 | xcM=cos(2*pi*fc_M'*t); 23 | T_MFSK=1/Rs; 24 | a_n=round((M-1)*rand(1,round(L/(T_MFSK*fs))))*(1/M); 25 | a_mfsk=repmat(a_n,T_MFSK*fs,1); 26 | a_mfsk=a_mfsk(:)'; 27 | %stairs(a_mfsk) 28 | a_mfsk_M=zeros(M,L); 29 | for i=1:M 30 | a_mfsk_M(i,:)=(a_mfsk==(i-1)/M); 31 | end 32 | I_mfsk=0; 33 | Q_mfsk=a_mfsk_M; 34 | y_MFSK=I_mfsk.*xcM+Q_mfsk.*xsM; 35 | y_MFSK=sum(y_MFSK,1); 36 | 37 | figure(1) 38 | plot(y_MFSK) 39 | 40 | figure(2) 41 | plotSpectral(y_MFSK,fs) 42 | -------------------------------------------------------------------------------- /Modulated signal/Basic/MSK/MSK.m: -------------------------------------------------------------------------------- 1 | %gen MSK by Quadrature 2 | %s_k(t)=p_k*cos(pi*t/(2*T_s))cos(w_c*t)-q_k*sin(pi*t/(2*T_s))sin(w_c*t) 3 | %(k-1)T_s0.5)-1; 20 | %a=[1,1,-1,1,-1,-1,1,1,-1,1] %%test signal 21 | %a=[1,1,1,-1,-1,1,1,1,-1,-1] 22 | a_sample=repmat(a,r,1); 23 | a_sample=a_sample(:)'; 24 | subplot(6,1,1) 25 | plot(a_sample) 26 | set(gca,'xticklabel',[]); 27 | set(gca,'position',[0.15 5.1/6 0.75 0.9/6]) 28 | axis([0 length(a_sample) -2 2]) 29 | ylabel('a(t)') 30 | %% Differential coding 31 | 32 | b=ones(1,N); 33 | b(1)=a(1); 34 | for jj=2:N 35 | if a(jj)==1 36 | b(jj)=b(jj-1); 37 | else 38 | b(jj)=-b(jj-1); 39 | end 40 | end 41 | 42 | b_sample=repmat(b,r,1); 43 | b_sample=b_sample(:)'; 44 | subplot(6,1,2); 45 | plot(b_sample) 46 | set(gca,'xticklabel',[]); 47 | set(gca,'position',[0.15 4.1/6 0.75 0.9/6]) 48 | axis([0 length(b_sample) -2 2]) 49 | ylabel('b(t)') 50 | 51 | %% serial to parallel conversion 52 | %b1b2b3b4b5b6b7b8=p1q2p3q4p5q6 53 | %b1=p1=p2,b2=q2=q3 54 | %p_k:p1p2p3p4p5p6p7=b1b1b3b3b5b5b7 55 | %q_k:q1q2q3q4q5q6q7q8=b0b2b2b4b4b6b6b8 56 | %At present, I don't know how to get the value of b0 p0 and q0 , 57 | %Suppose b0=a0,p0=cos(\phi_{0})=1,q0=b0 58 | b_odd=b(1:2:end); 59 | b_even=b(2:2:end); 60 | p=reshape([b_even;b_even],1,[]); 61 | p=[1,p(1:end-1)]; 62 | q=reshape([b_odd;b_odd],1,[]); 63 | 64 | %% plot p(t) 65 | p_sample=repmat(p,r,1); 66 | p_sample=p_sample(:)'; 67 | subplot(6,1,3); 68 | plot(p_sample) 69 | set(gca,'xticklabel',[]); 70 | set(gca,'position',[0.15 3.1/6 0.75 0.9/6]) 71 | axis([0 length(p_sample) -2 2]) 72 | ylabel('p(t)') 73 | %% plot q(t) 74 | q_sample=repmat(q,r,1); 75 | q_sample=q_sample(:)'; 76 | subplot(6,1,4); 77 | plot(q_sample); 78 | set(gca,'xticklabel',[]); 79 | set(gca,'position',[0.15 2.2/6 0.75 0.8/6]) 80 | axis([0 length(q_sample) -2 2]) 81 | ylabel('q(t)') 82 | 83 | %% plot p_sample.*cos(pi*t/(2*Ts)) 84 | subplot(6,1,5); 85 | plot(p_sample.*cos(pi*t/(2*Ts))); 86 | set(gca,'xticklabel',[]); 87 | set(gca,'position',[0.15 1.4/6 0.75 0.7/6]) 88 | axis([0 length(q_sample) -1 1]) 89 | ylabel('p*cos(\pi*t/(2*Ts)') 90 | 91 | %% plot q_sample.*sin(pi*t/(2*Ts)) 92 | subplot(6,1,6) 93 | plot(q_sample.*sin(pi*t/(2*Ts))) 94 | %set(gca,'xticklabel',[]); 95 | set(gca,'position',[0.15 1/12 0.75 0.8/6]) 96 | xlabel('time') 97 | ylabel('q*sin(\pi*t/(2*Ts)') 98 | 99 | %% s: MSK signal 100 | s=p_sample.*cos(pi*t/(2*Ts)).*xc-q_sample.*sin(pi*t/(2*Ts)).*xs; 101 | figure 102 | plot(s) 103 | title('MSK') 104 | figure 105 | plotSpectral(s,fs); 106 | 107 | %% plot additive phase 108 | %theta_k(t)=a_k*pi/(2*T_s)*t+phi 109 | phi=zeros(1,N); 110 | for jj=2:N 111 | phi(jj)=phi(jj-1)+(jj-1)*pi/2*(a(jj-1)-a(jj)); 112 | end 113 | %phi=mod(phi,2*pi) 114 | phi=repmat(phi,r,1); 115 | phi=phi(:)'; 116 | theta=(a_sample*pi)/(2*Ts).*t+phi; 117 | theta=wrapToPi(theta); 118 | plot(theta,'r') 119 | set(gca,'YTick',-pi:pi/2:pi) 120 | set(gca,'YTickLabel',{'-pi','-pi/2','0','pi/2','pi'}) 121 | ylabel('\theta_{k}(t)') 122 | xlabel('time') 123 | title('additive phase (mod 2\pi)') 124 | grid on 125 | 126 | -------------------------------------------------------------------------------- /Modulated signal/Basic/MSK/plotSpectral.m: -------------------------------------------------------------------------------- 1 | %plot Spectral 2 | %signal:row vector 3 | %fs:sample rate 4 | function [f,Y1]=plotSpectral(signal,fs) 5 | NFFT = 2^nextpow2(size(signal,2)); 6 | Y=fft(signal,NFFT)/size(signal,2); 7 | f = fs/2*linspace(0,1,NFFT/2+1) ; 8 | Y1=2*abs(Y(1:NFFT/2+1)); 9 | plot(f,Y1); 10 | xlabel('Hz'); 11 | end -------------------------------------------------------------------------------- /Modulated signal/Basic/OQPSK/OQPSK.m: -------------------------------------------------------------------------------- 1 | %OQPSK 2 | clc 3 | clear 4 | 5 | Rs=10e2; %bit ratio 6 | Ts=1/Rs; 7 | N=50; %Number of bits to process 8 | fc=20e2; %carrier frequency 9 | fs=10e4; %sample frequency 10 | T=1/fs; 11 | t=(0:(round(N*Ts/T)-1))*T; 12 | r=Ts/T; 13 | 14 | a=rand(1,N)>0.5; %bit symbol 15 | 16 | %% serial-to-paralle 17 | Idata=a(1:2:end); 18 | Idata=repmat(Idata,2,1); 19 | Idata=Idata(:)'; 20 | 21 | Qdata=a(2:2:end); 22 | Qdata=repmat(Qdata,2,1); 23 | Qdata=Qdata(:)'; 24 | 25 | %% Qdata delay one bit 26 | Qdata=[0,Qdata(1:end-1)]; 27 | 28 | %% Gray coded 29 | % 00->0->5pi/4 30 | % 01->1->7pi/4 31 | % 10->2->3pi/4 32 | % 11->3-> pi/4 33 | two_bits_decimal = [2,1]*[Qdata;Idata]; 34 | phase_code=pi*[5/4,7/4,3/4,1/4]; 35 | phi=phase_code(two_bits_decimal+1); 36 | %From here we can see that there is no phase jump of pi.only pi/2 37 | figure 38 | stem(abs(phi/pi-[phi(2:end),0]/pi)); 39 | title('phase jump') 40 | phi_sample=repmat(phi,r,1); 41 | phi_sample=phi_sample(:)'; 42 | 43 | %% constellation 44 | j=sqrt(-1); 45 | s=cos(phi)+sin(phi)*j; 46 | figure 47 | plot(s,'o') 48 | grid on;axis('equal',[-1.5 1.5 -1.5 1.5]); 49 | title('constellation map') 50 | figure 51 | plot(s) 52 | grid on;axis('equal',[-1.5 1.5 -1.5 1.5]); 53 | title('Phase change trajectory') 54 | 55 | %% carrier wave 56 | xc=cos(2*pi*fc*t); 57 | xs=sin(2*pi*fc*t); 58 | 59 | %% OQPSK 60 | A=1; %amplitude 61 | OQPSK_signal=A*(cos(phi_sample).*xc-sin(phi_sample).*xs); 62 | 63 | figure 64 | plotSpectral(OQPSK_signal,fs) 65 | 66 | 67 | -------------------------------------------------------------------------------- /Modulated signal/Basic/OQPSK/plotSpectral.m: -------------------------------------------------------------------------------- 1 | %plot Spectral 2 | %signal:row vector 3 | %fs:sample rate 4 | function plotSpectral(signal,fs) 5 | NFFT = 2^nextpow2(size(signal,2)); 6 | Y=fft(signal,NFFT)/size(signal,2); 7 | f = fs/2*linspace(0,1,NFFT/2+1) ; 8 | plot(f,2*abs(Y(1:NFFT/2+1))); 9 | xlabel('Hz'); 10 | end -------------------------------------------------------------------------------- /Modulated signal/Basic/PSK2.m: -------------------------------------------------------------------------------- 1 | %Generating FM signal 2 | clc 3 | clear all; 4 | close all; 5 | %use orthogonal modulation generate modulated siganl 6 | %You can see the original signal v in the code. 7 | fc=5e3; %carrier frequency 8 | fs=1e5; %sample frequency 9 | Rs=1e3; %symbol rate of digital signal 10 | T=1/fs; %sample time 11 | L=1000; %length of signal 12 | t=(0:L-1)*T; %time vector 13 | A=1; %%Ampltitude 14 | v=A*cos(2*pi*1000*t); %modulation signal 15 | xs=sin(2*pi*fc*t); 16 | xc=cos(2*pi*fc*t); 17 | 18 | T_psk=1/Rs; 19 | a_n=round(rand(1,round(L/(T_psk*fs)))); 20 | a_n=2*(a_n>0)-1; 21 | a_psk=repmat(a_n,T_psk*fs,1); 22 | a_psk=a_psk(:)'; 23 | %stairs(a_psk) 24 | I_psk=a_psk; 25 | Q_psk=0; 26 | y_2psk=I_psk.*xc+Q_psk.*xs; 27 | figure(1) 28 | plot(y_2psk) 29 | 30 | figure(2) 31 | plotSpectral(y_2psk,fs) 32 | -------------------------------------------------------------------------------- /Modulated signal/Basic/QAM/QAM.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/Modulated signal/Basic/QAM/QAM.m -------------------------------------------------------------------------------- /Modulated signal/Basic/QAM/QAM2.m: -------------------------------------------------------------------------------- 1 | %generate MQAM 2 | %code in matlab help file:Compute BER for a QAM System with AWGN Using MATLAB 3 | clc 4 | clear 5 | 6 | %% Setup 7 | % Define parameters. 8 | M = 16; % Size of signal constellation 9 | k = log2(M); % Number of bits per symbol 10 | n = 3e4; % Number of bits to process 11 | nsamp = 1; % Oversampling rate 12 | hMod = comm.RectangularQAMModulator(M); % Create a 16-QAM modulator 13 | 14 | %% Signal Source 15 | % Create a binary data stream as a column vector. 16 | x = randi([0 1],n,1); % Random binary data stream 17 | 18 | % Plot first 40 bits in a stem plot. 19 | stem(x(1:40),'filled'); 20 | title('Random Bits'); 21 | xlabel('Bit Index'); ylabel('Binary Value'); 22 | 23 | 24 | %% Bit-to-Symbol Mapping 25 | % Convert the bits in x into k-bit symbols. 26 | hBitToInt = comm.BitToInteger(k); 27 | 28 | 29 | xsym = step(hBitToInt,x); 30 | 31 | %% Stem Plot of Symbols 32 | % Plot first 10 symbols in a stem plot. 33 | figure; % Create new figure window. 34 | stem(xsym(1:10)); 35 | title('Random Symbols'); 36 | xlabel('Symbol Index'); ylabel('Integer Value'); 37 | 38 | %% Modulation 39 | y = modulate(modem.qammod(M),xsym); % Modulate using 16-QAM. 40 | 41 | 42 | %% Transmitted Signal 43 | ytx = y; 44 | 45 | %% Channel 46 | % Send signal over an AWGN channel. 47 | EbNo = 10; % In dB 48 | snr = EbNo + 10*log10(k) - 10*log10(nsamp); 49 | hChan = comm.AWGNChannel('NoiseMethod', 'Signal to noise ratio (SNR)', ... 50 | 'SNR',snr); 51 | hChan.SignalPower = (ytx' * ytx)/ length(ytx); 52 | ynoisy = step(hChan,ytx); 53 | 54 | %% Received Signal 55 | yrx = ynoisy; 56 | 57 | %% Scatter Plot 58 | % Create scatter plot of noisy signal and transmitted 59 | % signal on the same axes. 60 | h = scatterplot(yrx(1:nsamp*5e3),nsamp,0,'g.'); 61 | hold on; 62 | scatterplot(ytx(1:5e3),1,0,'k*',h); 63 | title('Received Signal'); 64 | legend('Received Signal','Signal Constellation'); 65 | axis([-5 5 -5 5]); % Set axis ranges. 66 | hold off; 67 | 68 | 69 | %% Demodulation 70 | % Demodulate signal using 16-QAM. 71 | zsym = demodulate(modem.qamdemod(M),yrx); 72 | 73 | 74 | %% Symbol-to-Bit Mapping 75 | % Undo the bit-to-symbol mapping performed earlier. 76 | hIntToBit = comm.IntegerToBit(k); 77 | z = step(hIntToBit,zsym); 78 | 79 | %% BER Computation 80 | % Compare x and z to obtain the number of errors and 81 | % the bit error rate. 82 | hErrorCalc = comm.ErrorRate; 83 | berVec = step(hErrorCalc,x,z); 84 | bit_error_rate = berVec(1) 85 | number_of_errors = berVec(2) 86 | 87 | -------------------------------------------------------------------------------- /Modulated signal/Basic/QAM/QAM3.m: -------------------------------------------------------------------------------- 1 | %% Plotting Signal Constellations 2 | % This example, described in the Getting Started chapter of the 3 | % Communications Toolbox documentation, aims to solve the following 4 | % problem: 5 | % 6 | % Plot a 16-QAM signal constellation with annotations that 7 | % indicate the mapping from integers to constellation points. 8 | 9 | % Copyright 1996-2009 The MathWorks, Inc. 10 | % $Revision: 1.1.8.2 $ $Date: 2009/07/20 17:37:54 $ 11 | 12 | %% Initial Plot, Without Gray Coding 13 | M = 16; % Number of points in constellation 14 | hMod = modem.qammod(M); % Modulator 15 | mapping = hMod.SymbolMapping; % Symbol mapping vector 16 | pt = hMod.Constellation; % Vector of all points in constellation 17 | 18 | % Plot the constellation. 19 | hScatter = commscope.ScatterPlot; % Create a scatter plot scope 20 | hScatter.Constellation = pt; % Set expected constellation 21 | hScatter.PlotSettings.Constellation = 'on'; % Display ideal constellation 22 | 23 | % Include text annotations that number the points. 24 | text(real(pt)+0.1,imag(pt),dec2bin(mapping)); 25 | 26 | %% Modified Plot, With Gray Coding 27 | M = 16; % Number of points in constellation 28 | hMod = modem.qammod('M',M,'SymbolOrder','Gray'); % Modulator 29 | mapping = hMod.SymbolMapping; % Symbol mapping vector 30 | pt = hMod.Constellation; % Vector of all points in constellation 31 | 32 | % Plot the constellation. 33 | hScatter = commscope.ScatterPlot; % Create a scatter plot scope 34 | hScatter.Constellation = pt; % Set expected constellation 35 | hScatter.PlotSettings.Constellation = 'on'; % Display ideal constellation 36 | 37 | % Include text annotations that number the points. 38 | text(real(pt)+0.1,imag(pt),dec2bin(mapping)); 39 | -------------------------------------------------------------------------------- /Modulated signal/Basic/QAM/gen_gray_code.m: -------------------------------------------------------------------------------- 1 | %generate gray code,first data is 0 vector 2 | %N>=2 3 | %hint: 4 | %0 => 0 0 => 00 10 =>00 => 00 00 => 0 00 1 00...... 5 | %1 1 1 01 11 01 01 01 0 01 1 01 6 | % 11 11 11 0 11 1 11 7 | % 10 10 10 0 10 1 10 8 | % 9 | function gray_code=gen_gray_code(N) 10 | sub_gray=[0;1]; 11 | for n=2:N 12 | top_gray=[zeros(1,2^(n-1))' sub_gray]; 13 | bottom_gray=[ones(1,2^(n-1))' sub_gray]; 14 | bottom_gray=bottom_gray(end:-1:1,:); 15 | sub_gray=[top_gray;bottom_gray]; 16 | end 17 | gray_code=sub_gray; 18 | end 19 | -------------------------------------------------------------------------------- /Modulated signal/Basic/QAM/plotSpectral.m: -------------------------------------------------------------------------------- 1 | %plot Spectral 2 | %signal:row vector 3 | %fs:sample rate 4 | function plotSpectral(signal,fs) 5 | NFFT = 2^nextpow2(size(signal,2)); 6 | Y=fft(signal,NFFT)/size(signal,2); 7 | f = fs/2*linspace(0,1,NFFT/2+1) ; 8 | plot(f,2*abs(Y(1:NFFT/2+1))); 9 | 10 | end -------------------------------------------------------------------------------- /Modulated signal/Basic/QPSK.m: -------------------------------------------------------------------------------- 1 | %Generating FM signal 2 | clc 3 | clear all; 4 | close all; 5 | %use orthogonal modulation generate modulated siganl 6 | %You can see the original signal v in the code. 7 | fc=1e4; %carrier frequency 8 | fs=1e5; %sample frequency 9 | Rs=2e3; %symbol rate of digital signal 10 | T=1/fs; %sample time 11 | L=500; %length of signal 12 | t=(0:L-1)*T; %time vector 13 | A=1; %%Ampltitude 14 | v=A*cos(2*pi*1000*t); %modulation signal 15 | xs=sin(2*pi*fc*t); 16 | xc=cos(2*pi*fc*t); 17 | 18 | T_qpsk=1/Rs; 19 | a_2n=round(rand(1,2*round(L/(T_qpsk*fs)))); 20 | phi_qpsk=[0 pi/2 pi 3*pi/2]; 21 | qpsk_code=[0,0;0,1;1,1;1,0]; 22 | I_QPSK=zeros(1,length(a_2n)/2); 23 | Q_QPSK=zeros(1,length(a_2n)/2); 24 | for i=1:length(a_2n)/2 25 | if a_2n(2*i-1:2*i)==qpsk_code(1,:) 26 | I_QPSK(i)=cos(phi_qpsk(1)); 27 | Q_QPSK(i)=-sin(phi_qpsk(1)); 28 | elseif a_2n(2*i-1:2*i)==qpsk_code(2,:) 29 | I_QPSK(i)=cos(phi_qpsk(2)); 30 | Q_QPSK(i)=-sin(phi_qpsk(2)); 31 | elseif a_2n(2*i-1:2*i)==qpsk_code(3,:) 32 | I_QPSK(i)=cos(phi_qpsk(3)); 33 | Q_QPSK(i)=-sin(phi_qpsk(3)); 34 | else 35 | I_QPSK(i)=cos(phi_qpsk(4)); 36 | Q_QPSK(i)=-sin(phi_qpsk(4)); 37 | end 38 | end 39 | I_QPSK=repmat(I_QPSK,T_qpsk*fs,1); 40 | I_QPSK=I_QPSK(:)'; 41 | Q_QPSK=repmat(Q_QPSK,T_qpsk*fs,1); 42 | Q_QPSK=Q_QPSK(:)'; 43 | y_qpsk=I_QPSK.*xc+Q_QPSK.*xs; 44 | 45 | figure(1) 46 | plot(y_qpsk) 47 | 48 | figure(2) 49 | plotSpectral(y_qpsk,fs) 50 | -------------------------------------------------------------------------------- /Modulated signal/Basic/SSB.m: -------------------------------------------------------------------------------- 1 | %Generating FM signal 2 | clc 3 | clear all; 4 | close all; 5 | %use orthogonal modulation generate modulated siganl 6 | %You can see the original signal v in the code. 7 | fc=1e4; %carrier frequency 8 | fs=1e5; %sample frequency 9 | T=1/fs; %sample time 10 | L=200; %length of signal 11 | t=(0:L-1)*T; %time vector 12 | A=1; %%Ampltitude 13 | v=A*cos(2*pi*1000*t); %modulation signal 14 | xs=sin(2*pi*fc*t); 15 | xc=cos(2*pi*fc*t); 16 | 17 | I_SSB=v; 18 | Q_SSB=imag(hilbert(v)); %LSB 19 | y_SSB=I_SSB.*xc+Q_SSB.*xs; 20 | 21 | figure(1) 22 | plot(y_SSB) 23 | title('LSB'); 24 | figure(2) 25 | plotSpectral(y_SSB,fs) 26 | 27 | I_SSB=v; 28 | 29 | Q_SSB=-imag(hilbert(v)); %USB 30 | y_SSB=I_SSB.*xc+Q_SSB.*xs; 31 | figure(3) 32 | plot(y_SSB) 33 | title('USB'); 34 | figure(4) 35 | plotSpectral(y_SSB,fs) -------------------------------------------------------------------------------- /Modulated signal/Basic/pi4DQPSK/pi4DQPSK.m: -------------------------------------------------------------------------------- 1 | % pi/4DQPSK 2 | clc 3 | clear 4 | 5 | Rs=10e2; %bit ratio 6 | Ts=1/Rs; 7 | N=500; %Number of bits to process 8 | fc=20e2; %carrier frequency 9 | fs=10e4; %sample frequency 10 | T=1/fs; 11 | t=(0:(round(N*Ts/T)-1))*T; 12 | r=Ts/T; 13 | 14 | a=rand(1,N)>0.5; %bit symbol 15 | 16 | %% serial-to-paralle 17 | Idata=a(1:2:end); 18 | Idata=repmat(Idata,2,1); 19 | Idata=Idata(:)'; 20 | 21 | Qdata=a(2:2:end); 22 | Qdata=repmat(Qdata,2,1); 23 | Qdata=Qdata(:)'; 24 | 25 | %% Qdata delay one bit 26 | Qdata=[0,Qdata(1:end-1)]; 27 | 28 | %% Gray coded 29 | % 00->0-> pi/4 30 | % 01->1-> 3pi/4 31 | % 10->2-> -pi/4 32 | % 11->3->-3pi/4 33 | two_bits_decimal = [2,1]*[Qdata;Idata]; 34 | phase_code=pi*[1/4,3/4,-1/4,-3/4]; 35 | phi=phase_code(two_bits_decimal+1); 36 | phi=cumsum(phi); 37 | %From here only the phase jump of pi/4 and 3pi/4 can be seen. 38 | figure 39 | stem(abs(phi/pi-[phi(2:end),0]/pi)); 40 | title('phase jump') 41 | phi_sample=repmat(phi,r,1); 42 | phi_sample=phi_sample(:)'; 43 | %% constellation 44 | j=sqrt(-1); 45 | s=cos(phi)+sin(phi)*j; 46 | figure 47 | plot(s,'o') 48 | grid on;axis('equal',[-1.5 1.5 -1.5 1.5]); 49 | title('constellation map') 50 | figure 51 | plot(s) 52 | grid on;axis('equal',[-1.5 1.5 -1.5 1.5]); 53 | title('Phase change trajectory') 54 | %% carrier wave 55 | xc=cos(2*pi*fc*t); 56 | xs=sin(2*pi*fc*t); 57 | 58 | %% pi4DQPSK 59 | A=1; %amplitude 60 | pi4DQPSK_signal=A*(cos(phi_sample).*xc-sin(phi_sample).*xs); 61 | 62 | figure 63 | plotSpectral(pi4DQPSK_signal,fs) 64 | -------------------------------------------------------------------------------- /Modulated signal/Basic/pi4DQPSK/plotSpectral.m: -------------------------------------------------------------------------------- 1 | %plot Spectral 2 | %signal:row vector 3 | %fs:sample rate 4 | function plotSpectral(signal,fs) 5 | NFFT = 2^nextpow2(size(signal,2)); 6 | Y=fft(signal,NFFT)/size(signal,2); 7 | f = fs/2*linspace(0,1,NFFT/2+1) ; 8 | plot(f,2*abs(Y(1:NFFT/2+1))); 9 | xlabel('Hz'); 10 | end -------------------------------------------------------------------------------- /Modulated signal/Basic/plotSpectral.m: -------------------------------------------------------------------------------- 1 | %plot Spectral 2 | %signal:row vector 3 | %fs:sample rate 4 | function plotSpectral(signal,fs) 5 | NFFT = 2^nextpow2(size(signal,2)); 6 | Y=fft(signal,NFFT)/size(signal,2); 7 | f = fs/2*linspace(0,1,NFFT/2+1) ; 8 | plot(f,2*abs(Y(1:NFFT/2+1))); 9 | 10 | end -------------------------------------------------------------------------------- /Modulated signal/KeyValue/GMSK.m: -------------------------------------------------------------------------------- 1 | %% Gaussian Filtered Minimum Shift keying-GMSK 2 | 3 | clc 4 | clear 5 | close all 6 | 7 | Rs=1e3; %bit ratio 8 | Ts=1/Rs; 9 | N=10; %Number of bits to process 10 | fc=40e2; %carrier frequency 11 | fs=10e4; %sample frequency 12 | T=1/fs; 13 | t=(0:(round(N*Ts/T)-1))*T; 14 | ts=(0:N-1)*Ts; 15 | r=round(Ts/T); 16 | 17 | %% Orthogonal carrier wave 18 | xc=cos(2*pi*fc*t); 19 | xs=sin(2*pi*fc*t); 20 | 21 | %% Gaussian Filter 22 | BTs=0.3; 23 | B=BTs/Ts; 24 | 25 | 26 | %alpha=sqrt(log(2)/2)/B; 27 | %h=sqrt(pi)/alpha*exp(-(pi/alpha*t).^2); 28 | 29 | 30 | %I couldn't do it with h convolution, and then I used qunc function. 31 | g_t=qfunc(2*pi*B*(t-Ts/2-4.5*Ts)/sqrt(log(2)))-qfunc(2*pi*B*(t+Ts/2-4.5*Ts)/sqrt(log(2)));%4,5Ts is used to display all g_t 32 | figure 33 | plot(t,g_t) 34 | 35 | 36 | %% gengerate bit sequence 37 | a=2*(rand(1,N)>0.5)-1; 38 | %a=[1,1,-1,1,-1,-1,1,1,-1,1] %%test signal 39 | %a=[1,1,1,-1,-1,1,1,1,-1,-1,-1,-1,-1,-1,-1] 40 | a=[1,1,1,-1,-1,1,1,1,-1,-1] 41 | a_sample=repmat(a,r,1); 42 | a_sample=a_sample(:)'; 43 | 44 | figure 45 | plot(a_sample) 46 | %% conv 47 | a_fil=conv(a_sample,g_t)/r;%I can't explain it here./r,It seems right. 48 | a_fil=a_fil(round(4.5*Ts/T):end);%Make up for the delays(4.5Ts) previously used 49 | figure 50 | plot(a_fil) 51 | title('a_fil') 52 | 53 | 54 | %% additive phase 55 | for ii=1:length(t) 56 | theta(ii)=pi/(2*Ts)*T*trapz(a_fil(1:ii)); 57 | end 58 | figure 59 | %Although the trend is right, the peak value is getting smaller and I don't know what the problem is. 60 | plot(theta) 61 | 62 | theta1=wrapToPi(theta); 63 | figure 64 | plot(theta1) 65 | %% GMSK 66 | s=cos(theta).*xc-sin(theta).*xs; 67 | figure 68 | plot(s) 69 | -------------------------------------------------------------------------------- /Modulated signal/KeyValue/KeyStatisticalFeaturesFromTheCommunicationSignal.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/Modulated signal/KeyValue/KeyStatisticalFeaturesFromTheCommunicationSignal.m -------------------------------------------------------------------------------- /Modulated signal/KeyValue/MSK.m: -------------------------------------------------------------------------------- 1 | %gen MSK by Quadrature 2 | %s_k(t)=p_k*cos(pi*t/(2*T_s))cos(w_c*t)-q_k*sin(pi*t/(2*T_s))sin(w_c*t) 3 | %(k-1)T_s0.5)-1; 20 | %a=[1,1,-1,1,-1,-1,1,1,-1,1] %%test signal 21 | %a=[1,1,1,-1,-1,1,1,1,-1,-1] 22 | a_sample=repmat(a,r,1); 23 | a_sample=a_sample(:)'; 24 | subplot(6,1,1) 25 | plot(a_sample) 26 | set(gca,'xticklabel',[]); 27 | set(gca,'position',[0.15 5.1/6 0.75 0.9/6]) 28 | axis([0 length(a_sample) -2 2]) 29 | ylabel('a(t)') 30 | %% Differential coding 31 | 32 | b=ones(1,N); 33 | b(1)=a(1); 34 | for jj=2:N 35 | if a(jj)==1 36 | b(jj)=b(jj-1); 37 | else 38 | b(jj)=-b(jj-1); 39 | end 40 | end 41 | 42 | b_sample=repmat(b,r,1); 43 | b_sample=b_sample(:)'; 44 | subplot(6,1,2); 45 | plot(b_sample) 46 | set(gca,'xticklabel',[]); 47 | set(gca,'position',[0.15 4.1/6 0.75 0.9/6]) 48 | axis([0 length(b_sample) -2 2]) 49 | ylabel('b(t)') 50 | 51 | %% serial to parallel conversion 52 | %b1b2b3b4b5b6b7b8=p1q2p3q4p5q6 53 | %b1=p1=p2,b2=q2=q3 54 | %p_k:p1p2p3p4p5p6p7=b1b1b3b3b5b5b7 55 | %q_k:q1q2q3q4q5q6q7q8=b0b2b2b4b4b6b6b8 56 | %At present, I don't know how to get the value of b0 p0 and q0 , 57 | %Suppose b0=a0,p0=cos(\phi_{0})=1,q0=b0 58 | b_odd=b(1:2:end); 59 | b_even=b(2:2:end); 60 | p=reshape([b_even;b_even],1,[]); 61 | p=[1,p(1:end-1)]; 62 | q=reshape([b_odd;b_odd],1,[]); 63 | 64 | %% plot p(t) 65 | p_sample=repmat(p,r,1); 66 | p_sample=p_sample(:)'; 67 | subplot(6,1,3); 68 | plot(p_sample) 69 | set(gca,'xticklabel',[]); 70 | set(gca,'position',[0.15 3.1/6 0.75 0.9/6]) 71 | axis([0 length(p_sample) -2 2]) 72 | ylabel('p(t)') 73 | %% plot q(t) 74 | q_sample=repmat(q,r,1); 75 | q_sample=q_sample(:)'; 76 | subplot(6,1,4); 77 | plot(q_sample); 78 | set(gca,'xticklabel',[]); 79 | set(gca,'position',[0.15 2.2/6 0.75 0.8/6]) 80 | axis([0 length(q_sample) -2 2]) 81 | ylabel('q(t)') 82 | 83 | %% plot p_sample.*cos(pi*t/(2*Ts)) 84 | subplot(6,1,5); 85 | plot(p_sample.*cos(pi*t/(2*Ts))); 86 | set(gca,'xticklabel',[]); 87 | set(gca,'position',[0.15 1.4/6 0.75 0.7/6]) 88 | axis([0 length(q_sample) -1 1]) 89 | ylabel('p*cos(\pi*t/(2*Ts)') 90 | 91 | %% plot q_sample.*sin(pi*t/(2*Ts)) 92 | subplot(6,1,6) 93 | plot(q_sample.*sin(pi*t/(2*Ts))) 94 | %set(gca,'xticklabel',[]); 95 | set(gca,'position',[0.15 1/12 0.75 0.8/6]) 96 | xlabel('time') 97 | ylabel('q*sin(\pi*t/(2*Ts)') 98 | 99 | %% s: MSK signal 100 | s=p_sample.*cos(pi*t/(2*Ts)).*xc-q_sample.*sin(pi*t/(2*Ts)).*xs; 101 | sl=p_sample.*cos(pi*t/(2*Ts))-q_sample.*sin(pi*t/(2*Ts))*j; 102 | figure 103 | plot(s) 104 | title('MSK') 105 | figure 106 | plotSpectral(s,fs); 107 | 108 | %% plot additive phase 109 | %theta_k(t)=a_k*pi/(2*T_s)*t+phi 110 | phi=zeros(1,N); 111 | for jj=2:N 112 | phi(jj)=phi(jj-1)+(jj-1)*pi/2*(a(jj-1)-a(jj)); 113 | end 114 | %phi=mod(phi,2*pi) 115 | phi=repmat(phi,r,1); 116 | phi=phi(:)'; 117 | theta=(a_sample*pi)/(2*Ts).*t+phi; 118 | theta=wrapToPi(theta); 119 | plot(theta,'r') 120 | set(gca,'YTick',-pi:pi/2:pi) 121 | set(gca,'YTickLabel',{'-pi','-pi/2','0','pi/2','pi'}) 122 | ylabel('\theta_{k}(t)') 123 | xlabel('time') 124 | title('additive phase (mod 2\pi)') 125 | grid on -------------------------------------------------------------------------------- /Modulated signal/KeyValue/M_pq.m: -------------------------------------------------------------------------------- 1 | %X;signal 2 | function M=M_pq(X,p,q) 3 | M=mean(X.^(p-q).*conj(X).^q); 4 | end 5 | -------------------------------------------------------------------------------- /Modulated signal/KeyValue/MaxSpectralDensity.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/Modulated signal/KeyValue/MaxSpectralDensity.m -------------------------------------------------------------------------------- /Modulated signal/KeyValue/OQPSK.m: -------------------------------------------------------------------------------- 1 | %OQPSK 2 | clc 3 | clear 4 | 5 | Rs=10e2; %bit ratio 6 | Ts=1/Rs; 7 | N=1000; %Number of bits to process 8 | fc=10e3; %carrier frequency 9 | fs=10e4; %sample frequency 10 | T=1/fs; 11 | t=(0:(round(N*Ts/T)-1))*T; 12 | r=round(Ts/T); 13 | 14 | a=rand(1,N)>0.5; %bit symbol 15 | 16 | %% serial-to-paralle 17 | Idata=a(1:2:end); 18 | Idata=repmat(Idata,2,1); 19 | Idata=Idata(:)'; 20 | 21 | Qdata=a(2:2:end); 22 | Qdata=repmat(Qdata,2,1); 23 | Qdata=Qdata(:)'; 24 | 25 | %% Qdata delay one bit 26 | Qdata=[0,Qdata(1:end-1)]; 27 | 28 | %% Gray coded 29 | % 00->0->5pi/4 30 | % 01->1->7pi/4 31 | % 10->2->3pi/4 32 | % 11->3-> pi/4 33 | two_bits_decimal = [2,1]*[Qdata;Idata]; 34 | phase_code=pi*[5/4,7/4,3/4,1/4]; 35 | phi=phase_code(two_bits_decimal+1); 36 | %From here we can see that there is no phase jump of pi.only pi/2 37 | figure 38 | stem(abs(phi/pi-[phi(2:end),0]/pi)); 39 | title('phase jump') 40 | phi_sample=repmat(phi,r,1); 41 | phi_sample=phi_sample(:)'; 42 | 43 | %% constellation 44 | j=sqrt(-1); 45 | s=cos(phi)+sin(phi)*j; 46 | figure 47 | plot(s,'o') 48 | grid on;axis('equal',[-1.5 1.5 -1.5 1.5]); 49 | title('constellation map') 50 | %hold on 51 | figure 52 | plot(s,'r') 53 | grid on;axis('equal',[-1.5 1.5 -1.5 1.5]); 54 | title('Phase change trajectory') 55 | 56 | %% carrier wave 57 | xc=cos(2*pi*fc*t); 58 | xs=sin(2*pi*fc*t); 59 | 60 | %% OQPSK 61 | A=1; %amplitude 62 | OQPSK_signal=A*(cos(phi_sample).*xc-sin(phi_sample).*xs); 63 | figure 64 | plot(OQPSK_signal) 65 | figure 66 | plotSpectral(OQPSK_signal,fs) 67 | 68 | s_complex=cos(phi_sample)+sin(phi_sample)*j; 69 | 70 | -------------------------------------------------------------------------------- /Modulated signal/KeyValue/QAM.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/Modulated signal/KeyValue/QAM.m -------------------------------------------------------------------------------- /Modulated signal/KeyValue/SpectralSymmetryIndex.m: -------------------------------------------------------------------------------- 1 | %symmetrical characteristic of specturm ,page 261. 2 | function y=SpectralSymmetryIndex(s,fs,fc) 3 | Ns=length(s); 4 | %fc=carrier_estimate(s,fs); %Only when the carrier frequency 5 | %estimation is very accurate can 6 | %the following algorithm be implemented 7 | %fc=1e4; 8 | f_cn=round(fc*Ns/fs-1); 9 | S_abs=abs(fft(s))/Ns; 10 | P_L=sum(S_abs(1:f_cn).^2); 11 | P_U=sum(S_abs(1+f_cn+1:f_cn+f_cn+1).^2); 12 | P=(P_L-P_U)/(P_L+P_U); 13 | y=P; 14 | end -------------------------------------------------------------------------------- /Modulated signal/KeyValue/bispecd.m: -------------------------------------------------------------------------------- 1 | function [Bspec,waxis] = bispecd (y, nfft, wind, nsamp, overlap) 2 | %BISPECD Bispectrum estimation using the direct (fft-based) approach. 3 | % [Bspec,waxis] = bispecd (y, nfft, wind, segsamp, overlap) 4 | % y - data vector or time-series 5 | % nfft - fft length [default = power of two > segsamp] 6 | % wind - window specification for frequency-domain smoothing 7 | % if 'wind' is a scalar, it specifies the length of the side 8 | % of the square for the Rao-Gabr optimal window [default=5] 9 | % if 'wind' is a vector, a 2D window will be calculated via 10 | % w2(i,j) = wind(i) * wind(j) * wind(i+j) 11 | % if 'wind' is a matrix, it specifies the 2-D filter directly 12 | % segsamp - samples per segment [default: such that we have 8 segments] 13 | % - if y is a matrix, segsamp is set to the number of rows 14 | % overlap - percentage overlap [default = 50] 15 | % - if y is a matrix, overlap is set to 0. 16 | % 17 | % Bspec - estimated bispectrum: an nfft x nfft array, with origin 18 | % at the center, and axes pointing down and to the right. 19 | % waxis - vector of frequencies associated with the rows and columns 20 | % of Bspec; sampling frequency is assumed to be 1. 21 | 22 | % Copyright (c) 1991-2001 by United Signals & Systems, Inc. 23 | % $Revision: 1.8 $ 24 | % A. Swami January 20, 1993. 25 | 26 | % RESTRICTED RIGHTS LEGEND 27 | % Use, duplication, or disclosure by the Government is subject to 28 | % restrictions as set forth in subparagraph (c) (1) (ii) of the 29 | % Rights in Technical Data and Computer Software clause of DFARS 30 | % 252.227-7013. 31 | % Manufacturer: United Signals & Systems, Inc., P.O. Box 2374, 32 | % Culver City, California 90231. 33 | % 34 | % This material may be reproduced by or for the U.S. Government pursuant 35 | % to the copyright license under the clause at DFARS 252.227-7013. 36 | 37 | % --------------------- parameter checks ----------------------------- 38 | 39 | [ly, nrecs] = size(y); 40 | if (ly == 1) y = y(:); ly = nrecs; nrecs = 1; end 41 | 42 | if (exist('nfft') ~= 1) nfft = 128; end 43 | if (exist('overlap') ~= 1) overlap = 50; end 44 | overlap = min(99,max(overlap,0)); 45 | if (nrecs > 1) overlap = 0; end 46 | if (exist('nsamp') ~= 1) nsamp = 0; end 47 | if (nrecs > 1) nsamp = ly; end 48 | 49 | if (nrecs == 1 & nsamp <= 0) 50 | nsamp = fix(ly/ (8 - 7 * overlap/100)); 51 | end 52 | if (nfft < nsamp) nfft = 2^nextpow2(nsamp); end 53 | 54 | overlap = fix(nsamp * overlap / 100); % added 2/14 55 | nadvance = nsamp - overlap; 56 | nrecs = fix ( (ly*nrecs - overlap) / nadvance); 57 | 58 | 59 | % ------------------- create the 2-D window ------------------------- 60 | if (exist('wind') ~= 1) wind = 5; end 61 | [m,n] = size(wind); 62 | window = wind; 63 | if (max(m,n) == 1) % scalar: wind is size of Rao-Gabr window 64 | winsize = wind; 65 | if (winsize < 0) winsize = 5; end % the window length L 66 | winsize = winsize - rem(winsize,2) + 1; % make it odd 67 | if (winsize > 1) 68 | mwind = fix (nfft/winsize); % the scale parameter M 69 | lby2 = (winsize - 1)/2; 70 | 71 | theta = -lby2:lby2; 72 | opwind = ones(winsize,1) * (theta .^2); % w(m,n)=m^2 73 | opwind = opwind + opwind' + theta' * theta; % m^2 + n^2 + mn 74 | opwind = 1 - (2*mwind/nfft)^2 * opwind; % 75 | hex = ones(winsize,1) * theta; % m 76 | hex = abs(hex) + abs(hex') + abs(hex+hex'); 77 | hex = (hex < winsize); 78 | opwind = opwind .* hex; 79 | opwind = opwind * (4 * mwind^2) / (7 * pi^2) ; 80 | else 81 | opwind = 1; 82 | end 83 | 84 | elseif (min(m,n) == 1) % 1-D window passed: convert to 2-D 85 | window = window(:); 86 | if (any(imag(window) ~= 0)) 87 | disp(['1-D window has imaginary components: window ignored']) 88 | window = 1; 89 | end 90 | if (any(window < 0)) 91 | disp(['1-D window has negative components: window ignored']) 92 | window = 1; 93 | end 94 | lwind = length(window); 95 | windf = [window(lwind:-1:2); window]; % the full symmetric 1-D 96 | window = [window; zeros(lwind-1,1)]; 97 | opwind = (windf * windf') ... 98 | .* hankel(flipud(window), window); % w(m)w(n)w(m+n) 99 | winsize = length(window); 100 | 101 | else % 2-D window passed: use directly 102 | winsize = m; 103 | if (m ~= n) 104 | disp('2-D window is not square: window ignored') 105 | window = 1; 106 | winsize = m; 107 | end 108 | if (rem(m,2) == 0) 109 | disp('2-D window does not have odd length: window ignored') 110 | window = 1; 111 | winsize = m; 112 | end 113 | opwind = window; 114 | end 115 | 116 | % ---------------- accumulate triple products ---------------------- 117 | 118 | Bspec = zeros(nfft,nfft); 119 | 120 | mask = hankel([1:nfft],[nfft,1:nfft-1] ); % the hankel mask (faster) 121 | locseg = [1:nsamp]'; 122 | for krec = 1:nrecs 123 | xseg = y(locseg); 124 | Xf = fft(xseg-mean(xseg), nfft)/nsamp; 125 | CXf = conj(Xf); 126 | Bspec = Bspec + (Xf * Xf.') .* ... 127 | reshape(CXf(mask), nfft, nfft); 128 | locseg = locseg + nadvance; 129 | end 130 | 131 | Bspec = fftshift(Bspec)/(nrecs); 132 | 133 | 134 | 135 | % ----------------- frequency-domain smoothing ------------------------ 136 | 137 | if (winsize > 1) 138 | lby2 = (winsize-1)/2; 139 | Bspec = conv2(Bspec,opwind); 140 | Bspec = Bspec(lby2+1:lby2+nfft,lby2+1:lby2+nfft); 141 | end 142 | % ------------ contour plot of magnitude bispectum -------------------- 143 | 144 | if (rem(nfft,2) == 0) 145 | waxis = [-nfft/2:(nfft/2-1)]'/nfft; 146 | else 147 | waxis = [-(nfft-1)/2:(nfft-1)/2]'/nfft; 148 | end 149 | 150 | hold off, clf 151 | % contour(abs(Bspec),4,waxis,waxis),grid 152 | contour(waxis,waxis,abs(Bspec),4),grid on 153 | title('Bispectrum estimated via the direct (FFT) method') 154 | xlabel('f1'), ylabel('f2') 155 | set(gcf,'Name','Hosa BISPECD') 156 | return 157 | -------------------------------------------------------------------------------- /Modulated signal/KeyValue/carrier_estimate.m: -------------------------------------------------------------------------------- 1 | %carrier_estimate,page 267,(5-299),it only be used to estimate frequency of 2 | %signal which has symmetry spectrum 3 | %s:modulate signal 4 | %y:carrier frequency 5 | %fs:sample frequency 6 | function y=carrier_estimate(s,fs) 7 | S=fft(s)/length(s); 8 | N_half=length(s)/2; 9 | k=1:N_half; 10 | y=fs/length(s)*sum(abs(S(1:N_half)).^2.*k)/sum(abs(S(1:N_half)).^2); 11 | end -------------------------------------------------------------------------------- /Modulated signal/KeyValue/gen_data_file.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/Modulated signal/KeyValue/gen_data_file.m -------------------------------------------------------------------------------- /Modulated signal/KeyValue/gen_gray_code.m: -------------------------------------------------------------------------------- 1 | %generate gray code,first data is 0 vector 2 | %N>=2 3 | %hint: 4 | %0 => 0 0 => 00 10 =>00 => 00 00 => 0 00 1 00...... 5 | %1 1 1 01 11 01 01 01 0 01 1 01 6 | % 11 11 11 0 11 1 11 7 | % 10 10 10 0 10 1 10 8 | % 9 | function gray_code=gen_gray_code(N) 10 | sub_gray=[0;1]; 11 | for n=2:N 12 | top_gray=[zeros(1,2^(n-1))' sub_gray]; 13 | bottom_gray=[ones(1,2^(n-1))' sub_gray]; 14 | bottom_gray=bottom_gray(end:-1:1,:); 15 | sub_gray=[top_gray;bottom_gray]; 16 | end 17 | gray_code=sub_gray; 18 | end 19 | -------------------------------------------------------------------------------- /Modulated signal/KeyValue/modulation_recognize.m: -------------------------------------------------------------------------------- 1 | %my code can't achieve modulate recognize if uses threshold in book 2 | function modulation_recognize(s,Rs,fc,fs) 3 | %A:analog,D:digital %range %maybe right 4 | tA_sigma_dp=pi/6; %pi/6 % 5 | tD_sigma_dp=pi/6.5; %pi/6.5-pi/2.5 % 6 | tAD_sigma_dp=1; %pi/6 % 1 7 | tA_P_SSB=0.5; %0.5-0.99 % 8 | tA_P_VSB=0.55; %0.55-0.6 % 9 | tAD_P_SSB=0.6; %0.6-0.9 % 10 | tAD_P_VSB=1; %0.5-0.7 %1 11 | tA_sigma_ap=pi/6.5; %pi/6.5-pi/2.5 % 12 | tD_sigma_ap=pi/5.5; %pi/5.5 % 13 | tAD_sigma_ap=pi/5.5; %pi/5.5 % 14 | t_sigma_a_2psk=0.1; %0.125-0.4 %0.1 15 | t_sigma_a_4psk=0.15; %0.15 %haven't test 16 | tA_gamma_max=5.5; %5.5-6 % 17 | tD_gamma_max=4; %4 % 18 | tAD_gamma_max=0.1; %2-2.5 %0.1 19 | tAD_mu_a_42=2.15; %2.15 % 20 | tAD_mu_f_42=2; %2.03 % 21 | tD_AD_sigma_aa=0.25; %0.25 % 22 | tD_AD_sigma_af=1.5; %0.4 %1.5 23 | 24 | a_t=1; 25 | Ysigma_dp=sigma_dp(s,a_t,fs,fc) 26 | Ysigma_ap=sigma_ap(s,a_t,fs,fc) 27 | Ymu_f_42=mu_f_42(s,fs,Rs) 28 | Ymu_a_42=mu_a_42(s) %not use func in book 29 | Ysigma_a=sigma_a(s,0.2) %there threshold I take 0.2 by test 30 | Ysigma_af=sigma_af(s,a_t,fs,Rs) 31 | Ysigma_aa=sigma_aa(s) 32 | Ygamma_max=MaxSpectralDensity(s) 33 | YP=SpectralSymmetryIndex(s,fs,fc) 34 | 35 | if Ysigma_dp>tAD_sigma_dp 36 | if abs(YP)>tAD_P_SSB 37 | if YP>0 38 | display('LSB'); 39 | else 40 | display('USB'); 41 | end 42 | else 43 | if Ysigma_aptAD_gamma_max 51 | if Ysigma_atAD_mu_f_42 58 | if Ysigma_af>tD_AD_sigma_af %I have changed logic 59 | display('4FSK'); 60 | else 61 | display('2FSK'); 62 | end 63 | else 64 | display('FM'); 65 | end 66 | end 67 | end 68 | end 69 | else 70 | if abs(YP)tD_AD_sigma_aa %I have changed logic 75 | display('4ASK'); 76 | else 77 | display('2ASK'); 78 | end 79 | end 80 | else 81 | display('VSB'); 82 | end 83 | end -------------------------------------------------------------------------------- /Modulated signal/KeyValue/mu_a_42.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/Modulated signal/KeyValue/mu_a_42.m -------------------------------------------------------------------------------- /Modulated signal/KeyValue/mu_f_42.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/Modulated signal/KeyValue/mu_f_42.m -------------------------------------------------------------------------------- /Modulated signal/KeyValue/pi4DQPSK.m: -------------------------------------------------------------------------------- 1 | % pi/4DQPSK 2 | clc 3 | clear 4 | 5 | Rs=10e2; %bit ratio 6 | Ts=1/Rs; 7 | N=20; %Number of bits to process 8 | fc=10e3; %carrier frequency 9 | fs=10e4; %sample frequency 10 | T=1/fs; 11 | t=(0:(round(N*Ts/T)-1))*T; 12 | r=Ts/T; 13 | 14 | a=rand(1,N)>0.5; %bit symbol 15 | 16 | %% serial-to-paralle 17 | Idata=a(1:2:end); 18 | Idata=repmat(Idata,2,1); 19 | Idata=Idata(:)'; 20 | 21 | Qdata=a(2:2:end); 22 | Qdata=repmat(Qdata,2,1); 23 | Qdata=Qdata(:)'; 24 | 25 | %% Qdata delay one bit 26 | Qdata=[0,Qdata(1:end-1)]; 27 | 28 | %% Gray coded 29 | % 00->0-> pi/4 30 | % 01->1-> 3pi/4 31 | % 10->2-> -pi/4 32 | % 11->3->-3pi/4 33 | two_bits_decimal = [2,1]*[Qdata;Idata]; 34 | phase_code=pi*[1/4,3/4,-1/4,-3/4]; 35 | phi=phase_code(two_bits_decimal+1); 36 | phi=cumsum(phi); 37 | %From here only the phase jump of pi/4 and 3pi/4 can be seen. 38 | figure 39 | stem(abs(phi/pi-[phi(2:end),0]/pi)); 40 | title('phase jump') 41 | phi_sample=repmat(phi,r,1); 42 | phi_sample=phi_sample(:)'; 43 | %% constellation 44 | j=sqrt(-1); 45 | s=cos(phi)+sin(phi)*j; 46 | %aaa=sum((cos(phi)>=-0.1)&(cos(phi)<=0.1))+sum((cos(phi)>=-1.1)&(cos(phi)<=-0.9))+sum((cos(phi)>=0.9)&(cos(phi)<=1.1)) 47 | figure 48 | plot(s,'o') 49 | grid on;axis('equal',[-1.5 1.5 -1.5 1.5]); 50 | title('constellation map') 51 | figure 52 | plot(s) 53 | grid on;axis('equal',[-1.5 1.5 -1.5 1.5]); 54 | title('Phase change trajectory') 55 | %% carrier wave 56 | xc=cos(2*pi*fc*t); 57 | xs=sin(2*pi*fc*t); 58 | 59 | %% pi4DQPSK 60 | A=1; %amplitude 61 | pi4DQPSK_signal=A*(cos(phi_sample).*xc-sin(phi_sample).*xs); 62 | 63 | figure 64 | plotSpectral(pi4DQPSK_signal,fs) 65 | 66 | s_complex=cos(phi_sample)+sin(phi_sample)*j; 67 | 68 | 69 | -------------------------------------------------------------------------------- /Modulated signal/KeyValue/plotBispectra.m: -------------------------------------------------------------------------------- 1 | %plot Bispectral or Bispectrum slice 2 | %signal:row vector 3 | %fs:sample rate 4 | %mode :1--plot Bispectra,2--plot Bispectrum slice 5 | %norm:1:normalization, 6 | function [f,bispectra]=plotBispectra(signal,fs,mode,norm) 7 | NFFT = 2^nextpow2(size(signal,2)); 8 | Y=fft(signal,NFFT)/size(signal,2); 9 | f = fs/2*linspace(0,1,NFFT/2+1) ; 10 | %Y_1=2*abs(Y(1:NFFT/2+1)); 11 | Y_1=2*Y(1:NFFT/2+1); 12 | Y_len_2=round((length(Y_1)-1)/2); 13 | bis=zeros(Y_len_2,Y_len_2); 14 | for ii=1:Y_len_2 15 | for jj=1:Y_len_2 16 | bis(ii,jj)=Y_1(ii)*Y_1(jj)*conj(Y_1(ii+jj)); 17 | end 18 | end 19 | bis=abs(bis); 20 | if mode==1 21 | bispectra=bis; 22 | [xx,yy]=meshgrid(f(1:size(bispectra,1))); 23 | if norm==1 24 | bispectra=bispectra/max(bispectra(:)); 25 | end 26 | % surf(xx,yy,bispectra); 27 | contour(xx,yy,bispectra) 28 | xlabel('Hz'); 29 | elseif mode==2 30 | bispectra=diag(bis); 31 | if norm==1 32 | bispectra=bispectra/max(bispectra); 33 | end 34 | plot(f(1:size(bis,1)),bispectra); 35 | xlabel('Hz'); 36 | end 37 | end 38 | 39 | -------------------------------------------------------------------------------- /Modulated signal/KeyValue/plotSpectral.m: -------------------------------------------------------------------------------- 1 | %plot Spectral 2 | %signal:row vector 3 | %fs:sample rate 4 | function plotSpectral(signal,fs) 5 | NFFT = 2^nextpow2(size(signal,2)); 6 | Y=fft(signal,NFFT)/size(signal,2); 7 | f = fs/2*linspace(0,1,NFFT/2+1) ; 8 | plot(f,2*abs(Y(1:NFFT/2+1))); 9 | xlabel('Hz'); 10 | end -------------------------------------------------------------------------------- /Modulated signal/KeyValue/plotSquareSpectrum.m: -------------------------------------------------------------------------------- 1 | %plot Square Spectral 2 | %signal:row vector 3 | %fs:sample rate 4 | function [f,square_spectrum]=plotSquareSpectrum(signal,fs) 5 | NFFT = 2^nextpow2(size(signal,2)); 6 | Y=fft(signal.^2,NFFT)/size(signal,2); 7 | Y_shift=fftshift(Y); 8 | f = fs/2*linspace(-1,1,NFFT) ; 9 | square_spectrum=2*abs(Y_shift).^2; 10 | plot(f,square_spectrum); 11 | xlabel('Hz'); 12 | end -------------------------------------------------------------------------------- /Modulated signal/KeyValue/sigma_a.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/Modulated signal/KeyValue/sigma_a.m -------------------------------------------------------------------------------- /Modulated signal/KeyValue/sigma_aa.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/Modulated signal/KeyValue/sigma_aa.m -------------------------------------------------------------------------------- /Modulated signal/KeyValue/sigma_af.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/Modulated signal/KeyValue/sigma_af.m -------------------------------------------------------------------------------- /Modulated signal/KeyValue/sigma_ap.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/Modulated signal/KeyValue/sigma_ap.m -------------------------------------------------------------------------------- /Modulated signal/KeyValue/sigma_dp.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/Modulated signal/KeyValue/sigma_dp.m -------------------------------------------------------------------------------- /Modulated signal/KeyValue/test.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/Modulated signal/KeyValue/test.m -------------------------------------------------------------------------------- /Modulated signal/Synchronizer/CarrierSynchronizer/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/Modulated signal/Synchronizer/CarrierSynchronizer/readme.md -------------------------------------------------------------------------------- /Modulated signal/Synchronizer/SymbolSynchronizer test/Gardner_func.m: -------------------------------------------------------------------------------- 1 | function [yiq,ypc] = Gardner_func(xiq,sps) 2 | j=sqrt(-1); 3 | rf=0.6; 4 | span=4; 5 | h1 = rcosdesign(rf,span,sps,'sqrt'); 6 | xi=real(xiq); 7 | xq=imag(xiq); 8 | yi=conv(xi,h1); 9 | yq=conv(xq,h1); 10 | ypc=yi+yq*j; 11 | %% TED 12 | %parameter 13 | N=sps; 14 | aa=0.707; 15 | BT=0.005; 16 | K0=-1; 17 | alpha=0.5; 18 | Kp=1/(4*pi*(1-alpha^2/4))*sin(pi*alpha/2); 19 | K1=(4*aa/N*(BT/(aa+1/(4*aa))))/(1+(2*aa/N*(BT/(aa+1/(4*aa))))+(BT/(N*(aa+1/(4*aa))))^2)/Kp/K0; 20 | K2=4*(BT/(N*(aa+1/(4*aa))))^2/(1+(2*aa/N*(BT/(aa+1/(4*aa))))+(BT/(N*(aa+1/(4*aa))))^2)/Kp/K0; 21 | 22 | CNT_next=0; 23 | mu_next=0; 24 | underflow=0; 25 | vi=0; 26 | TEDBuffI=zeros(2,1); 27 | TEDBuffQ=zeros(2,1); 28 | k=1; 29 | e_max=4*max([yi,yq]); 30 | for n=2:length(yi)-2 31 | CNT=CNT_next; 32 | mu=mu_next; 33 | u(n)=mu; 34 | v2i=1/2*[1,-1,-1,1]*yi(n+2:-1:n-1)'; 35 | v2q=1/2*[1,-1,-1,1]*yq(n+2:-1:n-1)'; 36 | v1i=1/2*[-1,3,-1,-1]*yi(n+2:-1:n-1)'; 37 | v1q=1/2*[-1,3,-1,-1]*yq(n+2:-1:n-1)'; 38 | v0i=yi(n); 39 | v0q=yq(n); 40 | yI=(mu*v2i+v1i)*mu+v0i; 41 | yQ=(mu*v2q+v1q)*mu+v0q; 42 | if underflow==1 43 | e(n)=TEDBuffI(1)*(sign(TEDBuffI(2))-sign(yI))+TEDBuffQ(1)*(sign(TEDBuffQ(2))-sign(yQ)); 44 | e(n)=e(n)/e_max; 45 | %e(n)=0; 46 | xxI(k)=yI; 47 | xxQ(k)=yQ; 48 | k=k+1; 49 | else 50 | e(n)=0; 51 | % e(n)=TEDBuffI(1)*(sign(TEDBuffI(2))-sign(yI))+TEDBuffQ(1)*(sign(TEDBuffQ(2))-sign(yQ)); 52 | end 53 | vp=K1*e(n); 54 | vi=vi+K2*e(n); 55 | v=vp+vi; 56 | vvi(n)=vi; 57 | %W(n)=1/N; 58 | W(n)=1/N+v; 59 | 60 | % update registers 61 | CNT_next=CNT-W(n); 62 | cnt_next(n)=CNT_next; 63 | if CNT_next<0 64 | CNT_next=1+CNT_next; 65 | underflow=1; 66 | mu_next=CNT/W(n); 67 | else 68 | underflow=0; 69 | mu_next=mu; 70 | end 71 | TEDBuffI=[yI;TEDBuffI(1)]; 72 | TEDBuffQ=[yQ;TEDBuffQ(1)]; 73 | end 74 | yiq=xxI+xxQ*j; 75 | % figure;plot(xxI);title('q') 76 | % figure;plot(vvi);title('vi') 77 | % figure;plot(cnt_next);title('cnt_next') 78 | % figure;plot(W);title('W') 79 | % figure;plot(e);title('TED') 80 | % figure;plot(u);title('\mu') 81 | 82 | end 83 | 84 | -------------------------------------------------------------------------------- /Modulated signal/Synchronizer/SymbolSynchronizer test/main.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/Modulated signal/Synchronizer/SymbolSynchronizer test/main.m -------------------------------------------------------------------------------- /Modulated signal/Synchronizer/SymbolSynchronizer test/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/Modulated signal/Synchronizer/SymbolSynchronizer test/readme.md -------------------------------------------------------------------------------- /Modulated signal/Synchronizer/SymbolSynchronizer test/reference/online 1/Gardner.m: -------------------------------------------------------------------------------- 1 | %File:timing_syn.m timing synchronization 2 | clc 3 | clear 4 | Data_Len = 2000; 5 | 6 | Fs = 3840000*8; % Sampling Frequency 7 | Fd = 3840000; % Symbol Frequency 8 | SNR = 30; % S/N Ratio for Chanel Simulatioin 9 | RolloffCoef = 0.22; % Roll Off Coeff. 10 | T_Gain = 0.02; % TED Loop Gain 11 | 12 | Ratio = Fs/Fd/2; % = Ts/Td/2 13 | Offset = 32; % 14 | 15 | timing_error = 0; 16 | datalen = Fs / Fd * (Data_Len - Offset); 17 | displaysize = 128; 18 | ted_out = zeros(1,displaysize); 19 | Interp_Pos = 2*Ratio + Ratio; 20 | Rec_out = zeros(1,displaysize); 21 | 22 | disp('1 Data Send'); 23 | %1+++++++++++++Data Source+++++++++++++++++++ 24 | disp(' 1.1 Data Source'); 25 | x = (-1).^(rand(1,Data_Len)>0.5) + j * (-1).^(rand(1,Data_Len)>0.5); 26 | 27 | figure(1) 28 | plot(x,'r*'); 29 | xlabel('real') 30 | ylabel('image') 31 | xlim([-2.0 2.0]); 32 | ylim([-2.0 2.0]); 33 | title('Sending Conset') 34 | grid on; 35 | 36 | %+++++++++++++pulse shaping+++++++++++++++++++ 37 | % Using Rolloff Setting 38 | %+++++++++++++++++++++++++++++++++++++++++++++ 39 | disp(' 1.2 Pulse Shaping'); 40 | x_t=rcosflt(x,Fd,Fs,'sqrt',RolloffCoef); 41 | 42 | %+++++++++++++channel simulation++++++++++++++ 43 | % Add White Offsetoise Using SOffsetR Setting 44 | %+++++++++++++++++++++++++++++++++++++++++++++ 45 | disp('2 Channel Simulation'); 46 | c_t = awgn(x_t,SNR,'measured'); 47 | 48 | %++++++++++++++++++receive++++++++++++++++++++ 49 | disp('3 Receive'); 50 | 51 | %4++++++++++Matching Filter++++++++++++++++++++ 52 | disp(' 3.1 Matching Filter'); 53 | %matched_data=rcosflt(r_t,Fd,Fs,'sqrt/Fs',RolloffCoef); 54 | r_t=rcosflt(c_t,Fd,Fs,'sqrt/Fs',RolloffCoef); 55 | matched_data=[r_t(Offset+1:end-Offset)]; 56 | 57 | %++++++++++++Timing Recovery+++++++++++++++++++ 58 | % =======Gardner Timing Recovery=============== 59 | % TE(k)={Y[(k-1)Td]-Y[kTd])*Y[(kTd-Td/2] 60 | % =======Parabolic Interpolation=============== 61 | % C_2 = 0.5 * mu^2 - 0.5 * mu; 62 | % C_1 = -0.5 * mu^2 + ( 0.5 + 1 ) * mu; 63 | % C0 = -0.5 * mu^2 + ( 0.5 - 1 ) * mu + 1; 64 | % C1 = 0.5 * mu^2 - 0.5 * mu; 65 | %+++++++++++++++++++++++++++++++++++++++++++++++ 66 | disp(' 3.2 Timing Recovery'); 67 | C_2 = inline('0.5*u^2-0.5*u'); 68 | C_1 = inline('-0.5*u^2+1.5*u'); 69 | C0 = inline('-0.5*u^2-0.5*u+1'); 70 | C1 = inline('0.5*u^2-0.5*u'); 71 | 72 | ted_data1 = matched_data(Offset); 73 | ted_data2 = matched_data(Offset+Ratio); 74 | 75 | % hp = timing_prefilter(T,Ti,2,beta); 76 | k = 1; 77 | count = 0; 78 | 79 | while( Interp_Pos < ( datalen - 6 ) ) 80 | %++++++++++++The first half++++++++++++++++++ 81 | mk = floor(Interp_Pos); % Integer Part 82 | uk = Interp_Pos-mk; % Fraction Part 83 | 84 | C_2u = C_2(uk); 85 | C_1u = C_1(uk); 86 | C0u = C0(uk); 87 | C1u = C1(uk); 88 | 89 | %+++++++++++++++Get Sampling Data+++++++++++++ 90 | % data1 = matched_data(mk); 91 | % data2 = matched_data(mk+1); 92 | % data3 = matched_data(mk+2); 93 | % data4 = matched_data(mk+3); 94 | 95 | data1 = matched_data(mk-1); 96 | data2 = matched_data(mk); 97 | data3 = matched_data(mk+1); 98 | data4 = matched_data(mk+2); 99 | 100 | %+++++++++++++Interpolation+++++++++++++++++++ 101 | % out = C_2 * in_i(4) + C_1 * in_i(3) + C0 * in_i(2) + C1 * in_i(1); 102 | %+++++++++++++++++++++++++++++++++++++++++++++ 103 | Interp_data = C_2u * data4 + C_1u * data3 + C0u * data2 + C1u * data1; 104 | Rec_out(k) = Interp_data; 105 | ted_data3 = Interp_data; 106 | 107 | Interp_Pos = Interp_Pos + Ratio + timing_error;% 108 | 109 | %++++++++++++++Gardner TED+++++++++++++++++++ 110 | % temp= ( ted_data1 - ted_data3 ) * ted_data2; 111 | %++++++++++++++++++++++++++++++++++++++++++++ 112 | temp = ( ted_data1 - ted_data3 ) * conj(ted_data2); 113 | 114 | %++++++++++++++Loop Filter++++++++++++++++++ 115 | timing_error = real(temp) * T_Gain; 116 | %timing_error = timing_error + real(temp) * T_Gain; 117 | 118 | ted_out(k) = timing_error; 119 | 120 | %+++++++++++++The second half+++++++++++++++ 121 | mk = floor(Interp_Pos); 122 | uk = Interp_Pos-mk 123 | 124 | C_2u = C_2(uk); 125 | C_1u = C_1(uk); 126 | C0u = C0(uk); 127 | C1u = C1(uk); 128 | 129 | %+++++++++++++++Get Sampling Data++++++++++++++ 130 | % data1 = matched_data(mk); 131 | % data2 = matched_data(mk+1); 132 | % data3 = matched_data(mk+2); 133 | % data4 = matched_data(mk+3); 134 | 135 | data1 = matched_data(mk-1); 136 | data2 = matched_data(mk); 137 | data3 = matched_data(mk+1); 138 | data4 = matched_data(mk+2); 139 | %+++++++++++++++++++Interpolation++++++++++++++ 140 | % out = C_2 * in_i(4) + C_1 * in_i(3) + C0 * in_i(2) + C1 * in_i(1); 141 | %++++++++++++++++++++++++++++++++++++++++++++++ 142 | Interp_data = C_2u * data4 + C_1u * data3 + C0u * data2 + C1u * data1; 143 | 144 | %+++Update Sampling Position(NCO Process)++++ 145 | % NewPosition = OldPosition + Fs/Fd/2 + TED 146 | %++++++++++++++++++++++++++++++++++++++++++++ 147 | Interp_Pos = Interp_Pos + Ratio + timing_error; 148 | % timing_error 149 | ted_data1 = ted_data3; 150 | ted_data2 = Interp_data; 151 | 152 | k = k + 1; 153 | count = count + 1; 154 | if count==displaysize 155 | count = 0; 156 | k = 1; 157 | figure(2); 158 | plot(Rec_out,'r*'); 159 | xlabel('real') 160 | ylabel('image') 161 | xlim([-2.0 2.0]); 162 | ylim([-2.0 2.0]); 163 | title('Receiving Conset') 164 | grid on; 165 | 166 | figure(3); 167 | plot(ted_out,'r+'); 168 | ylim([-0.2 0.2]); 169 | title('TED Error') 170 | grid on; 171 | pause(0.1); 172 | end 173 | end 174 | figure(3); 175 | stem(Rec_out); 176 | grid; -------------------------------------------------------------------------------- /Modulated signal/Synchronizer/SymbolSynchronizer test/reference/online 2/gardner.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/Modulated signal/Synchronizer/SymbolSynchronizer test/reference/online 2/gardner.m -------------------------------------------------------------------------------- /Modulated signal/Synchronizer/SymbolSynchronizer test/reference/online 3/main.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/Modulated signal/Synchronizer/SymbolSynchronizer test/reference/online 3/main.m -------------------------------------------------------------------------------- /Modulated signal/Synchronizer/SymbolSynchronizer test/reference/online 4/fourTOtwo.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/Modulated signal/Synchronizer/SymbolSynchronizer test/reference/online 4/fourTOtwo.m -------------------------------------------------------------------------------- /Modulated signal/Synchronizer/SymbolSynchronizer test/reference/online 4/judge.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/Modulated signal/Synchronizer/SymbolSynchronizer test/reference/online 4/judge.m -------------------------------------------------------------------------------- /Modulated signal/Synchronizer/SymbolSynchronizer test/reference/online 4/main.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/Modulated signal/Synchronizer/SymbolSynchronizer test/reference/online 4/main.m -------------------------------------------------------------------------------- /Modulated signal/Synchronizer/SymbolSynchronizer test/reference/online 4/twoTOfour.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/Modulated signal/Synchronizer/SymbolSynchronizer test/reference/online 4/twoTOfour.m -------------------------------------------------------------------------------- /Modulated signal/Synchronizer/SymbolSynchronizer test/some paper/Symbol Synchronization Techniques in Digital Communications/BPSK_Garder/main.m: -------------------------------------------------------------------------------- 1 | clc 2 | clear 3 | close all 4 | %% Data generation 5 | N = 3*10^4; % Number of bits 6 | ip = rand(1,N)>0.5;% Generating 0,1 7 | data = 2*ip-1; 8 | % BPSK modulation 9 | Tsym = 100;% No. of samples per symbol 10 | MSE = zeros(1,5); % A memory for the MSE 11 | BER_sim = zeros(1,5); % A memory for the simulated BER 12 | %% Pulse shape 13 | p = sin(2*pi*(0:Tsym-1)/(2*Tsym));% Sinusoidal wave 14 | %p=rcosdesign(0.5,10,Tsym,'sqrt'); 15 | data_up = zeros(1,length(data)*Tsym);% Creation a memory of zeros 16 | data_up(1:Tsym:end) = data; % Interpolation the data 17 | w = conv(data_up,p);% The convolution operation 18 | %% Noise addition 19 | SNRdB=2:2:10; % Signal to Noise Ratio 20 | SNR=10.^(SNRdB/10) ;% The linear values for the noise 21 | for cv=1:length(SNR) % Generate a loop 22 | noise=sqrt(1/(2*SNR(cv)))*randn(1,length(w)); 23 | % Noise generation 24 | received=w+noise; % Received signal with noise 25 | % received=conv(received1,p); 26 | %% Detection and Correction 27 | tau=0; %Initial value for tau 28 | delta=Tsym/2; %The shifting value before and 29 | %after the midway sample 30 | center=60; %The assumed place for the first 31 | %midway sample 32 | a=zeros(1,N-1); 33 | %A memory of zeros for the 34 | %earlier samples 35 | cenpoint=zeros(1,N-1); 36 | %A memory of zeros for the 37 | %midway samples 38 | remind=zeros(1,N-1); 39 | %A memory of zeros for the remind 40 | avgsamples=6; %Six values of Gardner algorithm 41 | %are used to find the average 42 | stepsize=1; %Correction step size 43 | rit=0; %Iteration counter 44 | GA=zeros(1,avgsamples); %A memory of zeros 45 | tauvector=zeros(1,1900); %A memory of zeros for tau 46 | %vector(2000-100=1900) 47 | uor=0; %A counter for the tau vector 48 | for ii= (Tsym/2)+1:Tsym:length(received)-(Tsym/2) 49 | rit=rit+1; %A counter 50 | midsample=received(center); %The midway sample 51 | latesample=received(center+delta);%The late sample 52 | earlysample=received(center-delta);%The early sample 53 | a(rit)=earlysample; %Save samples 54 | %% Error detection 55 | sub=latesample-earlysample; 56 | %Subtraction process 57 | GA(mod(rit,avgsamples)+1)=sub*midsample; 58 | %Gardner Algorithm 59 | %% Loop filter 60 | if mean(GA) > 0 61 | tau =- stepsize; %Shift by decreasing 62 | else 63 | tau = stepsize; %Shift by increasing 64 | end 65 | %% Safe remind values 66 | cenpoint(rit)=center; %Save positions of 67 | %midway samples 68 | remind(rit)=rem((center-Tsym/2),Tsym); 69 | %Save remind values to find 70 | % convergence plots 71 | %% tau vector 72 | if rit>=100 && rit<2000 %tau vector from 100 to 73 | %2000 where the convergence 74 | uor=uor+1; %happens 75 | tauvector(uor)= (remind(rit)-(Tsym/2)).^2; 76 | %Difference between the 77 | %estimated tau & the 78 | end %optimal tau 79 | %% Correction 80 | center=center+Tsym+tau; %Adding the tau value 81 | if center>=length(received)-(Tsym/2)-1 82 | break; %Break the loop when 83 | %the midway sample reaches 84 | %to 51 samples before 85 | %the last sample 86 | end 87 | end 88 | %% Mean Squared Error (MSE) 89 | MSE(cv)=mean(tauvector); %Finding the Mean Squared Error 90 | %% convergence plot 91 | figure 92 | symbols = 200; 93 | subplot(2,1,1); 94 | plot(remind(1:symbols), '-' ); 95 | hold on 96 | lim1=40*ones(1,symbols); 97 | lim2=60*ones(1,symbols); 98 | plot(lim1); 99 | hold on 100 | plot(lim2); 101 | title( 'Convergence plot for BPSK-Gardner' ); 102 | ylabel( 'tau axis' ), xlabel( 'iterations' ) 103 | legend( [ 'SNRdB=' int2str(SNRdB(cv))]); 104 | axis([1 symbols 0 Tsym]); 105 | subplot(2,1,2); 106 | symbols = 2000; 107 | plot(remind(1:symbols), '-' ); 108 | hold on 109 | plot(lim1); 110 | hold on 111 | plot(lim2); 112 | title( 'Convergence plot for BPSK-Gardner' ); 113 | ylabel( 'tau axis' ), xlabel( 'iterations' ) 114 | legend( [ 'SNRdB=' int2str(SNRdB(cv))]); 115 | axis([1 symbols 0 Tsym]); 116 | %% Calculating the simulated BER 117 | Error=0; %Set the initial value for Error 118 | for k=1:N-1 %Error calculation 119 | if ((a(k)>0 && data(k)==-1)||(a(k)< 0 && data(k)==1)) 120 | Error=Error+1; 121 | end 122 | end 123 | BER_sim(cv)=Error/(N-1); %Calculate error/bit end 124 | end 125 | %% Plot SNR Vs BER 126 | BER_th=(1/2)*erfc(sqrt(2*SNR)/sqrt(2)); %Calculate The 127 | %theoretical BER 128 | figure 129 | semilogy(SNRdB,BER_th, 'k-' , 'LineWidth' ,2); %Plot theoretical BER 130 | hold on 131 | semilogy(SNRdB,BER_sim, 'r-' , 'LineWidth' ,2); %Plot simulated BER 132 | title( 'SNR Vs. BER for BPSK-Gardner technique' ); 133 | legend( 'Theoretical' , 'Simulation' ); ylabel( 'log BER' ); xlabel( 'SNR in dB' ); 134 | -------------------------------------------------------------------------------- /Modulated signal/Synchronizer/SymbolSynchronizer test/some paper/Symbol Synchronization Techniques in Digital Communications/Symbol Synchronization Techniques in Digital Communications.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/Modulated signal/Synchronizer/SymbolSynchronizer test/some paper/Symbol Synchronization Techniques in Digital Communications/Symbol Synchronization Techniques in Digital Communications.pdf -------------------------------------------------------------------------------- /Modulated signal/Synchronizer/SymbolSynchronizer test/symbol rate est/online1/main.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/Modulated signal/Synchronizer/SymbolSynchronizer test/symbol rate est/online1/main.m -------------------------------------------------------------------------------- /Modulated signal/Synchronizer/online1/Gardner_timing.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/Modulated signal/Synchronizer/online1/Gardner_timing.m -------------------------------------------------------------------------------- /Modulated signal/Synchronizer/online1/System.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/Modulated signal/Synchronizer/online1/System.m -------------------------------------------------------------------------------- /Modulated signal/Synchronizer/online1/phase_frequence_recover.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/Modulated signal/Synchronizer/online1/phase_frequence_recover.m -------------------------------------------------------------------------------- /Modulated signal/by_matlab_modulator/OQPSK/main.m: -------------------------------------------------------------------------------- 1 | 2 | clc 3 | clear 4 | close all 5 | 6 | 7 | %% modulate 8 | oqpskmod = comm.OQPSKModulator('BitInput',true); 9 | oqpskdemod = comm.OQPSKDemodulator('BitOutput',true); 10 | channel = comm.AWGNChannel('EbNo',4,'BitsPerSymbol',2); 11 | 12 | %% 13 | errorRate = comm.ErrorRate('ReceiveDelay',2); 14 | 15 | %% 16 | for counter = 1:300 17 | txData = randi([0 1],100,1); 18 | modSig = oqpskmod(txData); 19 | rxSig = channel(modSig); 20 | rxData = oqpskdemod(rxSig); 21 | errorStats = errorRate(txData,rxData); 22 | end 23 | 24 | %% 25 | ber = errorStats(1) 26 | numErrors = errorStats(2) 27 | numBits = errorStats(3) -------------------------------------------------------------------------------- /Modulated signal/by_matlab_modulator/desktop.ini: -------------------------------------------------------------------------------- 1 | [ViewState] 2 | Mode= 3 | Vid= 4 | FolderType=Generic 5 | -------------------------------------------------------------------------------- /Modulated signal/by_matlab_modulator/test/main.m: -------------------------------------------------------------------------------- 1 | clc 2 | clear 3 | close all 4 | 5 | 6 | %% 7 | fc=10e3; 8 | fs=100e3; 9 | f0=1e3; 10 | N=1000; 11 | t=(0:N-1)/fs; 12 | ff=(-N/2:N/2-1)*(fs/N); 13 | %x=2*(randn(1,N)>0)-1; 14 | x=sin(2*pi*f0*t); 15 | y = modulate(x,fc,fs,'am'); 16 | Y=fftshift(fft(y)); 17 | figure 18 | plot(y) 19 | 20 | figure 21 | plot(ff,abs(Y)) -------------------------------------------------------------------------------- /Modulated signal/function/gen_AM.m: -------------------------------------------------------------------------------- 1 | %Generating AM signal 2 | function [y_AM,I_AM,Q_AM]=gen_AM(A,fc,fs,L,m_a,v) 3 | %use orthogonal modulation generate modulated siganl 4 | %You can see the original signal v in the code. 5 | if nargin==0 6 | A=1; %%Ampltitude 7 | fc=1e4; %carrier frequency 8 | fs=1e5; %sample frequency 9 | L=10000; %length of signal 10 | m_a=0.3; %modulation index,|m_a|<1 11 | 12 | end 13 | T=1/fs; %sample time 14 | t=(0:L-1)*T; %time vector 15 | if nargin==0 16 | v=A*cos(2*pi*1000*t); %modulation signal 17 | end 18 | xs=sin(2*pi*fc*t); 19 | xc=cos(2*pi*fc*t); 20 | 21 | I_AM=A+m_a*v; 22 | Q_AM=0; 23 | y_AM=I_AM.*xc+Q_AM.*xs; 24 | 25 | 26 | -------------------------------------------------------------------------------- /Modulated signal/function/gen_ASK2.m: -------------------------------------------------------------------------------- 1 | %Generating 2ASK signal 2 | function [y_2ask,I_ask,Q_ask]=gen_ASK2(A,fc,fs,Rs,L) 3 | %use orthogonal modulation generate modulated siganl 4 | %You can see the original signal v in the code. 5 | if nargin==0 6 | A=1; %%Ampltitude 7 | fc=1e4; %carrier frequency 8 | fs=1e5; %sample frequency 9 | Rs=1e3; %symbol rate of digital signal 10 | L=10000; %length of signal 11 | end 12 | T=1/fs; %sample time 13 | t=(0:L-1)*T; %time vector 14 | xs=sin(2*pi*fc*t); 15 | xc=cos(2*pi*fc*t); 16 | 17 | %2ASK 18 | % _________ ______ 19 | % signal | | | | 20 | %----------| |________| | so L/fs/T_ask is the length of a_n 21 | % <-T_ask-> 22 | %<-----------L points ---------------> 23 | T_ask=1/Rs; 24 | a_n=round(rand(1,round(L/(T_ask*fs)))); 25 | a_ask=repmat(a_n,T_ask*fs,1); 26 | a_ask=a_ask(:)'; 27 | %stairs(a_ask) %figure 2ask,unuse plot 28 | I_ask=0; 29 | Q_ask=a_ask; 30 | y_2ask=I_ask.*xc+Q_ask.*xs; 31 | y_2ask=A*y_2ask; 32 | end 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /Modulated signal/function/gen_OQPSK.m: -------------------------------------------------------------------------------- 1 | function [OQPSK_signal,s_complex,s]=gen_OQPSK(A,fc,fs,Rs,N) 2 | %OQPSK 3 | if nargin==0 4 | A=1; %amplitude 5 | Rs=10e2; %bit ratio 6 | N=1000; %Number of bits to process 7 | fc=10e3; %carrier frequency 8 | fs=10e4; %sample frequency 9 | end 10 | 11 | Ts=1/Rs; 12 | T=1/fs; 13 | t=(0:(round(N*Ts/T)-1))*T; 14 | r=round(Ts/T); 15 | 16 | a=rand(1,N)>0.5; %bit symbol 17 | 18 | %% serial-to-paralle 19 | Idata=a(1:2:end); 20 | Idata=repmat(Idata,2,1); 21 | Idata=Idata(:)'; 22 | 23 | Qdata=a(2:2:end); 24 | Qdata=repmat(Qdata,2,1); 25 | Qdata=Qdata(:)'; 26 | 27 | %% Qdata delay one bit 28 | Qdata=[0,Qdata(1:end-1)]; 29 | 30 | %% Gray coded 31 | % 00->0->5pi/4 32 | % 01->1->7pi/4 33 | % 10->2->3pi/4 34 | % 11->3-> pi/4 35 | two_bits_decimal = [2,1]*[Qdata;Idata]; 36 | phase_code=pi*[5/4,7/4,3/4,1/4]; 37 | phi=phase_code(two_bits_decimal+1); 38 | 39 | phi_sample=repmat(phi,r,1); 40 | phi_sample=phi_sample(:)'; 41 | 42 | %% constellation 43 | j=sqrt(-1); 44 | s=cos(phi)+sin(phi)*j; 45 | 46 | %% carrier wave 47 | xc=cos(2*pi*fc*t); 48 | xs=sin(2*pi*fc*t); 49 | 50 | %% OQPSK 51 | 52 | OQPSK_signal=A*(cos(phi_sample).*xc-sin(phi_sample).*xs); 53 | 54 | s_complex=cos(phi_sample)+sin(phi_sample)*j; 55 | s_complex=A*s_complex; 56 | end -------------------------------------------------------------------------------- /Modulated signal/function/main.m: -------------------------------------------------------------------------------- 1 | clc 2 | clear all 3 | close all 4 | %% parameter 5 | fc=1e4; %carrier frequency 6 | fs=1e5; %sample frequency 7 | Rs=1e3; %symbol rate of digital signal 8 | T=1/fs; %sample time 9 | L=1000; %length of signal 10 | t=(0:L-1)*T; %time vector 11 | A=1; %%Ampltitude 12 | m_a=0.3; 13 | SNR=20; 14 | %% AM 15 | v=A*cos(2*pi*1000*t); 16 | y_AM=gen_AM(A,fc,fs,L,m_a,v); 17 | y_AM=awgn(y_AM,SNR,'measured'); 18 | figure 19 | plot(y_AM) 20 | title('AM') 21 | 22 | %% ASK2 23 | [y_2ask,I,Q]=gen_ASK2(A,fc,fs,Rs,L); 24 | y_2ask=awgn(y_2ask,SNR,'measured'); 25 | figure 26 | plot(y_2ask) 27 | title('2ask') 28 | 29 | %% OQPSK 30 | [OQPSK_signal,s_complex,s]=gen_OQPSK(A,fc,fs,Rs,L); 31 | figure 32 | subplot(3,1,1) 33 | plot(OQPSK_signal);title('OQPSK'); 34 | subplot(3,1,2); 35 | plot(s_complex,'o'); 36 | subplot(3,1,3); 37 | plot(s,'o'); 38 | 39 | %% -------------------------------------------------------------------------------- /Modulated signal/raised_cosine/gen_rcos/main.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/Modulated signal/raised_cosine/gen_rcos/main.m -------------------------------------------------------------------------------- /Modulated signal/raised_cosine/main.m: -------------------------------------------------------------------------------- 1 | % raised cosine function test 2 | clc 3 | clear 4 | close all 5 | 6 | %% 7 | j=sqrt(-1); 8 | rf = 0.6; 9 | span = 6; 10 | sps = 64 ; 11 | 12 | h1 = rcosdesign(rf,span,sps,'sqrt'); % square-root raised cosine 13 | %h1 = rcosdesign(rf,span,sps,'normal');% normal raised cosine FIR filter 14 | %fvtool(h1,'impulse') 15 | figure 16 | subplot(2,1,1) 17 | stem(h1) 18 | title('h') 19 | subplot(2,1,2) 20 | H=abs(fftshift(fft(h1))); 21 | plot(10*log10(H/max(H))) 22 | title('H') 23 | %% gen iq baseband signal 24 | di = 2*randi([0 1], 100, 1) - 1; 25 | di=di*sqrt(2); 26 | dq = 2*randi([0 1], 100, 1) - 1; 27 | dq=dq*sqrt(2); 28 | diq=di+dq*j; 29 | 30 | %% Upsample and filter the data for pulse shaping. 31 | xi = upfirdn(di, h1, sps); 32 | xq = upfirdn(dq, h1, sps); 33 | 34 | %% add noise 35 | ri = xi + randn(size(xi))*0.1; 36 | rq = xq + randn(size(xq))*0.1; 37 | riq=ri+rq*j; 38 | %% Filter and downsample the received signal for matched filtering. 39 | yi = upfirdn(ri, h1, 1, sps); 40 | yq = upfirdn(rq, h1, 1, sps); 41 | xiq=xi+xq*j; 42 | yiq=yi+yq*j; 43 | 44 | %% plot 45 | figure 46 | subplot(4,1,1) 47 | stem(di);title('di') 48 | subplot(4,1,2) 49 | plot(xi);title('xi') 50 | subplot(4,1,3) 51 | plot(ri);title('ri') 52 | subplot(4,1,4) 53 | plot(yi);title('yi') 54 | 55 | %% abs 56 | figure 57 | subplot(4,1,1) 58 | plot(abs(diq)) 59 | subplot(4,1,2) 60 | plot(abs(xiq)) 61 | subplot(4,1,3) 62 | plot(abs(riq)) 63 | subplot(4,1,4) 64 | plot(abs(yiq)) 65 | suptitle('abs') 66 | 67 | %% constellation 68 | figure 69 | subplot(4,1,1) 70 | plot(diq,'kx') 71 | subplot(4,1,2) 72 | plot(xiq,'kx') 73 | subplot(4,1,3) 74 | plot(riq,'kx') 75 | subplot(4,1,4) 76 | plot(yiq,'kx') 77 | suptitle('constellation ') 78 | 79 | %% iq.^n spectrum 80 | figure 81 | subplot(5,1,1) 82 | plot(abs(fftshift(fft(diq)))) 83 | title('n=1') 84 | subplot(5,1,2) 85 | plot(abs(fftshift(fft(diq.^2)))) 86 | title('n=2') 87 | subplot(5,1,3) 88 | plot(abs(fftshift(fft(diq.^3)))) 89 | title('n=3') 90 | subplot(5,1,4) 91 | plot(abs(fftshift(fft(diq.^4)))) 92 | title('n=4') 93 | subplot(5,1,5) 94 | plot(abs(fftshift(fft(diq.^8)))) 95 | title('n=8') 96 | suptitle('spectrum of diq^n') 97 | 98 | 99 | 100 | %% iq .^4 spectrum 101 | figure 102 | subplot(4,1,1) 103 | plot(abs(fftshift(fft(diq.^4)))) 104 | title('Diq') 105 | subplot(4,1,2) 106 | plot(abs(fftshift(fft(xiq.^4)))) 107 | title('Xiq') 108 | subplot(4,1,3) 109 | plot(abs(fftshift(fft(riq.^4)))) 110 | title('Riq') 111 | subplot(4,1,4) 112 | plot(abs(fftshift(fft(yiq.^4)))) 113 | title('Yiq') 114 | suptitle('spectrum of iq^4') -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Signal Processing 2 | ## 简介 3 | 这里主要是matlab实现的各种信号处理算法的demo,2018-2021年会经常更新 4 | 5 | ## 分类 6 | 7 | * [Modulated signal](https://github.com/LHesperus/signal-processing/tree/master/Modulated%20signal) 包含常见调制信号的产生,调制方式识别 8 | * [Modern Digital Signal Processing](https://github.com/LHesperus/signal-processing/tree/master/Modern%20Digital%20Signal%20Processing)现代数字信号处理(电子科技大学)书的课后仿真作业 9 | * [Signals and Systems](https://github.com/LHesperus/signal-processing/tree/master/Signals%20and%20Systems)信号与系统中的一些定理 10 | -------------------------------------------------------------------------------- /Signals and Systems/CIC/main.m: -------------------------------------------------------------------------------- 1 | clc 2 | clear 3 | close all 4 | %% 5 | D=6; 6 | L=100; 7 | h=[ones(1,D),zeros(1,L-D)]; 8 | H=fftshift(fft(h)); 9 | ff=(-L/2:L/2-1)*(2*pi/L); 10 | 11 | figure 12 | subplot(4,1,1) 13 | stem(h);title('h') 14 | subplot(4,1,2) 15 | plot(ff,abs(H));title('H,you can see the max amp is D') 16 | 17 | 18 | %% multi-stage CIC filters 19 | h_m=conv(h,h); 20 | H_m=fftshift(fft(h_m)); 21 | L=length(h_m); 22 | ff=(-L/2:L/2-1)*(2*pi/L); 23 | subplot(4,1,3) 24 | stem(h_m);title('conv(h,h)') 25 | subplot(4,1,4) 26 | plot(ff,abs(H_m));title('Spectrum of conv(h,h)') 27 | suptitle( 'CIC') -------------------------------------------------------------------------------- /Signals and Systems/CIC/resample/main.m: -------------------------------------------------------------------------------- 1 | clc 2 | clear 3 | close all 4 | %% 5 | fs=10e3; 6 | fs0=fs; 7 | f0=1e3; 8 | L=100; 9 | t=(0:L-1)/fs; 10 | x=sin(2*pi*f0*t); 11 | x0=x; 12 | X=fftshift(fft(x)); 13 | %% 14 | ff=(-L/2:L/2-1)*(fs/L); 15 | figure 16 | subplot(2,1,1) 17 | stem(t,x) 18 | subplot(2,1,2) 19 | plot(ff,abs(X)) 20 | suptitle('source signal') 21 | %% 22 | n=2; 23 | x=[x;zeros(n,L)]; 24 | y=reshape(x,1,(n+1)*L); 25 | fs=(n+1)*fs; 26 | L=(n+1)*L; 27 | ff=(-L/2:L/2-1)*(fs/L); 28 | t=(0:L-1)/fs; 29 | 30 | Y=fftshift(fft(y)); 31 | figure 32 | subplot(2,1,1) 33 | stem(t,y) 34 | subplot(2,1,2) 35 | plot(ff,abs(Y)) 36 | suptitle('Interpolation') 37 | 38 | %% CIC 39 | D=n+3; 40 | h=ones(1,D); 41 | y_fil=conv(y,h); 42 | %y_fil=conv(y_fil,h); %% CIC - CIC 43 | Y_fil=fftshift(fft(y_fil)); 44 | y_cic=y_fil(1:D:end); 45 | Y_cic=fftshift(fft(y_cic)); 46 | figure 47 | subplot(2,1,1) 48 | stem(y_fil) 49 | subplot(2,1,2) 50 | stem(y_cic) 51 | 52 | figure 53 | subplot(2,1,1) 54 | plot(abs(Y_fil)) 55 | subplot(2,1,2) 56 | plot(abs(Y_cic)) 57 | 58 | %% equivalent CIC 59 | y_fil2=sum(y(1:1+D)); 60 | for ii=2+D:D:length(Y)-D 61 | y_fil2=[y_fil2, sum(y(ii:ii+D))]; 62 | end 63 | Y_fil2=fftshift(fft(y_fil2)); 64 | figure 65 | stem(y_fil2) 66 | figure 67 | plot(abs(Y_fil2)) 68 | 69 | %% func test 70 | [y,I,D,out_fs_real]=resample_CIC(x0,fs0,fs0/2,1); 71 | Y=fftshift(fft(y)); 72 | stem(y) 73 | figure 74 | plot(abs(Y)) 75 | -------------------------------------------------------------------------------- /Signals and Systems/CIC/resample/resample_CIC.m: -------------------------------------------------------------------------------- 1 | function [y,I,D,out_fs_real]=resample_CIC(xin,in_fs,out_fs,CIC_time) I=10; D=round(I*in_fs/out_fs); x_I=zeros(1,(length(xin)-1)*I+1); x_I(1:I:end)=xin; h=ones(1,min(I,D)); y_fil=conv(x_I,h); if CIC_time==2 y_fil=conv(y_fil,h); %% CIC - CIC end y_cic=y_fil(1:D:end); y=y_cic; out_fs_real=in_fs*I/D; end -------------------------------------------------------------------------------- /Signals and Systems/HPF/main.m: -------------------------------------------------------------------------------- 1 | clc 2 | clear 3 | close all 4 | 5 | %% gen HPF h(n) 6 | L=64; 7 | n=-L/2:L/2-1; 8 | h=zeros(1,L); 9 | 10 | omega=0.5*pi; 11 | h=-sin(omega*n)./(pi*n); 12 | h(L/2+1)=1-omega/pi; 13 | H=fftshift(fft(h)); 14 | 15 | figure 16 | subplot(2,1,1) 17 | stem(h) 18 | subplot(2,1,2) 19 | plot(abs(H)) 20 | 21 | %% gen HPF H 22 | H1=zeros(1,L); 23 | H1(1:round(1/8*L))=1; 24 | H1(round(7/8*L):end)=1; 25 | h1=ifft(ifftshift(H1)); 26 | H11=fftshift(fft(h1)); 27 | h11=ifft(ifftshift(H11)); 28 | 29 | figure 30 | subplot(2,2,1) 31 | plot(H1) 32 | subplot(2,2,2) 33 | stem(real(h1)) 34 | subplot(2,2,3) 35 | plot(abs(H11)) 36 | subplot(2,2,4) 37 | stem(real(h11)) 38 | 39 | 40 | %% 41 | H1=H; 42 | h1=ifft(ifftshift(H1)); 43 | H11=fftshift(fft(h1)); 44 | h11=ifft(ifftshift(H11)); 45 | 46 | figure 47 | subplot(2,2,1) 48 | plot(abs(H1)) 49 | subplot(2,2,2) 50 | stem(real(h1)) 51 | subplot(2,2,3) 52 | plot(abs(H11)) 53 | subplot(2,2,4) 54 | stem(real(h11)) -------------------------------------------------------------------------------- /Signals and Systems/Half-Band filter/halfband.m: -------------------------------------------------------------------------------- 1 | function Hd = halfband 2 | %HALFBAND Returns a discrete-time filter object. 3 | 4 | % MATLAB Code 5 | % Generated by MATLAB(R) 9.4 and DSP System Toolbox 9.6. 6 | % Generated on: 19-Jul-2019 22:18:49 7 | 8 | % FIR Window Halfband lowpass filter designed using the FIRHALFBAND 9 | % function. 10 | 11 | % All frequency values are normalized to 1. 12 | 13 | N = 30; % Order 14 | Beta = 0.5; % Window Parameter 15 | 16 | % Create the window vector for the design algorithm. 17 | win = kaiser(N+1, Beta); 18 | 19 | % Calculate the coefficients using the FIR1 function. 20 | b = firhalfband(N, win); 21 | Hd = dfilt.dffir(b); 22 | 23 | % [EOF] 24 | -------------------------------------------------------------------------------- /Signals and Systems/Half-Band filter/main.m: -------------------------------------------------------------------------------- 1 | clc 2 | clear 3 | close all 4 | %% parameter 5 | Hd = halfband; 6 | h=Hd.Numerator; 7 | H=fftshift(fft(h)); 8 | 9 | %% plot 10 | figure 11 | stem(h) 12 | figure 13 | plot(abs(H)) -------------------------------------------------------------------------------- /Signals and Systems/Initial-value Theorem/main.m: -------------------------------------------------------------------------------- 1 | clc 2 | clear 3 | close all 4 | 5 | %% 6 | j=sqrt(-1); 7 | L=1024; 8 | n=0:L-1; 9 | %f_n=rand(1,L); 10 | f_n=sin(2*pi*0.01*n); 11 | %f_n=f_n-mean(f_n); 12 | F=fftshift(fft(f_n)); 13 | 14 | w=pi*linspace(-1,1,L); 15 | z=exp(j*w); 16 | for ii=1:L 17 | F_z(ii)=sum(f_n.*(z(ii).^n)); 18 | end 19 | 20 | figure 21 | plot(f_n) 22 | figure 23 | plot(abs(F)) 24 | figure 25 | plot(abs(F_z)) 26 | 27 | %% initial value theorem 28 | syms y x 29 | y=cos(x); 30 | z=10000000; 31 | ztrans(y,x,z) -------------------------------------------------------------------------------- /Signals and Systems/LPF/main.m: -------------------------------------------------------------------------------- 1 | clc 2 | clear 3 | close all 4 | 5 | %% gen LPF h(n)->H(omega) 6 | L=1024; 7 | %omega=0.3*pi*(-0.5:1/L:0.5-1/L); 8 | omega=0.1*pi; 9 | n=(-L/2:L/2-1); 10 | h=sin(omega.*n)./(pi*n); 11 | %h=h+0.1*rand(1,L); 12 | 13 | h(L/2+1)=0.1; 14 | H=fftshift(fft(h)); 15 | figure 16 | subplot(2,1,1) 17 | plot(h) 18 | subplot(2,1,2) 19 | plot(abs(H)) 20 | suptitle('h(n)-> H(\omega)') 21 | %% gen LPF H(omega)->h(n) 22 | H1=zeros(1,L); 23 | H1(round(7/16*L):round(9/16*L-1))=1; 24 | h1=ifft(ifftshift(H1)); 25 | H11=fftshift(fft(h1)); 26 | h11=ifft(ifftshift(H11)); 27 | 28 | figure 29 | subplot(2,2,1) 30 | plot(abs(H1)) 31 | subplot(2,2,2) 32 | plot(real(h1)) 33 | title('WHY?') 34 | subplot(2,2,3) 35 | plot(abs(H11)) 36 | subplot(2,2,4) 37 | plot(real(h11)) 38 | suptitle(' H(\omega)-> h(n) ,:h(n) ???') 39 | %% 40 | H1=fftshift(fft(h)); %Similar frequency domains have different time 41 | %domains,WHHY? 42 | h1=ifft(ifftshift(H1)); 43 | H11=fftshift(fft(h1)); 44 | h11=ifft(ifftshift(H11)); 45 | figure 46 | subplot(2,2,1) 47 | plot(abs(H1)) 48 | subplot(2,2,2) 49 | plot(real(h1)) 50 | subplot(2,2,3) 51 | plot(abs(H11)) 52 | subplot(2,2,4) 53 | plot(real(h11)) 54 | suptitle(' H(\omega) of fig 1-> h(n)') 55 | %% fft ifft test 56 | fc=0.1*[0:L-1]/L; 57 | x=sin(2*pi*fc.*n); 58 | X=fftshift(fft(x)); 59 | x1=ifft(ifftshift(X)); 60 | X11=fftshift(fft(x1)); 61 | 62 | figure 63 | subplot(2,2,1) 64 | plot(x) 65 | subplot(2,2,2) 66 | plot(abs(X)) 67 | subplot(2,2,3) 68 | plot(x1) 69 | subplot(2,2,4) 70 | plot(abs(X11)) 71 | suptitle('fft ,ifft ,fftshift,ifftshift test') -------------------------------------------------------------------------------- /Signals and Systems/Nyquist/Variable_Frequency.m: -------------------------------------------------------------------------------- 1 | clc 2 | clear 3 | close all 4 | 5 | %% 6 | L=100000; 7 | %fc=2e3*(0.5:1/L:1.5-1/L); 8 | %fc=1.5e3*(1:1/L:2-1/L); 9 | fc1=10e3; 10 | fs=50e3; 11 | t=(0:L-1)/fs; 12 | fc=4e3*ones(1,L); 13 | fc(round(1/4*L):round(3/4*L))=3e2*t(round(1):round(2/4*L+1))+4e3; 14 | %fc(round(3/4*L):round(4/4*L))=4300; 15 | %x=exp(j*2*pi*fc.*t+j*2*pi*fc1*t); 16 | x=sin(2*pi*fc.*t); 17 | X=fftshift(fft(x)); 18 | ff=(-L/2:L/2-1)*(fs/L); 19 | 20 | figure 21 | subplot(2,1,1) 22 | plot(x) 23 | subplot(2,1,2) 24 | plot(ff,abs(X)) 25 | 26 | figure 27 | plot(fc) 28 | 29 | -------------------------------------------------------------------------------- /Signals and Systems/Nyquist/main.m: -------------------------------------------------------------------------------- 1 | clc 2 | clear 3 | close all 4 | 5 | %% fs>2fc 6 | L=1000; 7 | fc=1e3; 8 | fs=3e3; 9 | t=(0:L-1)/fs; 10 | x=sin(2*pi*fc*t); 11 | X=fftshift(fft(x)); 12 | ff=(-L/2:L/2-1)*(fs/L); 13 | 14 | figure 15 | subplot(2,1,1) 16 | plot(x) 17 | subplot(2,1,2) 18 | plot(ff,abs(X)) 19 | 20 | %% fs = 2fc 21 | L=100; 22 | fc=1e3; 23 | fs=2e3; 24 | t=(0:L-1)/fs; 25 | x=sin(2*pi*fc*t); 26 | X=fftshift(fft(x)); 27 | ff=(-L/2:L/2-1)*(fs/L); 28 | 29 | figure 30 | subplot(2,1,1) 31 | plot(x) 32 | subplot(2,1,2) 33 | plot(ff,abs(X)) 34 | 35 | 36 | %% fs<2fc 37 | L=1000; 38 | fc=1e3; 39 | fs=1e3; 40 | t=(0:L-1)/fs; 41 | x=sin(2*pi*fc*t); 42 | X=fftshift(fft(x)); 43 | ff=(-L/2:L/2-1)*(fs/L); 44 | 45 | figure 46 | subplot(2,1,1) 47 | plot(x) 48 | subplot(2,1,2) 49 | plot(ff,abs(X)) -------------------------------------------------------------------------------- /Signals and Systems/Nyquist/mian2.m: -------------------------------------------------------------------------------- 1 | clc 2 | clear 3 | close all 4 | 5 | %% fs>2fmax 6 | L=1000; 7 | fc=1e3*(1:0.1:2); 8 | fs=10e3; 9 | t=(0:L-1)/fs; 10 | x=sum(sin(2*pi*fc.'*t)); 11 | X=fftshift(fft(x)); 12 | ff=(-L/2:L/2-1)*(fs/L); 13 | 14 | figure 15 | subplot(2,1,1) 16 | plot(x) 17 | subplot(2,1,2) 18 | plot(ff,abs(X)) 19 | 20 | 21 | %% fs=2fmax 22 | L=1000; 23 | fc=1e3*(1:0.1:2); 24 | fs=4e3; 25 | t=(0:L-1)/fs; 26 | x=sum(sin(2*pi*fc.'*t)); 27 | X=fftshift(fft(x)); 28 | ff=(-L/2:L/2-1)*(fs/L); 29 | 30 | figure 31 | subplot(2,1,1) 32 | plot(x) 33 | subplot(2,1,2) 34 | plot(ff,abs(X)) 35 | 36 | %% fs2f_s=[-0.5,0.5] 8 | % 多普勒频率:fd=2v/lambda*sin(theata);归一化:fd/PRF=fd*PRI 9 | % 杂波脊斜率:beta=fd/f_s=2v/d*PRI 10 | %========================================================================== 11 | clc;clear;close all 12 | j=sqrt(-1); 13 | c=3e8; % 光速 14 | %-------------------雷达参数------------------------------------------------ 15 | N=16; % 天线个数 16 | M=16; % 脉冲个数 17 | lambda=c/600e6; % 信号波长 18 | d=lambda/2; % 线阵间隔 19 | PRI=0.1e-3; % 脉冲重复间隔 20 | Vr=200; % 平台速度 21 | beta=2*Vr/d*PRI; % 地杂波脊斜率 22 | %-------------------目标参数----------------------------------------------- 23 | Vtgt=800; % 目标速度 24 | % psi=60/180*pi; % 目标锥角 25 | theta=-30/180*pi; % 目标方位角 26 | Gtgt=10; % 目标匹配滤波后的强度 27 | %-------------------系统性能----------------------------------------------- 28 | Vmax=1/PRI * lambda / 2; 29 | %-------------------构建目标信号------------------------------------------- 30 | SpatialFreqTgt = d./lambda*sin(theta); %归一化空间频率,注:空间采样间隔=d*sin(theta)/c,fc=c/lambda 31 | fdTgt=2*Vtgt/lambda*sin(theta); % 多普勒频率 32 | Stgt=kron(exp(j*2*pi*fdTgt*(0:M-1)*PRI),exp(j*2*pi*(0:N-1)*SpatialFreqTgt));%目标空时导向矢量 33 | X=Gtgt*exp(j*2*pi*(0:N-1)'*SpatialFreqTgt).*exp(j*2*pi*fdTgt*(0:M-1)*PRI);%目标空时矩阵 (N*M) 34 | 35 | Xfft=fftshift(fft(X,1024,1),1); 36 | Xfft=fftshift(fft(Xfft,1024,2),2); 37 | figure 38 | mesh(abs(Xfft)) 39 | title('矩阵行列分别fft后结果') 40 | X=reshape(X,N*M,1);%空时快拍 41 | %===================构建杂波信号=========================================== 42 | %-------------------干扰信号----------------------------------------------- 43 | Gj=10; % 干扰幅度 44 | theta_j=20/180*pi; % 干扰方向 45 | SpatialFreqJ = d./lambda*sin(theta_j); % 空间频率 46 | As=exp(-j*2*pi*(0:N-1)'*SpatialFreqJ); 47 | Ij=Gj*diag(ones(1,M)); 48 | Rj=kron(Ij,conj(As)*As.'); %协方差矩阵(Ward,1995) 49 | 50 | figure 51 | mesh(abs(Rj));title('空时干扰信号协方差矩阵') 52 | %-------------------地杂波------------------------------------------------- 53 | % Rc; 54 | %-------------------高斯噪声----------------------------------------------- 55 | Rn=diag(0.1*ones(1,N*M)); 56 | %-------------------空时功率谱估计------------------------------------------ 57 | 58 | Ri=Rj+Rn; 59 | w=Ri\(Stgt.'); % STAP 最优权 60 | R=X*X'/length(X); 61 | 62 | R=R+Ri; 63 | f_ns=d/lambda*linspace(-1,1,100);%归一化空间频率 64 | f_nt=linspace(-0.5,0.5,100); %归一化多普勒频率 65 | P=zeros(length(f_ns),length(f_nt));Pw1=P; 66 | invR=inv(R); 67 | for ii=1:length(f_ns) 68 | As=exp(-j*2*pi*(0:N-1)*f_ns(ii)); 69 | for jj=1:length(f_nt) 70 | At=exp(-j*2*pi*(0:M-1)*f_nt(jj)); 71 | S=kron(At,As);%空时导向矢量 72 | P(ii,jj)=1/(S*invR*S'); % 信号谱 73 | Pw1(ii,jj) = abs(w'*S')^2; % STAP 74 | end 75 | end 76 | 77 | figure 78 | mesh(abs(P)) 79 | figure 80 | mesh(abs(Pw1)) 81 | -------------------------------------------------------------------------------- /radar/beampattern/RectangularArrayBeamPattern.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/radar/beampattern/RectangularArrayBeamPattern.m -------------------------------------------------------------------------------- /radar/beampattern/ULAbeamPattern1D.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/radar/beampattern/ULAbeamPattern1D.m -------------------------------------------------------------------------------- /radar/beampattern/ULAbeamPattern2D.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/radar/beampattern/ULAbeamPattern2D.m -------------------------------------------------------------------------------- /radar/beampattern/readme.md: -------------------------------------------------------------------------------- 1 | ## 阵列方向图/波束图 2 | 均匀线阵的方向图可以写成以下几种形式. 3 | $F(\theta)=|w^{\rm{H}}a(\theta)|=|\sum_{n=0}^{N-1}{e^{-j\frac{2*\pi *d n}{\lambda}(\sin(\theta)-\sin(\theta_{0}))}}|= |\frac{\sin(N*\pi*d(\sin(\theta)-\sin(\theta_{0})))}{\sin(\pi*d(\sin(\theta)-\sin(\theta_{0})))}|$ 4 | 5 | $w$体现阵列属性 6 | $\boldsymbol a(\theta)$是导向矢量,体现信号属性. 7 | $ \boldsymbol a(\theta)s(n)$相当于各个阵列天线接收的信号,因为这些信号理论上只有相位差不同. 8 | 9 | 均匀线阵的特殊结构使波束图可以通过FFT求得 10 | $|\sum_{n=0}^{N-1}{e^{-j\frac{2*\pi *d n}{\lambda}(\sin(\theta)-\sin(\theta_{0}))}}|$ 11 | 即对$w$进行FFT变换,但要注意的是用FFT求得的数据,横坐标是sin(theta),需要换算成asin,才可以和正常的波束图对应上. 12 | 13 | 14 | 对于二维波束图(增加多普勒频率维),如机载信号处理中STAP, 15 | 二维的要对每个行和列分别做FFT变换. -------------------------------------------------------------------------------- /radar/clutter/clutterRayleigh.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/radar/clutter/clutterRayleigh.m -------------------------------------------------------------------------------- /radar/clutter/genLognormalDistributionRandTest.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/radar/clutter/genLognormalDistributionRandTest.m -------------------------------------------------------------------------------- /radar/clutter/genRicianDistributionRandTest.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/radar/clutter/genRicianDistributionRandTest.m -------------------------------------------------------------------------------- /radar/clutter/genWeibullDistributionRandTest.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/radar/clutter/genWeibullDistributionRandTest.m -------------------------------------------------------------------------------- /radar/clutter/getPDF.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LHesperus/signal-processing/1f73072026fb7bfe8ff8e52ac9095552b316f1f6/radar/clutter/getPDF.m --------------------------------------------------------------------------------