Copyright Dhruv Lamba


clc;
close all;
clear all;

[y,Fs,bits] = auread('bird_chirping2.au');

x = y(:,1);

clear y;
N = length(x);

time = [1:N].*(1/Fs);

han = plot(time,x);
xlab = xlabel('Seconds');
ylab = ylabel('Amplitude');
grid on;
set(han,'LineWidth', 2);
set([xlab, ylab],'FontSize', 24, 'FontName', 'Times');
set(gca,'FontSize',20,'FontName','Times','Fontweight','Bold')

% wavwrite(x,Fs,bits,'test.wav');


[X,f] = centeredFFT(x,Fs);


figure;
han1 = plot(f,abs(X));
axis([-8000,8000,0,max(abs(X))]);
grid on;
xlab1=xlabel('Frequency(Hz)');
ylab1=ylabel('|X[k]|');
set(han1,'LineWidth', 2);
set([xlab1, ylab1],'FontSize', 24, 'FontName', 'Times');
set(gca,'FontSize',20,'FontName','Times','Fontweight','Bold')

% sound(x,Fs,bits);

% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %


fc = 2000;
fNorm = fc / ( Fs/2);
[b,a] = butter(10, fNorm, 'low');
x_Low = filtfilt(b, a, x);

figure;
freqz(b,a,bits,Fs/2);
grid on;

% sound(x_Low,Fs,bits);
% wavwrite(x_Low,Fs,bits,'x_Low_.wav');

[X_LOW,f_low] = centeredFFT(x_Low,Fs);


figure;
han2=plot(f_low,abs(X_LOW));
axis([-.8e4,.8e4,0,max(abs(X))]);
grid on;
xlab2=xlabel('Frequency(Hz)');
ylab2=ylabel('|X[k]|)');
set(han2,'LineWidth', 2);
set([xlab2, ylab2],'FontSize', 24, 'FontName', 'Times');
set(gca,'FontSize',20,'FontName','Times','Fontweight','Bold')


figure;
han3=plot(time,x_Low);
grid on;
xlab3=xlabel('Frequency(Hz)');
ylab3=ylabel('|X[k]|)');
set(han3,'LineWidth', 2);
set([xlab3, ylab3],'FontSize', 24, 'FontName', 'Times');
set(gca,'FontSize',20,'FontName','Times','Fontweight','Bold')


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%THIS IS A COOL CUSTOM FFT PLOTTING FUNCTION BY MATHWORKS%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% % function [X,freq]=centeredFFT(x,Fs)
% % %this is a custom function that helps in plotting the two-sided spectrum
% % %x is the signal that is to be transformed
% % %Fs is the sampling rate
% % 
% % N=length(x);
% % 
% % %this part of the code generates that frequency axis
% % if mod(N,2)==0
% %     k=-N/2:N/2-1; % N even
% % else
% %     k=-(N-1)/2:(N-1)/2; % N odd
% % end
% % T=N/Fs;
% % freq=k/T;  %the frequency axis
% % 
% % %takes the fft of the signal, and adjusts the amplitude accordingly
% % X=fft(x)/N; % normalize the data
% % X=fftshift(X); %shifts the fft data so that it is centered


Alumni Liaison

Questions/answers with a recent ECE grad

Ryne Rayburn