📄 am.m
字号:
% am.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 durationts=0.001; % sampling intervalfc=250; % carrier frequencysnr=10; % SNR in dB (logarithmic)a=0.85; % Modulation indexfs=1/ts; % sampling frequencyt=[0:ts:t0]; % time vectordf=0.2; % required frequency resolutionsnr_lin=10^(snr/10); % SNR% 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 signal[M,m,df1]=fftseq(m,ts,df); % Fourier transform M=M/fs; % scalingf=[0:df1:df1*(length(m)-1)]-fs/2; % frequency vectoru=(1+a*m_n).*c; % modulated signal[U,u,df1]=fftseq(u,ts,df); % Fourier transform U=U/fs; % scalingsignal_power=spower(u(1:length(t))); % power in modulated signal% power in normalized messagepmn=spower(m(1:length(t)))/(max(abs(m)))^2;eta=(a^2*pmn)/(1+a^2*pmn); % modulation efficiencynoise_power=eta*signal_power/snr_lin; % noise powernoise_std=sqrt(noise_power); % noise standard deviationnoise=noise_std*randn(1,length(u)); % generate noiser=u+noise; % add noise to the modulated signal[R,r,df1]=fftseq(r,ts,df); % Fourier transform R=R/fs; % scalingpause % Press a key to show the modulated signal powersignal_powerpause % Press a key to show the modulation efficiencyetapause % Press any key to see a plot of the messagesubplot(2,2,1)plot(t,m(1:length(t)))axis([0 0.15 -2.1 2.1])xlabel('Time')title('The message signal')pausepause % Press any key to see a plot of the carriersubplot(2,2,2)plot(t,c(1:length(t)))axis([0 0.15 -2.1 2.1])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)))axis([0 0.15 -2.1 2.1])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(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 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(fftshift(U))) title('Signal spectrum')xlabel('Frequency')subplot(2,1,2)plot(f,abs(fftshift(R))) title('Signal and noise spectrum')xlabel('Frequency')
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -