我正在尝试提取音频文件的峰值。我有以下代码来提取幅度谱的包络。但是我没有得到想要的输出图。有人可以告诉我需要进行哪些调整才能获得正确的图表。这是我的代码:
[song,FS] = wavread('c scale fast.wav');
P=20000/44100*FS; % length of filter
N=length(song); % length of song
t=0:1/FS:(N-1)/FS; % define time period
% Plot time domain signal
figure(1);
subplot(3,1,1)
plot(t,(3*abs(song)))
title('Wave File')
ylabel('Amplitude')
xlabel('Length (in seconds)')
xlim([0 1.1])
xlim([0 N/FS])
% Gaussian Filter
x = linspace( -1, 1, P); % create a vector of P values between -1 and 1 inclusive
sigma = 0.335; % standard deviation used in Gaussian formula
myFilter = -x .* exp( -(x.^2)/(2*sigma.^2));% compute first derivative, but leave constants out
myFilter = myFilter / sum( abs( myFilter ) ); % normalize
% Plot Gaussian Filter
subplot(3,1,2)
plot(myFilter)
title('Edge Detection Filter')
% fft convolution
myFilter = myFilter(:); % create a column vector
song(length(song)+length(myFilter)-1) = 0; %zero pad song
myFilter(length(song)) = 0; %zero pad myFilter
edges =ifft(fft(song).*fft(myFilter));
tedges=edges(P/2:N+P/2-1); % shift by P/2 so peaks line up w/ edges
tedges=tedges/max(abs(tedges)); % normalize
% Plot song filtered with edge detector
subplot(3,1,3)
plot(1/FS:1/FS:N/FS,tedges)
title('Song Filtered With Edge Detector')
xlabel('Time (s)')
ylabel('Amplitude')
ylim([-1 1.1])
xlim([0 N/FS])
这是我为上述代码得到的图表,我专注于“用边缘检测器过滤的歌曲”图
这是我需要得到的“用边缘检测器过滤的歌曲”图