close all
clear
clc
centralsample=4096;
N_win=[64 256 1024];
Const_threshold=-50;
Var_threshold=[-70 -40 -20];
%%%%%%%%%%%%%
[y1,f1]=audioread('aeiou.wav');
win=4096;N_window=4096;
frames=floor(size(y1,1)./N_window);
length_data=frames*N_window;
Data_syn=zeros(length_data,1);
centra=centralsample*24;
% legend('y = x','y = cos(x)*x','y = sin(x)*x^{2}');
% specular=stpt_frame(nt_total,win,win,1,centralsample,10.^(-3),fs);
% subplot(2,1,2)
% plot(specular,'k');
% hold on
% title('Spectrum');
% xlabel('Frequency/Hz');
% ylabel('Amplitude');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% stpt_frame function %%%%%%%%%%%%%%%%%%%%
x=y1;w=win;N=win;H=1;threshold=-50;centralsample=centra;
% function y = stpt_frame(x, w, N, H, centralsample,threshold, ~)
% Analysis/synthesis of a sound using the peaks
% of the short-time Fourier transform
% Authors: J. Bonada, X. Serra, X. Amatriain, A. Loscos
% x: A frame from the input sound, w: analysis window (odd size), N: FFT size, H: hop size,
% t: threshold in negative dB, y: output sound
%
%--------------------------------------------------------------------------
% This source code is provided without any warranties as published in
% DAFX book 2nd edition, copyright Wiley & Sons 2011, available at
% http://www.dafx.de. It may be used for educational purposes and not
% for commercial applications without further permission.
%--------------------------------------------------------------------------
% M = length(w); % analysis window size
M = w; % analysis window size
N2 = (N)/2; % size of positive spectrum
soundlength = length(x); % length of input sound aray
hM = (M-1)/2; % half analysis window size
fftbuffer = zeros(N,1); % initialize buffer for FFT
yw = zeros(M,1); % initialize output sound frame
y = zeros(M,1); % initialize output array
% w = w/sum(w); % normalize analysis window
sw = hanning(M); % synthesis window
sw = sw./sum(sw);
pend = centralsample; % last sample to start a frame
pin = pend-M+1; % initialize sound pointer at the middle of analysis window
%while pin<pend
%-----analysis-----%
xw = x(pin:pend).*sw(1:M); % window the input sound
fftbuffer(:) = 0; % reset buffer
fftbuffer(1:(M+1)/2) = xw((M+1)/2:M); % zero-phase fftbuffer
fftbuffer((M+1)/2+1:N) = xw(1:(M-1)/2);
X = fft(fftbuffer); % compute the FFT
mX = 20*log10(abs(X(1:N2))); % magnitude spectrum of positive frequencies
pX = unwrap(angle(X(1:N2))); % unwrapped phase spectrum
plot(mX);
ploc = 1 + find((mX(2:N2-1)>threshold) .* (mX(2:N2-1)>mX(3:N2)) ...
.* (mX(2:N2-1)>mX(1:N2-2))); % peaks
pmag = mX(ploc); % magnitude of peaks
pphase = pX(ploc); % phase of peaks
y=mX;
%-----synthesis-----%
Y = zeros(N,1); % initialize output spectrum
y2=zeros(M,1);
Y(ploc) = 10.^(pmag/20).*exp(1i.*pphase); % generate positive freq.
Y(N+2-ploc) = 10.^(pmag/20).*exp(-1i.*pphase); % generate negative freq.
fftbuffer = real(ifft(Y)); % real part of the inverse FFT
yw((M+1)/2:M) = fftbuffer(1:(M+1)/2); % undo zero phase window
yw(1:(M-1)/2) = fftbuffer(N-(M-1)/2+1:N);
y2(1:M) = y2(1:M) + H*N*sw.*yw(1:M); % overlap-add
% pin = pin+H;
% advance sound pointer
%
%
% subplot(2,1,2)
% plot(y,'k');
% hold on
% title('Spectrum');
% xlabel('Frequency/Hz');
% ylabel('Amplitude');
%%
% end
audiowrite('test.wav',y2,f1);
sound(y2,f1);
音频处理matlab,将原有音频进行抽样后,进行FFT傅里叶变换后再重构,查看IFFT后的变化
需积分: 5 185 浏览量
2024-01-11
09:46:39
上传
评论
收藏 113KB RAR 举报
坤波
- 粉丝: 58
- 资源: 20
最新资源
- 安卓(Android)期末课程设计-新闻阅读客户端.zip
- 安卓(Android)期末课程设计-食谱.rar
- CentOS7 X86-64 mysql客户端安装包,附安装说明
- vue3-ts 编辑svg 合并svg
- 安卓(Android)期末课程设计-购物app.zip
- 安卓(Android)期末课程设计-个人相册.zip
- 在(Linux)ubuntu下通过GTK调用libvlc开发视频播放器.pdf
- SSF3637-VB一款2个P-Channel沟道SOP8的MOSFET晶体管参数介绍与应用说明
- mac mysql-5.7.25-macos10.14-x86-64.dmg
- SSF3402-VB一款N-Channel沟道SOT23的MOSFET晶体管参数介绍与应用说明
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈