gpt4 book ai didi

matlab - 使用 MATLAB 获取信号的包络

转载 作者:太空宇宙 更新时间:2023-11-03 19:38:10 25 4
gpt4 key购买 nike

我正在尝试提取音频文件的峰值。我有以下代码来提取幅度谱的包络。但是我没有得到所需的输出图。谁能告诉我需要进行哪些调整才能获得正确的图表。这是我的代码:

[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])

This is the graph i get for the above code and im focusing on the "song filtered with edge detector" plot

这是我为上述代码得到的图表,我关注的是“用边缘检测器过滤的歌曲”图

enter image description here

这是我需要得到的“用边缘检测器过滤的歌曲”图

最佳答案

您可以使用希尔伯特变换来获取包络线。从技术上讲,这会返回 analytic signal .您会收到带有以下行的信封:

envelope = abs(hilbert(Song));

希尔伯特变换所做的是采用输入的 fft,将负频率归零,然后进行 ifft。变换的实部是原始信号,虚部是变换后的信号。实部和虚部的绝对值是包络线,自变量(angle(hilbert(Song)))是瞬时相位。

关于matlab - 使用 MATLAB 获取信号的包络,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17780748/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com