戚方 发表于 2012-12-20 15:17

请问matlab改变语音信号频率(改变男女声)?





=wavread('D:\yuyin\lushang.wav');sound(s,Fs,bits)%(回放)y=s(:,2); %处理立体声的一个声道sound(y,2*Fs,bits) %改变播放速度 a=fft(y,n);%傅里叶变换。请问matlab改变语音信号频率(改变男女声)? 听说频谱频域可以,具体代码是?

happy 发表于 2012-12-24 14:27

可以参考下面的程序

function varargout = boy_girl(varargin)
% BOY_GIRL M-file for boy_girl.fig
%      BOY_GIRL, by itself, creates a new BOY_GIRL or raises the existing
%      singleton*.
%
%      H = BOY_GIRL returns the handle to a new BOY_GIRL or the handle to
%      the existing singleton*.
%
%      BOY_GIRL('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in BOY_GIRL.M with the given input arguments.
%
%      BOY_GIRL('Property','Value',...) creates a new BOY_GIRL or raises the
%      existing singleton*.Starting from the left, property value pairs are
%      applied to the GUI before boy_girl_OpeningFcn gets called.An
%      unrecognized property name or invalid value makes property application
%      stop.All inputs are passed to boy_girl_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help boy_girl

% Last Modified by GUIDE v2.5 07-May-2011 12:11:56

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',gui_Singleton, ...
                   'gui_OpeningFcn', @boy_girl_OpeningFcn, ...
                   'gui_OutputFcn',@boy_girl_OutputFcn, ...
                   'gui_LayoutFcn',[] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before boy_girl is made visible.
function boy_girl_OpeningFcn(hObject, ~, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdatareserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to boy_girl (see VARARGIN)

% Choose default command line output for boy_girl
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes boy_girl wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = boy_girl_OutputFcn(~, ~, handles)
% varargoutcell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdatareserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
set(handles.time_edit,'string','10');
set(handles.freq_edit,'string','8000');
% Get default command line output from handles structureoriginal
varargout{1} = handles.output;



function time_edit_Callback(~, ~, ~)
% hObject    handle to time_edit (see GCBO)
% eventdatareserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of time_edit as text
%      str2double(get(hObject,'String')) returns contents of time_edit as a double


% --- Executes during object creation, after setting all properties.
function time_edit_CreateFcn(hObject, ~, ~)
% hObject    handle to time_edit (see GCBO)
% eventdatareserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function freq_edit_Callback(~, eventdata, handles)
% hObject    handle to freq_edit (see GCBO)
% eventdatareserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of freq_edit as text
%      str2double(get(hObject,'String')) returns contents of freq_edit as a double


% --- Executes during object creation, after setting all properties.
function freq_edit_CreateFcn(hObject, ~, ~)
% hObject    handle to freq_edit (see GCBO)
% eventdatareserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in start_pushbutton.
function start_pushbutton_Callback(hObject, ~, handles)
% hObject    handle to start_pushbutton (see GCBO)
% eventdatareserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
freq=str2num(get(handles.freq_edit,'String'));
time=str2num(get(handles.time_edit,'string'));
ai=analoginput('winsound',0);%初始化录音麦克
chanel=addchannel(ai,1);%1表示单声道
set(ai,'SampleRate',freq);
T=time; %录音时间
set(ai,'SamplesPerTrigger',T*freq);
start(ai);
y=0;time=0;
=getdata(ai);%读出相应的数据
handles.y=y;
handles.Fs=freq;
handles.yoriginal=y;
handles.foriginal=freq;
guidata(hObject,handles);
plot(handles.axes1,time,handles.y)%画出声音波形
title(handles.axes1,'时域图');
xlabel(handles.axes1,'时间');
ylabel(handles.axes1,'频率');
set(handles.axes1,'Xgrid','on');
set(handles.axes1,'Ygrid','on');


% --- Executes on selection change in xuanpin_popupmenu.
function xuanpin_popupmenu_Callback(hObject, eventdata, handles)
% hObject    handle to xuanpin_popupmenu (see GCBO)
% eventdatareserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
contents = cellstr(get(handles.xuanpin_popupmenu,'String')) ;%获取listbox1中的细胞矩阵
item=contents{get(handles.xuanpin_popupmenu,'Value')};%获取listbox中的值
if strcmp(item,'自定义')
    prompt={'频率编辑'};

title='请输入频率:';

lines=1;

def={'8000'};

answer=inputdlg(prompt,title,lines,def);
handles.Fs=str2num(answer{1});
guidata(hObject,handles);
else
end
% Hints: contents = cellstr(get(hObject,'String')) returns xuanpin_popupmenu contents as cell array
%      contents{get(hObject,'Value')} returns selected item from xuanpin_popupmenu


% --- Executes during object creation, after setting all properties.
function xuanpin_popupmenu_CreateFcn(hObject, eventdata, handles)
% hObject    handle to xuanpin_popupmenu (see GCBO)
% eventdatareserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in open_pushbutton.
function open_pushbutton_Callback(hObject, eventdata, handles)
% hObject    handle to open_pushbutton (see GCBO)
% eventdatareserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
=uigetfile({'*.wav','ALL FILES(*.*)'},'选择声音文件');
if isequal(,)
    return;
end
strname=;%选择的声音文件路径和文件名
=wavread(strname);%temp表示声音数据 Fs表示频率
handles.y=data;
handles.Fs=Fs;
handles.yoriginal=data;
handles.foriginal=Fs;
guidata(hObject,handles);



% --- Executes on button press in play_pushbutton.
function play_pushbutton_Callback(hObject, eventdata, handles)
% hObject    handle to play_pushbutton (see GCBO)
% eventdatareserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
c=handles.Fs;
contents = cellstr(get(handles.xuanpin_popupmenu,'String')) ;%获取listbox1中的细胞矩阵
item=contents{get(handles.xuanpin_popupmenu,'Value')};%获取listbox中的值
if strcmp(item,'默认频率')
    Fs=c;
elseif strcmp(item,'低频')
    Fs=0.7*c;
elseif strcmp(item,'高频')
    Fs=1.3*c;
else
   Fs=handles.Fs;
end;
    wavplay(handles.y,Fs);
    N=length(handles.y);
    y1=fft(handles.y,N);
    f1=0:Fs/N:Fs*(N-1)/N;
    plot(handles.axes1,f1,handles.y);
    title(handles.axes1,'原始时域图');
    xlabel(handles.axes1,'时间');
    ylabel(handles.axes1,'频率');
    set(handles.axes1,'Xgrid','on');
    set(handles.axes1,'Ygrid','on');
   
   
    plot(handles.axes2,f1(1:N/2),y1(1:N/2));
    set(handles.axes2,'Xgrid','on');
    set(handles.axes2,'Ygrid','on');
    title(handles.axes2,'频谱图');
    xlabel( handles.axes2,'频率');
    ylabel( handles.axes2,'幅度');
   

% --- Executes on button press in yuchuli2_radiobutton.
function yuchuli2_radiobutton_Callback(hObject, eventdata, handles)
% hObject    handle to yuchuli2_radiobutton (see GCBO)
% eventdatareserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of yuchuli2_radiobutton


% --- Executes on button press in yuchuli1_radiobutton.
function yuchuli1_radiobutton_Callback(hObject, eventdata, handles)
% hObject    handle to yuchuli1_radiobutton (see GCBO)
% eventdatareserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
   
% Hint: get(hObject,'Value') returns toggle state of yuchuli1_radiobutton

% --- Executes on selection change in yuchuli3_popupmenu.
function yuchuli3_popupmenu_Callback(hObject, eventdata, handles)
% hObject    handle to yuchuli3_popupmenu (see GCBO)
% eventdatareserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
contents = cellstr(get(handles.xuanpin_popupmenu,'String')) ;%获取listbox1中的细胞矩阵
item=contents{get(handles.xuanpin_popupmenu,'Value')};%获取listbox中的值
if strcmp(item,'低通滤波')
prompt={'请输入滤波上限频率:'};

title='请输入滤波上限频率:';

lines=1;

def={'2000'};

answer=inputdlg(prompt,title,lines,def);
handles.limit=str2num(answer{1});
else
prompt={'请输入滤波下限频率:'};

title='请输入滤波下限频率:';

lines=1;

def={'1000'};

answer=inputdlg(prompt,title,lines,def);
handles.limit=str2num(answer{1});   
end
guidata(hObject,handles);

% Hints: contents = cellstr(get(hObject,'String')) returns yuchuli3_popupmenu contents as cell array
%      contents{get(hObject,'Value')} returns selected item from yuchuli3_popupmenu


% --- Executes during object creation, after setting all properties.
function yuchuli3_popupmenu_CreateFcn(hObject, eventdata, handles)
% hObject    handle to yuchuli3_popupmenu (see GCBO)
% eventdatareserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in chuli_pushbutton.
function chuli_pushbutton_Callback(hObject, eventdata, handles)
% hObject    handle to chuli_pushbutton (see GCBO)
% eventdatareserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
contents = cellstr(get(handles.xuanpin_popupmenu,'String')) ;%获取listbox1中的细胞矩阵
item=contents{get(handles.xuanpin_popupmenu,'Value')};%获取listbox中的值
v1=get(handles.yuchuli1_radiobutton,'value');
v2=get(handles.yuchuli2_radiobutton,'value');
y=handles.y;fs=handles.Fs;
if v1==1
y=y-mean(y);
else
end
if v2==1
    y=detrend(y);
else
end
if strcmp(item,'低通滤波')
    fs=handles.Fs;
    limit=handles.limit-500;
    wp=pi*limit/fs;            %归一化通带数字频率wp
    ws=pi*(limit+200)/fs;%归一化阻带数字截止频率ws
   Rp=0.5;                      %通带波纹系数Rp
   Rs=60;
    =buttord(wp,ws,Rp,Rs); %求阶数N和滤波器截止频率Wn
    =butter(N,Wn);         %传输分子和分母的系数
else
   fs=handles.Fs;
   limit=handles.limit;
   wp=pi*limit/fs;            %归一化通带数字频率wp
   ws=pi*(limit-200)/fs;

   Rp=0.3;                      %通带波纹系数Rp
   Rs=80;
    =buttord(wp,ws,Rp,Rs); %求阶数N和滤波器截止频率Wn
    =butter(N,Wn,'high');         %传输分子和分母的系数
end
    f=filter(num,den,y);                  %滤波
    M=max(size(f));
    s=length(f);
    zh=fft(f,s);            %做FFT变换
    v=0:fs/s:fs*(s-1)/s;%计算频率
    plot(handles.axes3,v(1:M/2),zh(1:M/2))
    set(handles.axes3,'Xgrid','on');
    set(handles.axes3,'Ygrid','on');
    xlabel(handles.axes3,'频率');
    ylabel(handles.axes3,'振幅');
    title(handles.axes3,'滤波后的频谱图');
   
    plot(handles.axes1,v,handles.y);
    title(handles.axes1,'原始时域图');
    xlabel(handles.axes1,'时间');
    ylabel(handles.axes1,'频率');
    set(handles.axes1,'Xgrid','on');
    set(handles.axes1,'Ygrid','on');
   
    N=length(handles.y);
    y1=fft(handles.y,N);
    f1=0:fs/N:fs*(N-1)/N;
    plot(handles.axes2,f1(1:N/2),y1(1:N/2));
    set(handles.axes2,'Xgrid','on');
    set(handles.axes2,'Ygrid','on');
    title(handles.axes2,'频谱图');
    xlabel( handles.axes2,'频率');
    ylabel( handles.axes2,'幅度');
    handles.y=f;
    handles.Fs=fs;
    guidata(hObject,handles);



% --- Executes on button press in close_pushbutton.
function close_pushbutton_Callback(~, ~, ~)
% hObject    handle to close_pushbutton (see GCBO)
% eventdatareserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
close();

% --- Executes on button press in fft_pushbutton.
function fft_pushbutton_Callback(hObject, eventdata, handles)
% hObject    handle to fft_pushbutton (see GCBO)
% eventdatareserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
data=handles.y;
Fs=handles.Fs;
len=max(size(data));%读出声音数据文件的长度
=listdlg('ListString',{'默认长度','128','256','512','1024','2048','4096','8192','16384','32768','65536'},...
'name','选择FFT变换的点数', 'OKstring','确定', ...
'Cancelstring','取消', 'SelectionMode','single','ListSize',);
data_frequency=;
if ok==1
    M=data_frequency(sel);
    y=data(1:M);%取前M个数据做变换
   N=length(y);
   zh=fft(y,N);            %做FFT变换
      f=0:Fs/N:Fs*(N-1)/N;%计算频率
   
plot(handles.axes2,f(1:M/2),zh(1:M/2))
title(handles.axes2,'傅里叶变换图像');
set(handles.axes2,'Xgrid','on');
set(handles.axes2,'Ygrid','on');
xlabel(handles.axes2,'频率');
ylabel(handles.axes2,'振幅');
   
else
end
handles.zh=zh;
guidata(hObject,handles);


% --- Executes on button press in fan_pushbutton.
function fan_pushbutton_Callback(hObject, eventdata, handles)
% hObject    handle to fan_pushbutton (see GCBO)
% eventdatareserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
zh=handles.zh;
y=ifft(zh);
plot(handles.axes3,y);
title(handles.axes3,'反傅里叶变换图像')
xlabel(handles.axes3,'数据序列');
ylabel(handles.axes3,'频率');
set(handles.axes3,'Xgrid','on');
set(handles.axes3,'Ygrid','on');
handles.y=y;
guidata(hObject,handles);


% --- Executes on button press in b2g_pushbutton.
function b2g_pushbutton_Callback(hObject, eventdata, handles)
% hObject    handle to b2g_pushbutton (see GCBO)
% eventdatareserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
      %读取音频信息(双声道,16位,频率44100Hz)
      % 定义常数
    FL = 80;                % 帧长
    WL = 240;               % 窗长
    P = 10;               % 预测系数个数
    data=handles.y;fs=handles.Fs;   % 载入语音数据
        data= data/max(data);        %归一化
    L = length(data);          % 读入语音长度
    FN = floor(L/FL)-2;   % 计算帧数
   
        % 预测和重建滤波器
    exc = zeros(L,1);       % 激励信号(预测误差)
    zi_pre = zeros(P,1);    % 预测滤波器的状态
    s_rec = zeros(L,1);   % 重建语音
    zi_rec = zeros(P,1);
   
        % 合成滤波器
    exc_syn = zeros(L,1);   % 合成的激励信号(脉冲串)
    s_syn = zeros(L,1);   % 合成语音
        last_syn = 0;   %存储上一个(或多个)段的最后一个脉冲的下标
        zi_syn = zeros(P,1);   % 合成滤波器的状态
   
        % 变调不变速滤波器
    exc_syn_t = zeros(L,1);   % 合成的激励信号(脉冲串)
    s_syn_t = zeros(L,1);   % 合成语音
        last_syn_t = 0;   %存储上一个(或多个)段的最后一个脉冲的下标
        zi_syn_t = zeros(P,1);   % 合成滤波器的状态
   
        % 变速不变调滤波器(假设速度减慢一倍)
       
    hw = hamming(WL);       % 汉明窗
   
    % 依次处理每帧语音
    for n = 3:FN

      % 计算预测系数(不需要掌握)
      s_w = data(n*FL-WL+1:n*FL).*hw;    %汉明窗加权后的语音
       = lpc(s_w, P);            %用线性预测法计算P个预测系数
                                        % A是预测系数,E会被用来计算合成激励的能量

      
      
      s_f = data((n-1)*FL+1:n*FL);       % 本帧语音,下面就要对它做处理

      % (4) 用filter函数s_f计算激励,注意保持滤波器状态
                = filter(A,1,s_f,zi_pre);
      
      exc((n-1)*FL+1:n*FL) = exc1; %计算得到的激励

      % (5) 用filter函数和exc重建语音,注意保持滤波器状态
                = filter(1,A,exc1,zi_rec);
      
      s_rec((n-1)*FL+1:n*FL) = s_rec1; %计算得到的重建语音

      % 注意下面只有在得到exc后才会计算正确
      s_Pitch = exc(n*FL-222:n*FL);
      PT = findpitch(s_Pitch);    % 计算基音周期PT(不要求掌握)
      G = sqrt(E*PT);         % 计算合成激励的能量G(不要求掌握)

                     
                %方法3:本段激励只能修改本段长度
                tempn_syn = ';
                exc_syn1 = zeros(length(tempn_syn),1);
                exc_syn1(mod(tempn_syn,PT)==0) = G; %某一段算出的脉冲
                exc_syn1 = exc_syn1((n-1)*FL-last_syn+1:n*FL-last_syn);
                = filter(1,A,exc_syn1,zi_syn);
                exc_syn((n-1)*FL+1:n*FL) =exc_syn1;   %计算得到的合成激励
                s_syn((n-1)*FL+1:n*FL) = s_syn1;   %计算得到的合成语音
                last_syn = last_syn+PT*floor((n*FL-last_syn)/PT);
               
      
      
      % (13) 将基音周期减小一半,将共振峰频率增加150Hz,重新合成语音,听听是啥感受~
                PT1 =floor(PT/2);   %减小基音周期
      poles = roots(A);
                deltaOMG =150*2*pi/fs;
                for p=1:10   %增加共振峰频率,实轴上方的极点逆时针转,下方顺时针转
                        if imag(poles(p))>0 poles(p) = poles(p)*exp(j*deltaOMG);
                        elseif imag(poles(p))<0 poles(p) = poles(p)*exp(-j*deltaOMG);
                        end
                end
                A1=poly(poles);
       
               
                tempn_syn_t = ';
                exc_syn1_t = zeros(length(tempn_syn_t),1);
                exc_syn1_t(mod(tempn_syn_t,PT1)==0) = G; %某一段算出的脉冲
                exc_syn1_t = exc_syn1_t((n-1)*FL-last_syn_t+1:n*FL-last_syn_t);
                = filter(1,A1,exc_syn1_t,zi_syn_t);
                exc_syn_t((n-1)*FL+1:n*FL) =exc_syn1_t;   %计算得到的合成激励
                s_syn_t((n-1)*FL+1:n*FL) = s_syn1_t;   %计算得到的合成语音
                last_syn_t = last_syn_t+PT1*floor((n*FL-last_syn_t)/PT1);
      
    end

   plot(handles.axes3,s_syn_t),
   set(handles.axes3,'Xgrid','on');
   set(handles.axes3,'Ygrid','on');
   xlabel(handles.axes3,'数据序列');
   ylabel(handles.axes3,'频率');
   title(handles.axes3,'变音后的时域图'),XLim();       
   handles.y=s_syn_t;
   guidata(hObject,handles);
   Fs=handles.foriginal;
   N=length(handles.y);
    y1=fft(handles.y,N);
    f1=0:Fs/N:Fs*(N-1)/N;
    plot(handles.axes1,f1,handles.yoriginal);
    title(handles.axes1,'原始时域图');
    xlabel(handles.axes1,'时间');
    ylabel(handles.axes1,'频率');
    set(handles.axes1,'Xgrid','on');
    set(handles.axes1,'Ygrid','on');
   
   
    plot(handles.axes2,f1(1:N/2),y1(1:N/2));
    set(handles.axes2,'Xgrid','on');
    set(handles.axes2,'Ygrid','on');
    title(handles.axes2,'频谱图');
    xlabel( handles.axes2,'频率');
    ylabel( handles.axes2,'幅度');
   pause(3);
        sound(handles.yoriginal);

   sound(handles.y);



   

% --- Executes on button press in g2b_pushbutton.
function g2b_pushbutton_Callback(hObject, eventdata, handles)
% hObject    handle to g2b_pushbutton (see GCBO)
% eventdatareserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
y=handles.y;
fs=handles.Fs;%读取音频信息(双声道,16位,频率44100Hz)
N=length(y)
f=0:fs/N:fs*(N-1)/N;
Y=fft(y,N);                %进行傅立叶变换
plot(handles.axes2,f(1:N/2),Y(1:N/2));
title(handles.axes2,'声音信号的频谱');
xlabel(handles.axes2,'频率');
ylabel(handles.axes2,'振幅');
f1=0:(fs*0.7)/N:(fs*0.7)*(N-1)/N;
syms t;
t=;
R=y*exp(2*pi*300*t);
P=fft(R,N);
Z=ifft(P);
z=real(Z);
handles.y=y;
plot(handles.axes3,f1(1:N/2),Z(1:N/2));
title(handles.axes3,'变声后的时域图');
xlabel(handles.axes3,'时间序列');
ylabel(handles.axes3,'频率')
set(handles.axes3,'Xgrid','on');
set(handles.axes3,'Ygrid','on');

Fs=handles.foriginal;
   N=length(handles.y);
    y1=fft(handles.y,N);
    f1=0:Fs/N:Fs*(N-1)/N;
    plot(handles.axes1,f1,handles.yoriginal);
    title(handles.axes1,'原始时域图');
    xlabel(handles.axes1,'时间');
    ylabel(handles.axes1,'频率');
    set(handles.axes1,'Xgrid','on');
    set(handles.axes1,'Ygrid','on');
   
   
    plot(handles.axes2,f1(1:N/2),y1(1:N/2));
    set(handles.axes2,'Xgrid','on');
    set(handles.axes2,'Ygrid','on');
    title(handles.axes2,'频谱图');
    xlabel( handles.axes2,'频率');
    ylabel( handles.axes2,'幅度');
   pause(3);
guidata(hObject,handles);

sound(handles.yoriginal);

sound(handles.y,handles.foriginal*0.7);

% --- Executes on button press in bijiao_pushbutton.
function bijiao_pushbutton_Callback(hObject, eventdata, handles)
% hObject    handle to bijiao_pushbutton (see GCBO)
% eventdatareserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.y=handles.yoriginal;
handles.Fs=handles.foriginal;
guidata(hObject,handles);

% --- Executes on button press in save_pushbutton.
function save_pushbutton_Callback(hObject, eventdata, handles)
% hObject    handle to save_pushbutton (see GCBO)
% eventdatareserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
Fs=handles.Fs;
data=handles.y;
=uiputfile({'*.wav'},'文件保存');
wavwrite(data,Fs,filename);%data表示声音数据


% 计算一段语音的基音周期
function PT = findpitch(s)
= butter(5, 700/4000);
s = filter(B,A,s);
R = zeros(143,1);
for k=1:143
    R(k) = s(144:223)'*s(144-k:223-k);
end
= max(R(80:143));
T1 = T1 + 79;
R1 = R1/(norm(s(144-T1:223-T1))+1);
= max(R(40:79));
T2 = T2 + 39;
R2 = R2/(norm(s(144-T2:223-T2))+1);
= max(R(20:39));
T3 = T3 + 19;
R3 = R3/(norm(s(144-T3:223-T3))+1);
Top = T1;
Rop = R1;
if R2 >= 0.85*Rop
    Rop = R2;
    Top = T2;
end
if R3 > 0.85*Rop
    Rop = R3;
    Top = T3;
end
PT = Top;
return


happy 发表于 2012-12-24 14:27

还有一段男女声识别程序

%filename:manwoman.m
%different man from woman.
%===========================================================
clear;
if nargin<1;action='initialized';end;
=uigetfile('*.wav','Open Wave File');
file=;
=wavread(file);       % 读入声音文件(*.wav)      
sound(x,fs,bits);                % 数据通过声卡转换为声音
%===========================================================
% pause;
data1=x(:,1);
n=0:length(x)-1;
time=n/fs;
subplot(3,1,1)                                        % 绘制2行1列的第1张子图
plot(time,data1)                                    % 以时间为横轴,数据为纵轴作图
xlabel('Time (sec.)')                                 % 标注横坐标
ylabel('Signal Level (Volts)')                        % 标注纵坐标
grid on                                             % 添加网格
% pause;
% 对采集数据作滤波处理
blocksize =length(data1);                           % 计算窗函数长度
window = hanning(blocksize);                   % 计算汉宁窗函数(此函数为MATLAB自带)
data2=window.*data1;                                  % 对数据先作加窗处理
% wp=;                                             %100Hz--400Hz
% wp=wp*2/fs;
wp=3000*2/fs;
=ellip(4,0.1,20,wp);                      % 构造椭圆滤波器
data=filter(b,a,data2);                               % 求加窗处理后的数据经过滤波器的响应
subplot(3,1,2)                                        % 绘制2行1列的第1张子图
plot(time,data)                                    % 以时间为横轴,数据为纵轴作图
xlabel('Time (sec.)')                                 % 标注横坐标
%ylabel('Signal Level (Volts)')                        % 标注纵坐标
grid on                                             % 添加网格
% pause;
=max(data1);
timewin=floor(0.015*fs);
xwin=data1(index-timewin:index+timewin);
=xcov(xwin);
subplot(3,1,3)
plot(lags,y)
grid on
ylen=length(y);
halflen=(ylen+1)/2 +30;
yy=y(halflen: ylen);
= max(yy);
fmax=fs/(maxindex+30);
disp(['Maximum occurred at ', num2str(fmax), ' Hz'])

戚方 发表于 2012-12-25 22:29

happy 发表于 2012-12-24 14:27 static/image/common/back.gif
还有一段男女声识别程序

先谢谢您,还有点想问地就是第二个程序前面的我都会,变声部分能给我注释一下吗?

happy 发表于 2012-12-29 09:54

戚方 发表于 2012-12-25 22:29 static/image/common/back.gif
先谢谢您,还有点想问地就是第二个程序前面的我都会,变声部分能给我注释一下吗?

第二个是男女生识别,不是变声
主要是求相关性等,你看一下相关命令的帮助文件吧

戚方 发表于 2012-12-29 10:05

happy 发表于 2012-12-29 09:54 static/image/common/back.gif
第二个是男女生识别,不是变声
主要是求相关性等,你看一下相关命令的帮助文件吧

恩,我会相关性分析。通过自相关判断信号基频等区分男女声音。第一个变声是通过什么实现的?频谱搬迁吗?我不会频谱移动,给我段频谱搬迁的程序吧。{:3_53:}

happy 发表于 2012-12-29 10:13

戚方 发表于 2012-12-29 10:05 static/image/common/back.gif
恩,我会相关性分析。通过自相关判断信号基频等区分男女声音。第一个变声是通过什么实现的?频谱搬迁吗? ...

参考第一个程序的b2g_pushbutton_Callback部分
页: [1]
查看完整版本: 请问matlab改变语音信号频率(改变男女声)?