1.
%生成AM信号N = 3000; % 长度fs = 48e3; % 采样率fm = 300; % 调制信号频率Am = 0.5; % 调制信号幅度fc = 8e3; % 载波频率Ac = 1; % 载波幅度A0 = 5/3; % 直流分量t = (0:N-1)'/fs; % 时间tm_t = Am*sin(2*pi*fm*t); % 产生调制信号c_t = Ac*cos(2*pi*fc*t); % 产生载波信号s_t = (m_t + A0) .* c_t; % 调制plot(t, s_t , 'b'); % 绘波形xlabel('time');ylabel('amplitude');
%读取音频文件[y1,Fs] = audioread('MayDay.mp3');%读文件t1=0:1/Fs:(length(y1)-1)*(1/Fs);figure(1)plot(t1,y1);xlabel('t'),ylabel('幅度')title('mayday'),axis([0,(length(y1)-1)*(1/Fs),-0.4,0.5])%sound(y1,Fs);%发出声音%生成AM信号N = length(y1); % 长度fs = Fs; % 采样率fc = 200e3; % 载波频率Ac = 1; % 载波幅度Ma = 0.3;%调制系数y11=abs(y1);max_y11=max(y11);A0 = max_y11/Ma; % 直流分量t = (0:N-1)'/fs; % 时间tc_t = Ac*cos(2*pi*fc*t); % 产生载波信号s_t = (y11 + A0) .* c_t; % 调制figure(2)plot(t, s_t , 'b'); % 绘波形xlabel('time');ylabel('amplitude');
2.
%AM信号解调fs = 48e3; % 采样率fc = 8e3; % 本地振荡器频率phi_c = 0; % 本地振荡器初相fm = 300; % 调制信号频率b = fir1(20, fc/(fs/2)); % 设计截止频率为fc的FIR低通滤波器r_t = s_t;N = length(r_t); % 序列长度t = (0:N-1)'/fs; % 时间tc_t = 2*cos(2*pi*fc*t+phi_c); % 本地振荡器波形figure(1)plot(t, c_t , 'b'); % 绘制本地振荡器波形mix_t = r_t .* c_t; % 混频figure(2)plot(t, mix_t , 'b'); % 绘制混频波形filtered_t = filter(b,1,mix_t); % 滤波figure(3)plot(t, filtered_t , 'b'); % 绘制解调波形demod_t = filtered_t - sum(filtered_t)/length(filtered_t);% 去除DC分量figure(4)plot(t, demod_t , 'b'); % 绘制去除直流分量后的解调波形xlabel('time');ylabel('amplitude');
3.两种绘制功率谱的方式
%绘制功率谱fs = 48e3; % 采样率 L = length(s_t); % 取得序列长度 u = fft(s_t ); % 离散傅里叶变换,求频谱 u_pow = 10*log10(abs(u).^2); % 幅度转为dB w = (0:L-1)'*fs/L; % 横坐标-频率 plot(w, u_pow); % 绘图 grid on; xlabel('frequency(Hz)'); ylabel('magnitude(dB)');
fs = 48e3; % 采样率 psd(spectrum.periodogram, s_t, 'Fs', fs, 'CenterDC', 1); % 谱估计
4.
%产生一个低通滤波器,求幅度响应fs = 48e3; % 采样率 fcut = 5e3; % 截止频率,对于butter来说即-3dB点 filterN = 4; % Butterworth 阶数 [b,a] = butter(filterN, fcut/(fs/2)); % 设计滤波器 freqz(b, a, 512, fs); % 查看频响 x = zeros(128,1); % 产生delta序列 x(1) = 1; y = filter(b, a, x); % 滤波,获取其冲激响应 u = fft(y); % 离散傅里叶变换,求频谱 u_pow = 20*log10(abs(u)); % 幅度转为dB w = (0:length(u)-1)'*fs/length(u); % 横坐标-频率 figure; plot(w,u_pow); % 绘图 grid on; % 显示网格 xlabel('frequency(Hz)'); ylabel('magnitude(dB)');
5.
%相干解调fs = 48e3; % 采样率fc = 4e3; % 本地振荡器频率phi_c = 0; % 本地振荡器初相fm = 110; % 调制信号频率b = fir1(20, fc/(fs/2)); % 设计截止频率为fc% 的FIR低通滤波器r_t = s_t;N = length(r_t); % 序列长度t = (0:N-1)'/fs; % 时间tc_t = cos(2*pi*fc*t+phi_c); % 本地振荡器波形mix_t = r_t .* c_t; % 混频filtered_t = filter(b,1,mix_t); % 滤波demod_t = filtered_t - sum(filtered_t)/length(filtered_t);% 去除DC分量plot(t, demod_t , 'b'); % 绘制解调波形xlabel('time');ylabel('amplitude');
6.
%产生SSB信号m_t2 = hilbert(m_t);c_t = cos(2*pi*fc*t); % 本地振荡器波形c_t2 = sin(2*pi*fc*t); % 本地振荡器波形ssb_t1=m_t.*c_t+m_t2.*c_t2;%下边带ssb_t2=m_t.*c_t-m_t2.*c_t2;%上边带figure(1)plot(t,ssb_t1)title('SSB信号下边带')figure(2)plot(t,ssb_t2)title('SSB信号上边带')u1 = fftshift(fft(ssb_t1 )); % 离散傅里叶变换,求频谱u1_pow = pow2db(abs(u1).^2); % 幅度转为dBw = (0:L-1)'*fs/L - 1/2*fs; % 横坐标-频率figure(3)plot(w, u1_pow);title('SSB信号下边带功率谱')grid on;xlabel('frequency(Hz)');ylabel('F(w)');u2 = fftshift(fft(ssb_t2 )); % 离散傅里叶变换,求频谱u2_pow = pow2db(abs(u2).^2); % 幅度转为dBw = (0:L-1)'*fs/L - 1/2*fs; % 横坐标-频率figure(4)plot(w, u2_pow);title('SSB信号上边带功率谱')grid on;xlabel('frequency(Hz)');ylabel('F(w)');
7.
%包络检波x4=hilbert(s_t);demod_t = x4 - sum(x4)/length(x4);figure(1)plot(t,demod_t);title('解调信号')sound(demod_t,fs)