Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Speech signal spectrum

[y,fs] = audioread('file_example_WAV_1MG.wav');
N = length(y);
t = (0:N-1/fs);
n = (0:N-1);
y = y(:,1);
% spectral analysis
w = hanning(N, 'periodic');
[X, f] = periodogram(y, w, N, fs, 'power');
X = 20*log10(sqrt(X)*sqrt(2));
% plot the signal spectrum
figure(1);
subplot(2,1,1);
semilogx(f, X, 'r');
xlim([0 max(f)]);
grid on;
set(gca, 'FontName', 'Times New Roman', 'FontSize', 14);
title('Amplitude spectrum of the signal');
xlabel('Frequency, Cycles/Second');
ylabel('Magnitude, dB');
subplot(2,1,2);
semilogx((2*pi*f), X, 'r');
xlim([0 max(2*pi*f)]);
grid on;
set(gca, 'FontName', 'Times New Roman', 'FontSize', 14);
title('Amplitude spectrum of the signal');
xlabel('Angular Frequency, Radian/Sample');
ylabel('Magnitude, dB');
music file spectrum
mp3filename = 'C:\Users\Admin\pigeons-flying-6351.mp3';
wavFileName = 'C:\Users\Admin\apigeons-flying-6351.wav';
signal = audioread(mp3filename);
info = audioinfo(mp3filename);
Fs = info.SampleRate;
audiowrite(wavFileName, signal, Fs);
[y,fs] = audioread('apigeons-flying-6351.wav');
N = length(y);
t = (0:N-1/fs);
n = (0:N-1);
y = y(:,1);
% spectral analysis
w = hanning(N, 'periodic');
[X, f] = periodogram(y, w, N, fs, 'power');
X = 20*log10(sqrt(X)*sqrt(2));
% plot the signal spectrum
figure(1);
subplot(2,1,1);
semilogx(f, X, 'r');
xlim([0 max(f)]);
grid on;
set(gca, 'FontName', 'Times New Roman', 'FontSize', 14);
title('Amplitude spectrum of the signal');
xlabel('Frequency, Cycles/Second');
ylabel('Magnitude, dB');
subplot(2,1,2);
semilogx((2*pi*f), X, 'r');
xlim([0 max(2*pi*f)]);
grid on;
set(gca, 'FontName', 'Times New Roman', 'FontSize', 14);
title('Amplitude spectrum of the signal');
xlabel('Angular Frequency, Radian/Sample');
ylabel('Magnitude, dB');

You might also like