mt = sqrt(2) * cos(2 * pi * fm * t); %N0 = 0.01
%AM modulation A = 2;
s_am = (A + mt).* cos(2 * pi * fc * t); B = 2 * fm;
%noise = noise_nb(fc, B, N0, t); %s_am = s_am + noise; figure(1); subplot(311); plot(t, s_am); hold on; plot(t, A + mt, 'r--');
title('AM调制信号及其包络'); xlabel('t');
%AM demodulation
rt = s_am.* cos(2 * pi * fc * t); rt = rt - mean(rt);
%[f, rf] = T2F(t, rt); dt = t(2) - t(1); T = t(end); df = 1/T; N = length(rt);
f = -N/2 * df: df: N/2 * df -df; rf = fft(rt);
rf = T/N * fftshift(rf); % END of T2F
% ==== [t, rt] = lpf(f, rf, B); df = f(2) - f(1); T = 1/df;
hf = zeros(1, length(f));
bf = [-floor(B / df): floor(B / df)] + floor(length(f) / 2); hf(bf) = 1; yf = hf.* rf;
% ==== [t, st] = F2T(f, yf); df = f(2) - f(1);
Fmx = (f(end) - f(1) + df); dt = 1 / Fmx; N = length(yf); T = dt * N;
% ==== t = -T / 2: dt: T/2 -dt; t = 0: dt: T - dt;
sff = ifftshift(yf); st = Fmx * ifft(sff); % ==== END of F2T
rt = real(st); % ==== END of lpf
subplot(312); plot(t, rt); hold on; plot(t, mt/2, 'r--');
title('相干解调后的信号波形与输入信号的比较'); xlabel('t'); subplot(313);
%[t, sf] = T2F(t, s_am); dt = t(2) - t(1); T = t(end); df = 1/T; N = length(s_am);
f = -N/2 * df:df: N/2 * df -df; sf = fft(s_am); sf = T/N * fftshift(sf); % END of T2F
psf = (abs(sf).^2) / T; plot(f, psf);
axis([-2 * fc 2 * fc 0 max(psf)]); title('AM 信号功率谱'); xlabel('f'); >>
实验二 >> clear all; close all; A = 1;
fc = 2; %2Hz N_sample = 8;
N = 500; %码元数 Ts = 1; %1 Baud/s
dt = Ts/fc/N_sample; %波形采样间隔 t = 0: dt: N * Ts - dt; Lt = length(t);
%产生二进制信源 d = sign(randn(1, N));
%dd = sigexpand((d + 1)/2, fc * N_sample); N = length((d + 1)/2); out = zeros(fc * N_sample, N); out(1, :) = d;
dd = reshape(out, 1, fc * N_sample * N); %END of sigexpand
gt = ones(1, fc * N_sample); %NRZ波形 %gt = ones(1, fc * N_sample * N); figure(1);
subplot(221); %输入NRZ信号波形(单极性) d_NRZ = conv(dd, gt); gt = ones(1, length(d_NRZ)); d_NRZ = d_NRZ + gt; d_NRZ = 0.5 * d_NRZ;
plot(t, d_NRZ(1 : length(t))); axis([0 10 0 1.2]); ylabel('输入信号');
subplot(222); %输入NRZ频谱
%[f, d_NRZf] = T2F(t, d_NRZ(1 : length(t))); dt = t(2) - t(1); T = t(end); df = 1/T;
N = length(d_NRZ);
f = -N/2 * df: df: N/2 * df -df; d_NRZf = fft(d_NRZ);
d_NRZf = T/N * fftshift(d_NRZf); %END of T2F
plot(f, 10 * log10(abs(d_NRZf).^2/T)); axis([-2 2 -50 10]);
ylabel('输入信号功率谱密度(dB/Hz)');
%OOK信号
ht = A * cos(2 * pi * fc * t); s_2ask = d_NRZ(1 : Lt) .* ht; subplot(223); plot(t, s_2ask); axis([0 10 -1.2 1.2]); ylabel('ASK');
%[f, s_2askf] = T2F(t, s_2ask); dt = t(2) - t(1); T = t(end); df = 1/T;
N = length(s_2ask);
f = -N/2 * df: df: N/2 * df -df; s_2askf = fft(s_2ask);
s_2askf = T/N * fftshift(s_2askf); %END of T2F
subplot(224);
plot(f, 10 * log10(abs(s_2askf).^2/T)); axis([-6 6 -50 10]);
ylabel('ASK功率谱密度(dB/Hz)'); figure(2); %2PSK信号
d_2psk = 2 * d_NRZ - 1; s_2psk = d_2psk(1 : Lt) .* ht; subplot(221); plot(t, s_2psk); axis([0 10 -1.2 1.2]); ylabel('2PSK');
subplot(222);
%[f, s_2pskf] = T2F(t, s_2psk); dt = t(2) - t(1); T = t(end); df = 1/T;
N = length(s_2psk);
f = -N/2 * df: df: N/2 * df -df;
s_2pskf = fft(s_2psk);
s_2pskf = T/N * fftshift(s_2pskf); %END of T2F
plot(f, 10 * log10(abs(s_2pskf).^2/T)); axis([-6 6 -50 10]);
ylabel('2PSK功率谱密度(dB/Hz)');
%2FSK信号
sd_2fsk = 2 * d_NRZ - 1;
s_2fsk = A * cos(2 * pi * fc * t + 2 * pi * sd_2fsk(1 : length(t)) .* t);
subplot(223); plot(t, s_2fsk); axis([1 10 -1.2 1.2]); xlabel('t'); ylabel('2FSK'); subplot(224);
%[f, s_2fskf] = T2F(t, s_2fsk); dt = t(2) - t(1); T = t(end); df = 1/T;
N = length(s_2fsk);
f = -N/2 * df: df: N/2 * df -df; s_2fskf = fft(s_2fsk);
s_2fskf = T/N * fftshift(s_2fskf); %END of T2F
plot(f, 10 * log10(abs(s_2fskf).^2/T)); axis([-6 6 -50 10]); xlabel('f');
ylabel('2FSK功率谱密度(dB/Hz)'); >>
因篇幅问题不能全部显示,请点此查看更多更全内容