📄 am_dem.m
字号:
% 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 intervalfc=250; % carrier frequencya=0.85; % Modulation indexfs=1/ts; % sampling frequencyt=[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 signal[M,m,df1]=fftseq(m,ts,df); % Fourier transform f=[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 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(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 env_r=env_phas(r); % envelope, when noise is presentdem2=2*(env_r-1)/a; % demodulate in the presence of noisepause % Press 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 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 signalclfsubplot(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')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')
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -