Audio signal modulation, demodulation, noise addition, denoising, filtering, matlab implementation

topic analysis

Realization of modem communication system.

Record a voice signal, perform amplitude modulation and demodulation on it, compare the spectrum of the voice signal at both ends, and play it to see if there is any deviation. On this basis, a noise is added to the modulated speech signal, and then filtered to observe the distortion of the restored speech signal.

The following tasks need to be completed:

  • Collect a voice signal
  • Make the original signal time domain frequency domain diagram
  • Amplitude Modulation of Speech Signal
  • Make the demodulated spectrum
  • Comparison before and after modulation and demodulation
  • Noise added after modulation
  • Demodulation observation comparison

experiment process

Raw signal analysis

This experiment downloads the audio signal in WAV format from the network and cuts its length to 5s for easy processing.

Generally, music and speech signals are binaural signals, and the time domain and spectrograms will have two colors, so a single column should be used for analysis, which is realized by the statement x1=x(:,1).

First use the audioread function to read the audio file to obtain its frequency and other information.

Then use the fft function to find the Fourier transform, then use the abs function to find the magnitude and draw the magnitude spectrum, and then use the plot to draw the spectrum. For the convenience of observation, fftshift can be used to swap it left and right. An interface is_shift is reserved in the experiment. When its value is 1, the images of the whole experiment are transformed by fftshift. Otherwise, it is not done, which is convenient and flexible.

Finally, two graphs of time domain and frequency domain are made.

insert image description here

The spectrogram is drawn above, and you can see the characteristics of the signal more intuitively, including the cutoff frequency and audio range. The audio signal is mainly concentrated in the low frequency band.

amplitude modulation

Here, the frequency normalization is used uniformly, which is convenient for reading the cutoff frequency and setting the carrier frequency from the original signal.

The carrier of a certain frequency is used to perform AM modulation on the signal, and the variable am_f represents the frequency of the carrier signal. After repeated parameter adjustment, it is considered that 0.6 is the most appropriate. Here, 0.6pi is taken as the modulation carrier frequency, which is multiplied by the original signal to realize AM modulation, which is realized here by dot multiplication and transposition matrix.

insert image description here

It can be seen from the figure that the cutoff frequency of the original music signal is 0.2pi (minus one from the symmetric axis of the picture). Here, 0.6pi is set to perform AM modulation on the signal. The modulation of the original signal is equivalent to shifting the spectrum, moving one to the left and one to the right. The purpose of modulation is to facilitate the transmission of signals in the channel. When the modulation frequency is high, the loudness of the sound is low, almost only the sound of zzz can be heard, and the signal is almost completely distorted. When the modulation frequency is low, the sound is sharp and loud, and the tone can be heard, but there is also zzz. sound.

demodulation

  • First, the modulated signal is demodulated: the modulated signal is multiplied by the same carrier wave as in the modulation to realize demodulation, which is realized here by dot multiplication and transposition matrix.

insert image description here

  • Then use the Butterworth filter to filter the demodulated signal: first find the frequency response of the Buttord filter, which uses buttord to find the filter order N and 3dB cut-off frequency wc that meet the performance index, and use butter to calculate the analog filter The transfer function Ha(s) of the device, use freqz to find the frequency response. Then use filter to achieve filtering.
  • Play the modulated, demodulated and filtered sound at the end: Feel the modulation, demodulation and filtering through sound changes.

insert image description here

Firstly, the demodulated time-domain waveform and spectrum diagram are obtained. It can be seen that the demodulated signal does not completely restore the original signal, and will be mixed with a bit of the carrier wave in the modulation process. After filtering, the signal spectrum has been greatly improved. Play the sound and find that the sound after Butterworth filtering is clear, basically the same as the original music, but the music is slightly lower. Butterworth filters are characterized by a smooth frequency response curve in the passband.

Noise

  • Adding random white noise to the signal: first obtain random white noise with an amplitude of 0.05, use the randn statement to generate noise, and then superimpose the noise and the signal modulated by the original signal obtained before.
  • Filter out the noise: I use the Butterworth filter to filter the noise, which uses buttord to find the filter order N and 3dB cut-off frequency wc that meet the performance index, uses butter to find the parameters of the frequency response in the s domain, and uses the bilinear function That is, the bilinear transformation is used to realize the transformation of the frequency response from the s domain to the z domain, and then the filter is used to obtain the filtered signal.

insert image description here

From the figure, we can see the spectrogram of random noise and the time-domain waveform and spectrum after the random noise of the signal. Through playback, we can feel the influence of noise on the signal; after filtering, the noise is greatly improved, the noise becomes smaller, and the original sound is clearer
. , but the Butterworth filter will filter out part of the original signal frequency, and the sound will be a bit muffled.

Attachment: Experimental code

clear;clc;close all;
[x,fs] = audioread('water.wav');%读取音乐信号

%输出频率
fprintf('fs1: %i \n',fs )
%音乐语音信号分声道处理
x_l=x(:,1);
n1=length(x_l);
t1=(0:(n1-1))/fs;%length取数列长度即元素个数

is_shift=1; % 预留接口,下面用来判断频谱是否使用fftshift

%=======================原音频时域/频域图=================================%
figure('NumberTitle', 'off', 'Name', '原音频时域/频域波形图');
%画音乐信号时域图
subplot(2,1,1);plot(t1,x_l);
axis([0,5,-0.5,0.5]);xlabel('时间t');ylabel('幅度');title('音乐时域波形');


%画音乐信号频域图
x_l_fft=fft(x_l,n1);
if is_shift==1 x_l_fft=fftshift(x_l_fft);end;
f1=0:fs/n1:fs*(n1-1)/n1;

subplot(2,1,2);plot(f1,abs(x_l_fft));
axis([0,fs,0,200]);xlabel('频率f');ylabel('幅度');title('音乐信号频谱');

%============================AM调制=======================================%

n=0:n1-1;%所有元素
w=2*f1/fs;%归一化
am_f=0.6;%调制载波频率

%调制
x_cos=cos(n*am_f*pi);%时余弦信号
x_am=x_l.*x_cos';%调制信号
x_cos_fft=fft(x_cos); 
x_am_fft=fft(x_am);
if is_shift==1 x_am_fft=fftshift(x_am_fft);end;

%画出载波和调制信号波形
figure('NumberTitle', 'off', 'Name', 'AM调制图');
subplot(2,2,1);plot(t1,x_cos);
axis([0,0.005,-1,1]);title('余弦信号时域波形');xlabel('时间t');ylabel('幅度');

subplot(2,2,2);plot(w,abs(x_cos_fft));
title('余弦信号频谱');xlabel('w');ylabel('幅度');
subplot(2,2,3);plot(t1,x_am);
axis([0,5,-0.5,0.5]);title('调制信号时域波形');xlabel('时间t');ylabel('幅度');

subplot(2,2,4);plot(w,abs(x_am_fft));
title('调制信号频谱');xlabel('w');ylabel('幅度');

%播放调制信号
%sound(x_l,fs);pause(5);%播放原音乐
%sound(x_am,fs);pause(5);%低频调制播放

%============================解调========================================%

x_am_r=x_am.*x_cos'; %解调信号
x_am_r_fft=fft(x_am_r); %傅里叶变换
if is_shift==1 x_am_r_fft=fftshift(x_am_r_fft);end;

%画解调信号时域波形和频谱
figure('NumberTitle', 'off', 'Name', '解调时域/频域波形图');
subplot(2,1,1);plot(t1,x_am_r);
axis([0,5,-0.5,0.5]);xlabel('时间t');ylabel('幅度');title('解调信号时域波形');

subplot(2,1,2);plot(w,abs(x_am_r_fft));
xlabel('w');ylabel('幅度');title('解调信号频谱');


%巴特沃斯低通滤波器过滤信号,wp<ws为低通滤波器
wp=am_f;%设置通带频率
ws=am_f*1.1; %设置阻带频率
rp=1;%设置通带波纹系数
rs=50; %设置阻带波纹系数    

[N,wc]=buttord(wp,ws,rp,rs); %求满足性能指标的滤波器阶数N和3dB截止频率wc
[b,a]=butter(N,wc); %计算模拟滤波器的传输函数Ha(s)
[Hd,Ww]=freqz(b,a);%求频响

figure('NumberTitle', 'off', 'Name', '解调后滤波图');
subplot(3,1,1);plot(Ww/pi,abs(Hd));
axis([0,1,0,1.5]);xlabel('w/π');ylabel('幅度');title('巴特沃斯频率响应曲线');

%求巴特沃斯滤波器滤波信号
x_am_r_f=filter(b,a,x_am_r);%滤波后的音乐信号
x_am_r_f=x_am_r_f*2;

N3=length(x_am_r_f);
t1=(0:(N3-1))/fs;%时间
f1=0:fs/N3:fs*(N3-1)/N3;%频率
w1=2*f1/fs;%归一化
x_am_r_f_fft=fft(x_am_r_f);%傅里叶变换
if is_shift==1 x_am_r_f_fft=fftshift(x_am_r_f_fft);end;

subplot(3,1,2);plot(t1,x_am_r_f);
axis([0,5,-0.5,0.5]);
xlabel('时间t');ylabel('幅度');title('巴特沃斯滤波信号时域波形');

subplot(3,1,3);plot(w1,abs(x_am_r_f_fft));
xlabel('w');ylabel('幅度');title('巴特沃斯滤波信号频谱');

%sound(x_l,fs);pause(5);%原声音
%sound(x_am_r_f,fs);pause(5);%解调并用巴特沃斯滤波器滤波后的声音 


%============================调制后信号加噪===================================%

%加随机白噪声
x_noise=0.05*randn(n1,1);%噪声占比5%
x_noise_fft=fft(x_noise);%噪声傅里叶变换
if is_shift==1 x_noise_fft=fftshift(x_noise_fft);end;

%X_noise=x1+x_noise;%对调制后信号加随机噪声 
X_noise=x_am+x_noise;%对调制后信号加随机噪声 
X_noise_fft=fft(X_noise);%加噪信号傅里叶变换
if is_shift==1 X_noise_fft=fftshift(X_noise_fft);end;

figure('NumberTitle', 'off', 'Name', '加噪滤波频谱图');

subplot(3,2,1);plot(w,abs(x_noise_fft));
xlabel('w');ylabel('幅度');title('随机白噪声频谱图');

subplot(3,2,2);plot(t1,X_noise);
axis([0,5,-0.5,0.5]);
xlabel('时间t');ylabel('幅度');title('加随机噪声信号时域波形');

subplot(3,2,3);plot(w,abs(X_noise_fft));
xlabel('w');ylabel('幅度');title('加随机噪声信号频谱图');


%=======================含噪信号解调滤波==================================%
%先对含噪调制信号解调
X_noise_r=X_noise.*x_cos'; %解调信号
X_noise_r_fft=fft(X_noise_r); %傅里叶变换
if is_shift==1 X_noise_r_fft=fftshift(X_noise_r_fft);end;

%画解调信号时域波形和频谱
subplot(3,2,4);plot(w,abs(X_noise_r_fft));
xlabel('w');ylabel('幅度');title('含噪调制信号解调频谱');



%再用巴特沃斯滤波器去噪
noise_w = 0.4;
wp=noise_w;ws=noise_w+0.06;Rp=1;Rs=15;
[n1,Wn1]=buttord(wp,ws,Rp,Rs,'s');%求低通滤波器的阶数和截止频率
[bb1,aa1]=butter(n1,Wn1,'s');%求s域的频率响应的参数
[bb2,aa2]=bilinear(bb1,aa1,1);%利用双线性变换实现频率响应s域到z域的变换
%%subplot(3,2,2);plot(abs(bb2),aa2);
%%xlabel('w/π');ylabel('幅度');title('巴特沃斯频率响应曲线');

X_noise_r_f=filter(bb2,aa2,X_noise_r);%求滤随机噪声后的信号
%画滤噪后的图
filter_noisy_fft=fft(X_noise_r_f);
if is_shift==1 filter_noisy_fft=fftshift(filter_noisy_fft);end;

subplot(3,2,5);plot(t1,X_noise_r_f);
axis([0,5,-0.5,0.5]);
xlabel('时间t');ylabel('幅度');title('滤随机噪声后信号时域波形');

subplot(3,2,6);plot(w,abs(filter_noisy_fft));
xlabel('w');ylabel('幅度');title('滤随机噪声后信号频谱');

%播放
%sound(x_l,fs);pause(5);%原音乐
sound(X_noise,fs);pause(5);%加随机噪声
sound(X_noise_r_f,fs);pause(5);%滤随机噪声


Guess you like

Origin blog.csdn.net/weixin_46291251/article/details/122073188
Recommended