1、线性调制程序AM解调% am-dem.m% Matlab demonstration script for envelope detection. The message signal% is +1 for 0 t t0/3, -2 for t0/3 t 2t0/3 and zero otherwise.echo ont0=.15; % signal durationts=0.001; % sampling interval抽样时间fc=250; % carrier frequency载波频率a=0.85; % Modulation indexfs=1/ts; % sampling frequ
2、ency采样频率t=0:ts:t0; % time vectordf=0.25; % required frequency resolution% message signalm=ones(1,t0/(3*ts),-2*ones(1,t0/(3*ts),zeros(1,t0/(3*ts)+1);c=cos(2*pi*fc.*t); % carrier signalm_n=m/max(abs(m); % normalized message signalM,m,df1=fftseq(m,ts,df); % Fourier transform f=0:df1:df1*(length(m)-1)-f
3、s/2; % frequency vectoru=(1+a*m_n).*c; % modulated signalU,u,df1=fftseq(u,ts,df); % Fourier transform env=env_phas(u); % find the envelope dem1=2*(env-1)/a; % remove dc and rescalesignal_power=spower(u(1:length(t); % power in modulated signalnoise_power=signal_power/100; % noise powernoise_std=sqrt(
4、noise_power); % noise standard deviationnoise=noise_std*randn(1,length(u); % generate noiser=u+noise; % add noise to the modulated signalR,r,df1=fftseq(r,ts,df); % Fourier transform env_r=env_phas(r); % envelope, when noise is presentdem2=2*(env_r-1)/a; % demodulate in the presence of noisepause % P
5、ress any key to see a plot of the messagesubplot(2,1,1)plot(t,m(1:length(t)axis(0 0.15 -2.1 2.1)xlabel(Time)title(The message signal)pause % Press any key to see a plot of the modulated signalsubplot(2,1,2)plot(t,u(1:length(t)axis(0 0.15 -2.1 2.1)xlabel(Time)title(The modulated signal)pause % Press
6、a key to see the envelope of the modulated signalclfsubplot(2,1,1)plot(t,u(1:length(t)axis(0 0.15 -2.1 2.1)xlabel(Time)title(The modulated signal)subplot(2,1,2)plot(t,env(1:length(t)xlabel(Time)title(Envelope of the modulated signal)pause % Press a key to compare the message and the demodulated sign
7、alclfsubplot(2,1,1)plot(t,m(1:length(t)axis(0 0.15 -2.1 2.1)xlabel(Time)title(The message signal)subplot(2,1,2)plot(t,dem1(1:length(t)xlabel(Time)title(The demodulated signal)pause % Press a key to compare in the presence of noise clfsubplot(2,1,1)plot(t,m(1:length(t)axis(0 0.15 -2.1 2.1)xlabel(Time
8、)title(The message signal)subplot(2,1,2)plot(t,dem2(1:length(t)xlabel(Time)title(The demodulated signal in the presence of noise)双边带解调DSB1% dsb1.m% Matlab demonstration script for DSB-AM modulation. The message signal% is +1 for 0 t t0/3, -2 for t0/3 t 2t0/3 and zero otherwise.echo ont0=.15; % signa
9、l durationts=0.001; % sampling intervalfc=250; % carrier frequencysnr=20; % SNR in dB (logarithmic)fs=1/ts; % sampling frequencydf=0.3; % desired freq. resolutiont=0:ts:t0; % time vectorsnr_lin=10(snr/10); % linear SNR% message signalm=ones(1,t0/(3*ts),-2*ones(1,t0/(3*ts),zeros(1,t0/(3*ts)+1);c=cos(
10、2*pi*fc.*t); % carrier signalu=m.*c; % modulated signalM,m,df1=fftseq(m,ts,df); % Fourier transform M=M/fs; % scaling U,u,df1=fftseq(u,ts,df); % Fourier transform U=U/fs; % scalingC,c,df1=fftseq(c,ts,df); % Fourier transformf=0:df1:df1*(length(m)-1)-fs/2; % freq. vectorsignal_power=spower(u(1:length
11、(t); % power in modulated signalnoise_power=signal_power/snr_lin; % compute noise powernoise_std=sqrt(noise_power); % compute noise standard deviationnoise=noise_std*randn(1,length(u); % generate noiser=u+noise; % add noise to the modulated signalR,r,df1=fftseq(r,ts,df); % spectrum of the signal+noi
12、se R=R/fs; % scalingpause % Press a key to show the modulated signal powersignal_powerpause % Press any key to see a plot of the messageclfsubplot(2,2,1)plot(t,m(1:length(t)xlabel(Time)title(The message signal)pause % Press any key to see a plot of the carriersubplot(2,2,2)plot(t,c(1:length(t)xlabel
13、(Time)title(The carrier)pause % Press any key to see a plot of the modulated signalsubplot(2,2,3)plot(t,u(1:length(t)xlabel(Time)title(The modulated signal)pause % Press any key to see a plots of the magnitude of the message and the % modulated signal in the frequency domain.subplot(2,1,1)plot(f,abs
14、(fftshift(M)xlabel(Frequency)title(Spectrum of the message signal)subplot(2,1,2)plot(f,abs(fftshift(U)title(Spectrum of the modulated signal)xlabel(Frequency)pause % Press a key to see a noise samplesubplot(2,1,1)plot(t,noise(1:length(t)title(noise sample) xlabel(Time)pause % Press a key to see the
15、modulated signal and noise subplot(2,1,2)plot(t,r(1:length(t)title(Signal and noise)xlabel(Time)pause % Press a key to see the modulated signal and noise in freq. domainsubplot(2,1,1)plot(f,abs(fftshift(U)title(Signal spectrum)xlabel(Frequency)subplot(2,1,2)plot(f,abs(fftshift(R) title(Signal and no
16、ise spectrum)xlabel(Frequency)DSB2% dsb2.m% Matlab demonstration script for DSB-AM modulation. The message signal% is m(t)=sinc(100t). echo on t0=.2; % signal durationts=0.001; % sampling intervalfc=250; % carrier frequencysnr=20; % SNR in dB (logarithmic)fs=1/ts; % sampling frequencydf=0.3; % requi
17、red freq. resolutiont=-t0/2:ts:t0/2; % time vectorsnr_lin=10(snr/10); % linear SNRm=sinc(100*t); % the message signalc=cos(2*pi*fc.*t); % the carrier signalu=m.*c; % the DSB-AM modulated signalM,m,df1=fftseq(m,ts,df); % Fourier transformM=M/fs; % scalingU,u,df1=fftseq(u,ts,df); % Fourier transformU=
18、U/fs; % scalingf=0:df1:df1*(length(m)-1)-fs/2; % frequency vectorsignal_power=spower(u(1:length(t); % compute modulated signal powernoise_power=signal_power/snr_lin; % compute noise powernoise_std=sqrt(noise_power); % compute noise standard deviationnoise=noise_std*randn(1,length(u); % generate nois
19、e sequencer=u+noise; % add noise to the modulated signalR,r,df1=fftseq(r,ts,df); % Fourier transformR=R/fs; % scalingpause % Press a key to show the modulated signal powersignal_powerpause %Press any key to see a plot of the message clfsubplot(2,2,1)plot(t,m(1:length(t)xlabel(Time)title(The message
20、signal) pause % Press any key to see a plot of the carriersubplot(2,2,2)plot(t,c(1:length(t)xlabel(Time)title(The carrier) pause % Press any key to see a plot of the modulated signalsubplot(2,2,3)plot(t,u(1:length(t)xlabel(Time)title(The modulated signal) pause % Press any key to see a plot of the m
21、agnitude of the message and the % modulated signal in the frequency domain.subplot(2,1,1)plot(f,abs(fftshift(M)xlabel(Frequency)title(Spectrum of the message signal)subplot(2,1,2)plot(f,abs(fftshift(U)title(Spectrum of the modulated signal)xlabel(Frequency) pause % Press a key to see a noise samples
22、ubplot(2,1,1)plot(t,noise(1:length(t)title(noise sample) xlabel(Time)pause % Press a key to see the modulated signal and noisesubplot(2,1,2)plot(t,r(1:length(t)title(Signal and noise)xlabel(Time)pause % Press a key to see the modulated signal and noise in freq. domainsubplot(2,1,1)plot(f,abs(fftshif
23、t(U)title(Signal spectrum)xlabel(Frequency)subplot(2,1,2) plot(f,abs(fftshift(R) title(Signal and noise spectrum)xlabel(Frequency)DSB3% dsb1.m% Matlab demonstration script for DSB-AM modulation. The message signal% is +1 for 0 t t0/3, -2 for t0/3 t 2t0/3 and zero otherwise.echo ont0=.15; % signal du
24、rationts=0.0005; % sampling intervalfc=250; % carrier frequencysnr=10; % SNR in dB (logarithmic)fs=1/ts; % sampling frequencyt_long=20*t0; % extended signal duration n0=floor(t_long/ts)+1; % length of extended signal vector n00=2(ceil(log2(n0);df=fs/n00; % frequency resolutiont_long1=0:ts:t_long; %
25、extended time vectorf=-fs/2+df:df:fs/2; % frequency vector % message signalm=ones(1,t0/(3*ts),-2*ones(1,t0/(3*ts),zeros(1,t0/(3*ts)+1);m_long=m,zeros(1,n0-length(m); % extended message signal c_long=cos(2*pi*fc.*t_long1); % extended carrier signal u_long=m_long.*c_long; % extended modulated signaldu
26、_long=u_long.*c_long;DU=fft(du_long,n00)/fs;M=fft(m_long,n00)/fs; % spectrum of the extended message signal U=fft(u_long,n00)/fs; % spectrum of the extended modulated signal pause % Press any key to see a plots of the magnitude of the message and the % modulated signal in the frequency domain.subplo
27、t(2,1,1)plot(f,abs(fftshift(M)xlabel(Frequency)title(Spectrum of the message signal)subplot(2,1,2)plot(f,abs(fftshift(U)title(Spectrum of the modulated signal)xlabel(Frequency) pause % Press a key to see the modulated and modulated X carrier in freq. domainsubplot(2,1,1)plot(f,abs(fftshift(U)title(M
28、odulated signal spectrum)xlabel(Frequency)subplot(2,1,2)plot(f,abs(fftshift(DU) title(Modulated signal X Carrier spectrum)xlabel(Frequency)DSB DEM% dsb_dem.m% Matlab demonstration script for DSB-AM demodulation. The message signal% is +1 for 0 t t0/3, -2 for t0/3 t 2t0/3 and zero otherwise.echo ont0
29、=.15; % signal durationts=1/1500; % sampling intervalfc=250; % carrier frequencyfs=1/ts; % sampling frequencyt=0:ts:t0; % time vectordf=0.3; % desired frequency resolution% message signalm=ones(1,t0/(3*ts),-2*ones(1,t0/(3*ts),zeros(1,t0/(3*ts)+1);c=cos(2*pi*fc.*t); % carrier signalu=m.*c; % modulated signaly=u.*c; % mixingM,m,df1=fftseq(m,ts,df); % Fourier transform M=M/fs; % scalingU,u,df1=fftseq(u,ts,df); % Fourier transform U=U/fs; % scalingY,y,df1=fftseq(y,ts,df); % Fourier transformY=Y/fs; % scalingf_cutoff=150; % cutoff freq. of the filtern_cutoff=floor(150
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1