1.读取wav音乐文件
% 读取音频文件 filename = 'jay.wav'; [sound_data, fs] = audioread(filename); % 9507502x2 44100 sound_data_1 = sound_data(:, 1); sound_data_1 = sound_data_1'; % 转置
sound_data有两列,因为此音乐文件有两个通道,音频采样率为44100;
这里只使用其中一个通道数据;
将多行数据转置为单行数据,方便后续调制
2.调制
% 调制参数 carrier_freq = 10e3; % 载波频率 modulation_index = 1; % 调制指数 dc = 0; % 直流偏置 % 创建载波信号 t = (0:length(sound_data_1)-1) / fs; carrier = cos(2*pi*carrier_freq*t); % 进行AM调制 sound_data_1 = dc + modulation_index*sound_data_1; %直流偏置,乘以调制指数在偏置 modulated_signal = sound_data_1 .* carrier;
% modulated_signal = awgn(modulated_signal, 10, 'measured'); % 添加高斯白噪声
关于一些参数:
调制指数:也叫调制深度,定义为调制信号振幅与载波振幅之间的比例。调制指数决定了调制信号对载波振幅的影响程度。
3.相干解调
DSB只能使用相干解调
%%%%%%%%%%%%%相干解调%%%%%%%%%%%%% % demodulated_signal = modulated_signal .* carrier; % 理想情况下的相干解调,同频同相 carrier_new = cos(2*pi*carrier_freq*t+pi/4); % 一般情况下的相干解调,有个相位偏移 demodulated_signal = modulated_signal .* carrier_new; % 设计低通滤波器 [b, a] = butter(20, carrier_freq/(fs/2)); % 设计6阶低通滤波器 % 低通滤波 filtered = filter(b, a, demodulated_signal); subplot(2, 1, 1); plot(sound_data_1); subplot(2, 1, 2); plot(filtered); sound(filtered, fs); % fs为采样率
4.FFT分析
%%%%%%%%%%%%%%%%%%%绘图%%%%%%%%%%%%%%%%%% % fft点数 fft_points = length(sound_data_1); %%%%%%%%%%%%%%画原始信号的fft%%%%%%%%%%%%% subplot(4, 1, 1); x1 = fs*(0:(fft_points-1))/fft_points; y1 = abs(fft(sound_data(:, 1), fft_points)); plot(x1, y1); xlabel('Frequency (Hz)'); ylabel('Magnitude'); title('FFT Spectrum'); %%%%%%%%%%%%%%画加了偏置原始信号的fft%%%%%%%%%%%%% subplot(4, 1, 2); x2 = fs*(0:(fft_points-1))/fft_points; y2 = abs(fft(sound_data_1, fft_points)); plot(x2, y2); xlabel('Frequency (Hz)'); ylabel('Magnitude'); title('FFT Spectrum'); %%%%%%%%%%%%%画am调制信号的fft%%%%%%%%%%%%% subplot(4, 1, 3); x3 = fs*(0:(fft_points-1))/fft_points; y3 = abs(fft(modulated_signal, fft_points)); plot(x3, y3); xlabel('Frequency (Hz)'); ylabel('Magnitude'); title('FFT Spectrum'); %%%%%%%%%%%%%画解调调制信号的fft%%%%%%%%%%%%% subplot(4, 1, 4); x4 = fs*(0:(fft_points-1))/fft_points; y4 = abs(fft(demodulated_signal, fft_points)); plot(x4, y4); xlabel('Frequency (Hz)'); ylabel('Magnitude'); title('FFT Spectrum');
5.完整代码
% DSB调制 % 读取音频文件 filename = 'jay.wav'; [sound_data, fs] = audioread(filename); % 9507502x2 44100 sound_data_1 = sound_data(:, 1); sound_data_1 = sound_data_1'; % 转置 % % 调制参数 carrier_freq = 10e3; % 载波频率 modulation_index = 1; % 调制指数 dc = 0; % 直流偏置 % 创建载波信号 t = (0:length(sound_data_1)-1) / fs; carrier = cos(2*pi*carrier_freq*t); % 进行AM调制 sound_data_1 = dc + modulation_index*sound_data_1; %直流偏置,乘以调制指数在偏置 modulated_signal = sound_data_1 .* carrier; modulated_signal = awgn(modulated_signal, 40, 'measured'); % 添加高斯白噪声 %%%%%%%%%%%%%相干解调%%%%%%%%%%%%% % demodulated_signal = modulated_signal .* carrier; % 理想情况下的相干解调,同频同相 carrier_new = cos(2*pi*carrier_freq*t+pi/4); % 一般情况下的相干解调,有个相位偏移 demodulated_signal = modulated_signal .* carrier_new; % 设计低通滤波器 [b, a] = butter(20, carrier_freq/(fs/2)); % 设计6阶低通滤波器 % 低通滤波 filtered = filter(b, a, demodulated_signal); subplot(2, 1, 1); plot(sound_data_1); subplot(2, 1, 2); plot(filtered); sound(filtered, fs); % fs为采样率
6.说明
①、频谱分析
假设调制指数为1,则DSB调制信号在Fc处左右各有一个带宽的基带信号,总共占用带宽为2B【B为基带信号的带宽】
标签:sound,fs,signal,fft,音频文件,carrier,Matlab,wav,data From: https://www.cnblogs.com/judes/p/17539290.html