Digital signal processing big job-based on matlab R2019a male voice to female voice data summary and code

@Digital signal processing big job-based on matlab R2019a male voice to female voice data summary and code

Overview

After referring to a lot of predecessor's information, I found that many functions are outdated, and from the code I downloaded through VIP, the logic of the code is not very clear, there is a lot of nonsense, and the comments are not clear (maybe I am too young I don’t understand it in vain hahahahaha) The original intention of blogging is to summarize the work I have done in the past three days, so that people in the future will feel very happy, hehe!

Look at my folder

Attention, everyone, the matlab code and other related files must be neatly placed, otherwise you will have your hardship in the future, hehehe; I am also Xiaobaihehe, everyone must learn from each other; the first time I write a blog, Ugly typesetting hopes to make more suggestions, and Xiao Zhu bows to everyone!
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

Algorithm principle

I found several, the following is a small note:

  1. Changing the sampling rate of the voice can change the voice. For example, if the sampling rate is lower than 2fh in the Nyquist theorem, high frequency components will be lost, and the sound tone will naturally change. But this will lose information and it is not easy to use parameter control;
  2. This can be achieved by changing the playback speed, 5% faster is a female voice, and 5% slower is a male voice. Remember the Doppler effect? A car with a siren sounds high-pitched when it comes to you, and muffled when it is away from you, which probably means something like this. But obviously, we don't want the input and output sound speed to change, so the user experience is too bad;
  3. Therefore, the tone shift of male and female voices must be spectrum shifting. Comrades who have studied power/signal and systems know that multiplying the cosine function by a cosine function, and integrating the sum difference, will generate sum frequency difference frequency components, and the frequency spectrum will shift. This change is called "modulation". So can we achieve this through this method? No way. It is okay when the power is on, because the frequency of the two multiplied quantities is very different, and the generated signal can be easily filtered out. The distance between male and female voices is very close, and the frequency band is wide, so it cannot be realized by simulation.
  4. Hahaha So at this time it reflects the superiority of digital signal processing. Although the effect I am doing is not very good at present, I believe I can do better, and I will update it later! Some codes use cirshift to move, but it's just a function that makes the spectrum rotate in a fixed range. I really don't understand the use of it. So I finally chose to multiply exp(jwt) in the time domain, but the effect is not good, I don't understand why. This is probably the gap between ideals and reality, indicating that the theory is difficult to implement.

try1.m

clc
[y1,Fs] = audioread('source.wav');  %读出信号,采样率和采样位数。 %注意文件格式要求
%source为男声音频
%sound(y1,Fs);  %播放文件

%设计巴特沃斯低通滤波器  此处加滤波器会使声音变模糊,似乎很重要的高频分量被丢掉了
%Wc1=2*1000/Fs;                                          %男声截止频率 1000Hz
%[b,a]=butter(4,Wc1);
%y1=filter(b,a,y1);

Y1 = fft(y1);%Fast Fourier transform

sigLength=length(y1);%Length of largest array dimension
f=Fs*(1:sigLength)/sigLength;
absY=abs(Y1);%Absolute value and complex magnitude

figure('Name','Measured Data','NumberTitle','off');
%Create figure window
%Specify the Name property again, but this time, set the NumberTitle property to 'off'. 
%The resulting title does not include the figure number.

%绘制男声频域
subplot(2,2,1);plot(f,absY);xlabel('Frequency(Hz)男声频域');grid on

%绘制男声时域
t=(0:sigLength-1)/Fs;%t = 1 / f
subplot(2,2,2);plot(t,y1);xlabel('Time(s)男声时域');grid on

%频谱搬移(时域相移,频域调制)
Y2 = fft(y1 .* exp(1000/(2 * pi) * 1i .* t'));

%绘制女声频域
absY2=abs(Y2);
subplot(2,2,3);plot(f,absY2);xlabel('Frequency(Hz)女声频域');grid on

%绘制女声时域
y2=ifft(Y2);
subplot(2,2,4);plot(t,y2);xlabel('Time(s)女声时域');grid on
y2=abs(y2);%audiowrite必须输入为实数

%失败的滤波器尝试
%BPF = load('LPF_60M.mat');
%y3 = filter(BPF.LPF_60M,1,y2);

%能调通但是效果不好的滤波器尝试
y3=highp(y2,400,500,0.0001,0.02,Fs);

audiowrite('transform30.wav',y3,Fs)
%transform30为生成的文件,它生成的地址不是很确定,会发生变化,
%我还没搞明白,以下是它出现的两个位置:
%C:\Users\honor\Documents\MATLAB\Examples\R2019a\matlab\WriteanAudioFileExample
%E:\\dsp_greatassignment\try
若不清楚可在电脑“开始”里搜一下具体在哪。

The highp function used above, this code is available on many web pages, I copied and pasted it from https://www.cnblogs.com/tkppain/p/6691052.html?utm_source=itdadao&utm_medium=referral and made some changes .

function y=highp(x,f1,f2,rp,rs,Fs)
%高通滤波,该代码鲁棒性很差,试试你就晓得了
%也可能是我不会用
%通带或阻带的截止频率的选取范围是不能超过采样率的一半
%即,f1,f3的值都要小于 Fs/2
%x:需要带通滤波的序列
% f 1:通带截止频率
% f 2:阻带截止频率
%rp:边带区衰减DB数设置
%rs:截止区衰减DB数设置
%FS:序列x的采样频率

wp=2*pi*f1/Fs;
ws=2*pi*f2/Fs;
% 设计切比雪夫滤波器;
[n,wn]=cheb1ord(wp/pi,ws/pi,rp,rs);
[bz1,az1]=cheby1(n,rp,wp/pi,'high');

%查看设计滤波器的曲线
[h,w]=freqz(bz1,az1,256,Fs);
h=20*log10(abs(h));
figure('Name','highpass filter','NumberTitle','off');
plot(w,h);title('所设计滤波器的通带曲线');grid on;
y=filter(bz1,az1,x);
end

% The failed filter tried to use the code downloaded via VIP (the'filter' in the reference code), but it could not be adjusted for some reason. Type fdatool in the MATLAB command line window to pop up the filter design window, but the .fda file is generated after the design is directly saved. It cannot be used directly, and it has to be a .mat file; the .mat file cannot be used directly. You have to use "load('BPF_130M.mat')" in the editor or double-click it in the folder. However, maybe the parameters I exported as a mat file were not selected correctly. It looks the same as the reference code'filter', but it just can't be adjusted. Urgent~~

data

The following are helpful webpages passed by during the difficult and tortuous exploration process.

https://jingyan.baidu.com/article/3052f5a108e14397f21f8658.html
open .mat file

https://wenku.baidu.com/view/cf9f236cbd64783e09122b87.html#
Problems with using fdatool and FIR MegaCore

https://blog.csdn.net/yangming2466/article/details/83548946
Seven filtering methods

https://blog.csdn.net/flypassion/article/details/82082543?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522160343803219724838551089%2522%252C%2522scm%2522%253A%252220140713.130102334...%2522%257D&request_id=257D 160343803219724838551089&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2 all first_rank_v2~rank_v28-1-82082543.first_rank_ecpm_v3_pc_rank_v2&utm_term=%E9%AB%98%E9%80%9A4%E6%BB3%A4%E6%BB %E5%99%A8matlab&spm=1018.2118.3001.4187
filter data

https://www.cnblogs.com/lianjiehere/p/3806964.html
fda file

https://blog.csdn.net/qq_38559814/article/details/86521602
filter
https://www.cnblogs.com/tkppain/p/6691052.html
filter

Guess you like

Origin blog.csdn.net/weixin_46279604/article/details/109252160