📄 mainfinal.m
字号:
close all;
clear all;
fs=20e+6; %the sampling frequency
fi=15e+6; %the intermediate frequency
fo=15e+6; %the local frequency
fso=5e+6; %the desired data frequency
b=5e+6; %the bandwidth
T=20e-6; %the pulse width
MM=fs/fso;%the decimation factor
wp=(0.5*b/fs)*2*pi;%the parameter of prototype lowpass filter-the passband cut-off frequency
tb=0.5e+6;%the parameter of prototype lowpass filter-the transition band width
ws=(tb+0.5*b)/fs*2*pi;%the parameter of prototype lowpass filter-the stopband starting frequency
rp=0.30;%the parameter of prototype lowpass filter-the ripple of passband
rs=60; %the parameter of prototype lowpass filter-the ripple of stopband
[signal,tn1,tn2,tn3,tn4]=produce(fs,fi,b,T);%calling the function "produce" to get LFM signal
figure(1)
subplot(2,1,1);
plot(tn4,real(signal),'r')%drawing the waveform of the real part of the LFM signal
xlabel('time(us)'); ylabel('v');
title( 'LFM Waveform');
subplot(2,1,2);
[x,DF1]=db(fs,signal);%calling the function "db" to get spectrum of the LFM signal in db form
w=linspace(0,2*pi,length(DF1));
plot(w,DF1,'r')%drawing the sprctrum of the LFM signal
axis([min(w) max(w) min(DF1) max(DF1)]);
title('Spectrum of the IF signal');
ylabel('dB');grid;
fovi=cos(2*pi*fo/fs*tn3);%getting local frequency-cos
fovq=sin(2*pi*fo/fs*tn3);%getting local frequency-sin
[x,DFovi]=db(fs,fovi);%calling the function "db" to get spectrum of local frequency-cos
[x,DFovq]=db(fs,fovq);%calling the function "db" to get spectrum of local frequency-sin
figure(3)
subplot(2,1,1);
plot(tn4,fovi,'r')%drawing the waveform of the local frequency-cos
title('the waveform of NCO-cos')
subplot(2,1,2);
plot(tn4,fovq,'b')%drawing the waveform of the local frequency-sin
title('the waveform of NCO-sin')
figure(4)
subplot(2,1,1);
plot(x,DFovi,'r')%drawing the spectrum of the local frequency-cos
title('the spectrum of the NCO-cos')
xlabel('MHz');ylabel('dB');grid;
subplot(2,1,2);
plot(x,DFovq,'b')%drawing the spectrum of the local frequency-sin
title('the spectrum of the NCO-sin')
xlabel('MHz');ylabel('dB');grid;
si=signal.*fovi;%demodulating to get the I signal
sq=signal.*fovq;%demodulating to get the Q signal
figure(5)
subplot(2,1,1);
plot(tn4,si,'r')%drawing the waveform of the demodulated I signal
title('the waveform of I' )
subplot(2,1,2);
plot(tn4,sq,'b')%drawing the waveform of the demodulated Q signal
title('the waveform of Q')
figure(6)
subplot(2,1,1);
[x,DFsi]=db(fs,si);%calling the function "db" to get spectrum of the demodulated I signal
plot(x,DFsi,'r')%drawing the spectrum of the demodulated I siganl
title('the spectrum of I' )
ylabel('dB');grid;
subplot(2,1,2);
[x,DFsq]=db(fs,sq);%calling the function "db" to get spectrum of the demodulated Q signal
plot(x,DFsq,'b')%drawing the spectrum of the demodulated Q siganl
title('the spectrum of Q' )
ylabel('dB');grid;
fs=fs/MM;%the sampling frequency has been decimated,it is the desired data rate
[I,Q]=mpfilter(wp,ws,rp,rs,si,sq,MM,tn2);%calling function"mpfilter" to get decimated I,Q
time=0:1/fs:(length(I)-1)/fs;
figure(7)
subplot(2,1,1);
plot(time,I,'r')%drawing the waveform of decimated I signal
axis([min(time) max(time) min(I) max(I)]);
title('waveform of I(result)')
subplot(2,1,2);
plot(time,Q,'b')%drawing the waveform of decimated Q signal
axis([min(time) max(time) min(Q) max(Q)]);
title('waveform of Q(result)')
figure(8)
subplot(2,1,1);
[x,DFI]=db(fs,I);%calling the function "db" to get spectrum of decimated I signal
plot(x,DFI,'r')%drawing the spectrum of decimated I signal
title('spectrum of I(result)')
xlabel('MHz');ylabel('dB');grid;
subplot(2,1,2);
[x,DFQ]=db(fs,Q);%calling the function "db" to get spectrum of decimated Q signal
plot(x,DFQ,'b')%drawing the spectrum of decimated Q signal
title('spectrum of Q(result)')
ylabel('dB');grid;
IQ=I+Q*i;%getting siganl IQ
figure(9)
plot(abs(IQ),'r');%drawing the waveform of signal IQ
title('waveform of IQ');
figure(10)
[x,DFIQ]=db(fs,IQ(10:length(IQ)));%calling the function "db" to get spectrum of signal IQ
%DFIQ=fftshift(DFIQ);
w=linspace(0,2*pi,length(DFIQ));
plot(w,DFIQ,'r');%drawing the spectrum of signal IQ
axis([min(w) max(w) min(DFIQ) max(DFIQ)]);
title('spectrum of IQ')
ylabel('dB');grid;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -