%For recorded audio signal
clc;clear;close all;
f=22050;
x=audiorecorder(f,16,1);
disp('start');
recordblocking(x,5);
disp('stop');
xr=getaudiodata(x);
sound(xr,fs);
subplot(2,1,1);
plot(xr);
title('Original audio Signal');
xlabel('Time');
ylabel('Frequency(Hz)');
y=fft(xr);
n=length(xr);
ymag=abs(y);
ymagh=ymag(1:n/2);
f=(1:n/2)*fs/n;
subplot(2,1,2);
plot(f,ymagh);
title('Frequency Spectrum');
xlabel('Time');
ylabel('Frequency(Hz)');
%For external audio signal
[x,fs]=audioread('Sampleaudio.mp3');
xr=x(:,1);
subplot(2,1,1);
plot(xr);
title('Original audio Signal');
xlabel('Time');
ylabel('Frequency(Hz)');
y=fft(xr);
n=length(xr);
ymag=abs(y);
ymagh=ymag(1:n/2);
f=(1:n/2)*fs/n;
subplot(2,1,2);
plot(f,ymagh);
title('Frequency Spectrum');
xlabel('Time');
ylabel('Frequency(Hz)');