필터 지우기
필터 지우기

audio waves energetic attenuation diagram

조회 수: 2 (최근 30일)
ting po chun
ting po chun 2024년 1월 11일
댓글: ting po chun 2024년 1월 13일
Hi:
I want to convert audio files into images,please refer to the attached picture.
How can i do it?
Thank!

답변 (1개)

Ayush Anand
Ayush Anand 2024년 1월 11일
Hi,
To create a log Power vs. time plot as shown in the picture provided, you could sum the power across all frequencies at each time point to get the total power at that time, and then plot this on a log scale. This could be considered a variant of the common spectogram with frequency domain collapsed, hence the "spectogram" function could be used for the same.
Here's how you can implement this in code:
% Read the Audio File
[audioData, fs] = audioread('sample.wav');
%Since spectogram accepts first argument as vector, ensure audioData is a vector by converting stereo audio to mono if necessary
if size(audioData, 2) == 2
audioData = mean(audioData, 2);
end
% Convert audioData to double if it's not already double
audioData = double(audioData);
% Create the Spectrogram with desired parameters
windowSize = 256; % Window size for the spectrogram
overlap = round(windowSize * 0.75); % Overlap between windows
nfft = 1024; % Number of FFT points
[S, F, T, P] = spectrogram(audioData, windowSize, overlap, nfft, fs);
%Sum the power across all frequencies to get total power at each time point
totalPower = sum(P, 1);
%Create the plot and save it as an image
scatter(T, 10*log10(totalPower));
%... customize the plot
You can refer to the link below to read more on the "spectogram" function:
Hope this helps!
  댓글 수: 6
ting po chun
ting po chun 2024년 1월 13일
thank so much!
ting po chun
ting po chun 2024년 1월 13일
Hi
Did i do something wrong? It seem doens't have two singals
clear
% Read the Audio File
[audioData1, fs] = audioread('聲道式-imp.wav');
%Since spectogram accepts first argument as vector, ensure audioData is a vector by converting stereo audio to mono if necessary
if size(audioData1, 2) == 2
audioData1 = mean(audioData1, 2);
end
% Convert audioData to double if it's not already double
audioData1 = double(audioData1);
% Create the Spectrogram with desired parameters
windowSize = 256; % Window size for the spectrogram
overlap = round(windowSize * 0.75); % Overlap between windows
nfft = 1024; % Number of FFT points
[S, F, T, P1] = spectrogram(audioData1, windowSize, overlap, nfft, fs);
%Sum the power across all frequencies to get total power at each time point
totalPower = sum(P1, 1);
%Create the plot and save it as an image
% scatter(T, 10*log10(totalPower));
%... customize the plot
[audioData2, ~] = audioread('場景式-imp.wav');
if size(audioData2, 2) == 2
audioData2 = mean(audioData2, 2);
end
audioData2 = double(audioData2);
% Create the Spectrogram with desired parameters
windowSize = 256; % Window size for the spectrogram
overlap = round(windowSize * 0.75); % Overlap between windows
nfft = 1024; % Number of FFT points
[S1, F1, T1, P2] = spectrogram(audioData2, windowSize, overlap, nfft, fs);
%Sum the power across all frequencies to get total power at each time point
totalPower1 = sum(P1, 1);
%Create the plot and save it as an image
hold on
scatter(T, 10*log10(totalPower));
scatter(T1, 10*log10(totalPower1));
%... customize the plot
hold off

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by