How to plot (1) amplitude vs time and (2) amplitude vs frequency plots from .wav file

조회 수: 36 (최근 30일)
Hi, I am having some trouble trying to figure out how to plot an Amplitude vs Frequency plot from a .wav file. I think I managed to figure out how to plot the Amplitude vs Time plot though.
Here is my code:
[y,Fs]=audioread('HornC5.wav'); %Reads .wav file into 2 matrices for amplitude (y) and sampling frequency (Fs)
% sound(y,Fs); % see what it sounds like
y=y(:,1); % Converts to a single channel
dt=1/Fs;
t=0:dt:(length(y)*dt)-dt; %Matrix for time points
% I don't really now how to code the Fourier Transform part :(
figure(1)
subplot(2,1,1)
plot(t,y); title('Horn C5'); xlabel('Time (s)'); ylabel('Amplitude'); % Amplitude vs Time plot
subplot(2,1,2)
plot

채택된 답변

Star Strider
Star Strider 2020년 8월 26일
The amplitude - Frequency plot would go something like this:
[y,Fs]=audioread('HornC5.wav'); %Reads .wav file into 2 matrices for amplitude (y) and sampling frequency
L = size(y,1);
Fn = Fs/2;
FTy = fft(y)/L;
Fv = linspace(0, 1, fix(L/2)+1)*Fn;
Iv = 1:numel(Fv);
figure
plot(Fv, abs(FTy(Iv,:))*2)
grid
xlabel('Frequency')
ylabel('Amplitude')
There could be two channels in the .wav file. This will plot both of them in the same plot. Note that ‘Fn’ is the Nyquist frequency, ‘Fv’ is the frequency vector, and ‘Iv’ is the index vector for the plot or other analyses.
I do not have your .wav file so I could not test this with it. It should work.
  댓글 수: 3
Star Strider
Star Strider 2020년 12월 16일
The frequency units (here) are Hz, amplitude is whatever the transducer produced (e.g. mV) or was transformed to (e.g. Pascals if calibrated with respect to Sound pressure level).
It’s complicated!
Gowri R
Gowri R 2022년 12월 19일
Hi,could you please help to plot this waveform as time in xaxis (milliseconds) and amplitude (microvolts) in y axis.

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

추가 답변 (1개)

Sara Boznik
Sara Boznik 2020년 8월 26일
figure(1)
subplot(2,1,1)
plot(t,y); title('Horn C5'); xlabel('Time (s)'); ylabel('Amplitude'); % Amplitude vs Time plot
subplot(2,1,2)
f=1/t
plot(f,y)
I will do it like that.

카테고리

Help CenterFile Exchange에서 Audio I/O and Waveform Generation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by