1/f amplitude spectrum and slope

6 views (last 30 days)
Hi,
I would like to compute 1/f amplitude spectrum and loglog plot Or log10 .wav files and here is the code which does not work for many reasons. Any help is appreciated.
clear all;
close all;
clc;
[x,Fs] = audioread('*.wav');
Pxx = zeros(129,size(x,2));
for nn = 1:size(x,2)
[Pxx,F] = pwelch(x(:,nn),hamming(128),[],[],Fs,'psd');
end
PSD_x = 1./F(1:end).^2;
figure;
plot(log10(F),10*log10(PSD_x),'r','linewidth',4);
hold on;
plot(log10(F),10*log10(Pxx));
xlabel('loglog(Hz)'); ylabel('loglog(dB)');

Accepted Answer

Mathieu NOE
Mathieu NOE on 23 Feb 2021
hello Mercede
Slightly modified code, simply give it a valid wav file name - it works as can be seen below - or where is your issue ?
clear all;
close all;
clc;
[x,Fs] = audioread('unfiltered_sound.wav'); % my test file name
% Pxx = zeros(129,size(x,2));
for nn = 1:size(x,2)
[Pxx,F] = pwelch(x(:,nn),hamming(128),[],[],Fs,'psd');
end
PSD_x = 1./F(1:end).^2;
figure;
% plot(log10(F),10*log10(PSD_x),'r','linewidth',4);
semilogx(F,10*log10(PSD_x),'r','linewidth',4);
hold on;
semilogx(F,10*log10(Pxx));
% plot(log10(F),10*log10(Pxx));
% xlabel('loglog(Hz)'); ylabel('loglog(dB)');
xlabel('(Hz)'); ylabel('(dB)');
  9 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!