SlideShare a Scribd company logo
1 of 12
Contents
 Matlab Code:
 signal into left and right, stereo records
 time for right signal only (stereo) for original signals
 find new length
 find new time
 find new frequency
 perform fft and plot of the cut orignal signal
 Zoom in to signal baseline noise signal
 plot two signals
 plot fft compare
 calculate and compare two signals
 corlation
Matlab Code:
Author: Minh Anh Nguyen (minhanhnguyen@q.com) This script will perform the following
tasks:
%1. read in two "wav" files, plot the signals of these files
%2. fft
% 3. compare input signals, and display a message on the screen whether or
not the signals are the same.
% the MSE must be 0, for both signals are the same.
% The script will read in a stereo data (right channel)
close all;% Close all figures (except those of imtool.)
clear all; % Erase all existing variables.
clc;% Clear the command window.
fontSize = 20;
fontSize1 = 14;
fontSize2 = 12;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Please edit files
% set folder
folder = 'C:UsersMinh anhDesktopmicrophone-project-demo';
%%Open WAV file:
sound1=audioread('.good 2.wav');
[y1,fs1]=audioread('.good 2.wav');
sound2=audioread('.good 3.wav');
[y2,fs2]=audioread('.good 3.wav');
% sound2=audioread('.upper_channel 2.wav');
% [y2,fs2]=audioread('.upper_channel 2.wav');
% sound2=audioread('.upper_channel_bide 1.wav');
% [y2,fs2]=audioread('.upper_channel_bide 1.wav');
% sound2=audioread('.lower_channel 1.wav');
% [y2,fs2]=audioread('.lower_channel 1.wav');
% sound2=audioread('.pin1.wav');
% [y2,fs2]=audioread('.pin1.wav');
sound1_baseline_noise=audioread('.good 2_noise.wav');
[y1_basenoise,fs1_basenoise]=audioread('.good 2_noise.wav');
%
sound2_baseline_noise=audioread('.good 3_noise.wav');
[y2_basenoise,fs2_basenoise]=audioread('.good 3_noise.wav');
% sound2_baseline_noise=audioread('upper_channel 2_noise.wav');
% [y2_basenoise,fs2_basenoise]=audioread('.upper_channel 2_noise.wav');
% sound2_baseline_noise=audioread('upper_channel_bide 1_noise.wav');
% [y2_basenoise,fs2_basenoise]=audioread('.upper_channel_bide 1_noise.wav');
% sound2_baseline_noise=audioread('lower_channel 1_noise.wav');
% [y2_basenoise,fs2_basenoise]=audioread('.lower_channel 1_noise.wav');
% sound2_baseline_noise=audioread('.pin1_noise.wav');
% [y2_basenoise,fs2_basenoise]=audioread('.pin1_noise.wav');
signal into left and right, stereo records
size(y1);
left1=y1(:,1);
right1=y1(:,2);
[MR1,NR1] = size(right1);
size(y2);
left2=y2(:,1);
right2=y2(:,2);
[MR2,NR2] = size(right2);
time for right signal only (stereo) for original signals
Nl = length(right1); % number of points to analyze
lsl = size (right1); % find the length of the data per second
nbits = 2^(length(right1));
t1l = (0:1:length(right1)-1)/fs1;
fx = fs1*(0:Nl/2-1)/Nl; %Prepare freq data for plot
T1 = 1/fs1; % period between each sample
N = Nl;
N2 = length(right2);
ls2 = size (right2); % find the length of the data per second
nbits2 = 2^(length(right2));
t2 = (0:1:length(right2)-1)/fs2;
fx2 = fs2*(0:N2/2-1)/N2; %Prepare freq data for plot
T2 = 1/fs2; % period between each sample
% baseline noise is removed from signals
size(y1_basenoise);
left1_basenoise=y1_basenoise(:,1);
right1_basenoise=y1_basenoise(:,2);
[MR1_basenoise,NR1_basenoise] = size(right1_basenoise);
size(y2_basenoise);
left2_basenoise=y2_basenoise(:,1);
right2_basenoise=y2_basenoise(:,2);
[MR2_basenoise,NR2_basenoise] = size(right2_basenoise);
t1_basenoise = (0:1:length(right1_basenoise)-1)/fs1_basenoise;
t2_basenoise = (0:1:length(right2_basenoise)-1)/fs2_basenoise;
%%cut signal to the same length for comparing
voice1 = right1(fs1*1 : fs1*40);
voice2 = right2(fs2*1 : fs2*40);
find new length
N2x = length(voice2);
N1x = length(voice1);
find new time
t1x = (0:1:length(voice1)-1)/fs1;
t2x = (0:1:length(voice2)-1)/fs2;
find new frequency
f2x = fs2*(0:N2x/2-1)/N2x;
f1x = fs1*(0:N1x/2-1)/N1x;
perform fft and plot of the cut orignal signal
NFFT1x = 2 ^ nextpow2(N1x);
Y1x = fft(voice1, NFFT1x)/ N1x;
f1xx = (fs1/ 2 * linspace(0, 1, NFFT1x / 2+1))'; % Vector containing
frequencies in Hz
STFFT1x = ( 2 * abs(Y1x(1: NFFT1x / 2+1))); % Vector containing corresponding
amplitudes
NFFT2x = 2 ^ nextpow2(N2x);
Y2x = fft(voice2, NFFT2x) / N2x;
f2xx = (fs2 / 2 * linspace(0, 1, NFFT2x / 2+1))'; % Vector containing
frequencies in Hz
STFFT2x = ( 2 * abs(Y2x(1: NFFT2x / 2+1))); % Vector containing corresponding
amplitudes
% plot of the cut orginal signal
figure; subplot (2,2,1); plot(t1x, voice1);xlim([0,40]); ylim([-2,2]);
%str1=sprintf('Correct loading with sampling rate = %d Hz, number sample =
%d', fs1, N1x);
str1=sprintf('Correct loading signal');
title(str1,'Fontsize', fontSize2);
xlabel('Time (sec)','Fontsize', fontSize1); ylabel('Amplitude','Fontsize',
fontSize1); grid on;
subplot (2,2,2); plot(t2x, voice2); xlim([0,40]); ylim([-2,2]);
%str2=sprintf(' User loading with sampling rate = %d Hz, number sample = %d',
fs2, N2x);
str2=sprintf('User loading signal');
title(str2,'Fontsize', fontSize2); xlabel('Time (sec)','Fontsize',
fontSize1); ylabel('Amplitude','Fontsize', fontSize1); grid on;
% plot of the fft cut signal2
%subplot (2,2,3); plot(f1xx, STFFT1x); xlim([0,1500]); ylim([0,.09]);
figure;
plot(f1xx, STFFT1x); xlim([0,1500]); ylim([0,.09]);
str1ft1=sprintf('Single-sided Power spectrum for Correct loading');
title(str1ft1,'Fontsize', fontSize2);
ylabel ('Magnitude','Fontsize', fontSize1); xlabel ('Frequency
[Hz]','Fontsize', fontSize1); grid on;
% display markers at specific data points on DFT graph
indexmin1 = find(min(STFFT1x) == STFFT1x);
xmin1 = f1xx(indexmin1);
ymin1 = STFFT1x(indexmin1);
indexmax1 = find(max(STFFT1x) == STFFT1x);
xmax1 = f1xx(indexmax1);
ymax1 = STFFT1x(indexmax1);
strmax1 = ['Frequency = ',num2str(xmax1),' Hz',' ','Magnitude=',
num2str(ymax1),''];
text(xmax1,ymax1,strmax1,'HorizontalAlignment','Left');
%subplot (2,2,4); plot(f2xx, STFFT2x); xlim([0,1500]); ylim([0,.09]);
figure; plot(f2xx, STFFT2x); xlim([0,1500]); ylim([0,.09]);
str1ft2=sprintf('Single-sided Power spectrum for User loading');
title(str1ft2,'Fontsize', fontSize2);
ylabel ('Magnitude', 'Fontsize', fontSize1); xlabel ('Frequency
[Hz]','Fontsize', fontSize1); grid on;
% display markers at specific data points on DFT graph
indexmin2 = find(min(STFFT2x) == STFFT2x);
xmin2 = f2xx(indexmin2);
ymin2 = STFFT2x(indexmin2);
indexmax2 = find(max(STFFT2x) == STFFT2x);
xmax2 = f2xx(indexmax2);
ymax2 = STFFT2x(indexmax2);
strmax2 = ['Frequency = ',num2str(xmax2),' Hz',' ','Magnitude =',
num2str(ymax2),' '];
text(xmax2,ymax2,strmax2,'HorizontalAlignment','Left');
Zoom in to signal baseline noise signal
figure; subplot(3,2,1); plot(t1_basenoise,right1_basenoise); xlim([0,10]);
ylim([-2,2]);
str1=sprintf('Correct loading with Zoom in');
title(str1,'Fontsize', fontSize1);
xlabel('Time (secs)','Fontsize', fontSize1); ylabel('Amplitude','Fontsize',
fontSize1); grid on;
subplot(3,2,3); plot(t2_basenoise,right2_basenoise,'r'); xlim([0,10]);
ylim([-2,2]);
str2=sprintf('User loading with Zoom in');
title(str2, 'Fontsize', fontSize1);
xlabel('Time (secs)','Fontsize', fontSize1); ylabel('Amplitude','Fontsize',
fontSize1); grid on;
plot two signals
figure, plot(t1_basenoise,right1_basenoise,
t2_basenoise,right2_basenoise,'r'); xlim([0,10]); ylim([-2,2]);
str2=sprintf('Comparing two loading signals with Zoom in ');
title(str2, 'Fontsize', fontSize1);
xlabel('Time (secs)','Fontsize', fontSize1); ylabel('Amplitude','Fontsize',
fontSize1); grid on;
legend ('Correct loading signal', 'User loading signal', 'Fontsize',
fontSize);
Warning: Using an integer to specify the legend location is not supported.
Specify the legend location with respect to the axes using the 'Location'
parameter.
Warning: Ignoring extra legend entries.
plot fft compare
figure, plot(f1xx, STFFT1x,f2xx, STFFT2x,'r'); xlim([0,1500]); ylim([0,.09]);
str1ft3=sprintf('Comparing FFT for two loading signals');
title(str1ft3,'Fontsize', fontSize1);
ylabel ('Magnitude', 'Fontsize', fontSize1); xlabel ('Frequency
[Hz]','Fontsize', fontSize1); grid on;
indexmax3 = find(max(STFFT2x) == STFFT2x);
xmax3 = f2xx(indexmax3);
ymax3 = STFFT2x(indexmax3);
strmax3 = ['Frequency = ',num2str(xmax3),' Hz',' ','Magnitude= ',
num2str(ymax3),' '];
legend ('Correct loading signal', 'User loading signal','Fontsize',
fontSize);
Warning: Using an integer to specify the legend location is not supported.
Specify the legend location with respect to the axes using the 'Location'
parameter.
Warning: Ignoring extra legend entries.
calculate and compare two signals
Calculate the MSE
D= voice1 - voice2;
MSE=mean(D.^2);
%msgbox(strcat('MSE value is= ',mat2str(),' MSE'));
%msgbox(strcat('MSE value is= ',mat2str(MSE)));
%if MSE ==0;
%if MSE <= 0.00135; %%v this will work
if MSE <= 5.2731e-09 ; %%v this will work
disp('Signal are the same');
else
% msgbox(strcat('MSE value is= ',mat2str(MSE)));
disp('Signal are not the same');
msgbox('Centrifuge loading error. Please check bearings are seated
properly');
end
% %% play back play back the audio files
% disp('Playing (correctly loaded).');
% sound(y1,fs1);
% pause; %create a 2 second pause
%
%
% disp('Playing the user loading.');
% sound(y2,fs2);
% pause
%%Calculate variance, mean and standard deviation of sounds
D1c= STFFT1x - STFFT2x;
MSEfft=mean(D1c.^2);
disp(['MSEfft' num2str(MSEfft)]);
mean1= sum(right1)/N;
mean2= sum(right2)/N2;
stdev1 = sqrt ((sum(right1-mean1).^2)/2);
stdev2 = sqrt ((sum(right2-mean2).^2)/2);
% var(right1(1:length(right2))-right2) %for the whole signal y1-y2
var(voice1(1:length(voice2))-voice2); %for the voice
fprintf('digital statitics of voice 1 a same length signalnn');
fprintf('mean of voice 1:%fn', mean(voice1));
fprintf('standard deviation of voice 1:%fn', std(voice1));
fprintf('variance of voice 1:%fn', std(voice1)^2);
fprintf('average power of voice 1:%fn', mean(voice1.^2));
fprintf('average magnitude of voice 1:%fn', mean(abs(voice1)));
% prod1 = sound1(1:N-1) * sound1(2:N);
% crossing1 = length (find(prod1<0));
% fprintf(' zero crossing of sound 1:% 0.fn', crossing1);
%
fprintf('ndigital statitics of voice 2nn');
fprintf('mean of voice 2:%fn', mean(voice2));
fprintf('standard deviation of voice 2:%fn', std(voice2));
fprintf('variance of voice 2:%fn', std(voice2)^2);
fprintf('average power of voice 2:%fn', mean(voice2.^2));
fprintf('average magnitude of voice 2:%fn', mean(abs(voice2)));
% prod1 = sound1(1:N-1) * sound1(2:N);
% crossing1 = length (find(prod1<0));
% fprintf(' zero crossing of sound 1:% 0.fn', crossing1);
%
% % var(right1(1:length(right2))-right2) %for the whole signal y1-y2
% var(voice1(1:length(voice2))-voice2); %for the voice
%
%
Signal are the same
MSEfft0
digital statitics of voice 1 a same length signal
mean of voice 1:-0.000105
standard deviation of voice 1:0.251742
variance of voice 1:0.063374
average power of voice 1:0.063374
average magnitude of voice 1:0.197595
digital statitics of voice 2
mean of voice 2:-0.000105
standard deviation of voice 2:0.251742
variance of voice 2:0.063374
average power of voice 2:0.063374
average magnitude of voice 2:0.197595
correlation
[C1, lag1] = xcorr(abs((fft(voice1))),abs((fft(voice2)) ));
figure, plot(lag1/fs1,C1);
ylabel('Amplitude'); grid on
title('Cross-correlation between Correct and User loading files')
% %% plot orginal signal. for debug. %% team does not like long length
% %% perform fft and plot of orignal signal
% %
% figure; subplot (2,2,1); plot(t1, sound1);
% title ('Signal of sound 1 , frequency = 44100 Hz and number sample =
2742270');
% xlabel('time (sec)'); ylabel('relative signal strength'); grid on;
% %
% subplot (2,2,2); plot(t2, sound2);
% title ('Signal of sound 2, frequency = 44100 Hz and number sample =
2674665');
% xlabel('time (sec)'); ylabel('relative signal strength'); grid on;
% %% fft of orignal signal
% NFFT1 = 2 ^ nextpow2(N);
% Y1 = fft(y1, NFFT1)/ N;
% f1 = (fs1 / 2 * linspace(0, 1, NFFT1 / 2+1))'; % Vector containing
frequencies in Hz
% STFFT1 = ( 2 * abs(Y1(1: NFFT1 / 2+1))); % Vector containing corresponding
amplitudes
% subplot (2,2,3); plot(f1, STFFT1); title ('Single-sided Power spectrum for
Sound1');
% %subplot (2,2,3); plot(abs(fft(sound1))); title ('plot fft of Sound 1');
%plot Magnitude of fft
% ylabel ('Magnitude |y(f)|'); xlabel ('frequency [Hz]'); grid on;
%
% NFFT2 = 2 ^ nextpow2(N2);
% Y2 = fft(y2, NFFT2) / N2;
% f2 = (fs2 / 2 * linspace(0, 1, NFFT2 / 2+1))'; % Vector containing
frequencies in Hz
% STFFT2 = ( 2 * abs(Y2(1: NFFT2 / 2+1))); % Vector containing corresponding
amplitudes
% subplot (2,2,4); plot(f2, STFFT2); title ('Single-sided Power spectrum for
Sound2');
% % subplot (2,2,4); plot(abs(fft(sound2))); title ('plot fft of Sound2');
% ylabel ('Magnitude |y(f)|'); xlabel ('frequency [Hz]'); grid on;
Published with MATLAB® R2016a

More Related Content

Viewers also liked

STUCK-OPEN FAULT ANALYSIS IN CMOS TRANSISTOR BASED COMBINATIONAL CIRCUITS
STUCK-OPEN FAULT ANALYSIS IN CMOS TRANSISTOR BASED COMBINATIONAL CIRCUITSSTUCK-OPEN FAULT ANALYSIS IN CMOS TRANSISTOR BASED COMBINATIONAL CIRCUITS
STUCK-OPEN FAULT ANALYSIS IN CMOS TRANSISTOR BASED COMBINATIONAL CIRCUITSMinh Anh Nguyen
 
Comparing two audio files
Comparing two audio filesComparing two audio files
Comparing two audio filesMinh Anh Nguyen
 
The method of comparing two audio files
The method of comparing two audio filesThe method of comparing two audio files
The method of comparing two audio filesMinh Anh Nguyen
 
The method of comparing two image files
The method of comparing two image filesThe method of comparing two image files
The method of comparing two image filesMinh Anh Nguyen
 
Use of spatial frequency domain imaging (sfdi) to quantify drug delivery
Use of spatial frequency domain imaging (sfdi) to quantify drug deliveryUse of spatial frequency domain imaging (sfdi) to quantify drug delivery
Use of spatial frequency domain imaging (sfdi) to quantify drug deliveryMinh Anh Nguyen
 
Simulation results of induction heating coil
Simulation results of induction heating coilSimulation results of induction heating coil
Simulation results of induction heating coilMinh Anh Nguyen
 
STUCK-OPEN FAULT ANALYSIS IN CMOS TRANSISTOR BASED COMBINATIONAL CIRCUITS
STUCK-OPEN FAULT ANALYSIS IN CMOS TRANSISTOR BASED COMBINATIONAL CIRCUITSSTUCK-OPEN FAULT ANALYSIS IN CMOS TRANSISTOR BASED COMBINATIONAL CIRCUITS
STUCK-OPEN FAULT ANALYSIS IN CMOS TRANSISTOR BASED COMBINATIONAL CIRCUITSMinh Anh Nguyen
 
Chuc Mung Nam Moi 2017- Dinh Dau
Chuc Mung Nam Moi 2017- Dinh DauChuc Mung Nam Moi 2017- Dinh Dau
Chuc Mung Nam Moi 2017- Dinh DauMinh Anh Nguyen
 
Cmos Arithmetic Circuits
Cmos Arithmetic CircuitsCmos Arithmetic Circuits
Cmos Arithmetic Circuitsankitgoel
 
faults in digital systems
faults in digital systemsfaults in digital systems
faults in digital systemsdennis gookyi
 
UNIT-III-DIGITAL SYSTEM DESIGN
UNIT-III-DIGITAL SYSTEM DESIGNUNIT-III-DIGITAL SYSTEM DESIGN
UNIT-III-DIGITAL SYSTEM DESIGNDr.YNM
 

Viewers also liked (13)

STUCK-OPEN FAULT ANALYSIS IN CMOS TRANSISTOR BASED COMBINATIONAL CIRCUITS
STUCK-OPEN FAULT ANALYSIS IN CMOS TRANSISTOR BASED COMBINATIONAL CIRCUITSSTUCK-OPEN FAULT ANALYSIS IN CMOS TRANSISTOR BASED COMBINATIONAL CIRCUITS
STUCK-OPEN FAULT ANALYSIS IN CMOS TRANSISTOR BASED COMBINATIONAL CIRCUITS
 
Comparing two audio files
Comparing two audio filesComparing two audio files
Comparing two audio files
 
The method of comparing two audio files
The method of comparing two audio filesThe method of comparing two audio files
The method of comparing two audio files
 
The method of comparing two image files
The method of comparing two image filesThe method of comparing two image files
The method of comparing two image files
 
Use of spatial frequency domain imaging (sfdi) to quantify drug delivery
Use of spatial frequency domain imaging (sfdi) to quantify drug deliveryUse of spatial frequency domain imaging (sfdi) to quantify drug delivery
Use of spatial frequency domain imaging (sfdi) to quantify drug delivery
 
A place in_my_heart
A place in_my_heartA place in_my_heart
A place in_my_heart
 
Simulation results of induction heating coil
Simulation results of induction heating coilSimulation results of induction heating coil
Simulation results of induction heating coil
 
Maxwell3 d
Maxwell3 dMaxwell3 d
Maxwell3 d
 
STUCK-OPEN FAULT ANALYSIS IN CMOS TRANSISTOR BASED COMBINATIONAL CIRCUITS
STUCK-OPEN FAULT ANALYSIS IN CMOS TRANSISTOR BASED COMBINATIONAL CIRCUITSSTUCK-OPEN FAULT ANALYSIS IN CMOS TRANSISTOR BASED COMBINATIONAL CIRCUITS
STUCK-OPEN FAULT ANALYSIS IN CMOS TRANSISTOR BASED COMBINATIONAL CIRCUITS
 
Chuc Mung Nam Moi 2017- Dinh Dau
Chuc Mung Nam Moi 2017- Dinh DauChuc Mung Nam Moi 2017- Dinh Dau
Chuc Mung Nam Moi 2017- Dinh Dau
 
Cmos Arithmetic Circuits
Cmos Arithmetic CircuitsCmos Arithmetic Circuits
Cmos Arithmetic Circuits
 
faults in digital systems
faults in digital systemsfaults in digital systems
faults in digital systems
 
UNIT-III-DIGITAL SYSTEM DESIGN
UNIT-III-DIGITAL SYSTEM DESIGNUNIT-III-DIGITAL SYSTEM DESIGN
UNIT-III-DIGITAL SYSTEM DESIGN
 

Similar to Matlab code for comparing two microphone files

Question I Part (a) 1.SOURCE CODE LISTING for numb.docx
Question I Part (a) 1.SOURCE CODE LISTING for numb.docxQuestion I Part (a) 1.SOURCE CODE LISTING for numb.docx
Question I Part (a) 1.SOURCE CODE LISTING for numb.docxcatheryncouper
 
Basic simulation lab manual1
Basic simulation lab manual1Basic simulation lab manual1
Basic simulation lab manual1Janardhana Raju M
 
The method of comparing two audio files
The method of comparing two audio filesThe method of comparing two audio files
The method of comparing two audio filesMinh Anh Nguyen
 
Matlab 2
Matlab 2Matlab 2
Matlab 2asguna
 
Fast Fourier Transform (FFT) of Time Series in Kafka Streams
Fast Fourier Transform (FFT) of Time Series in Kafka StreamsFast Fourier Transform (FFT) of Time Series in Kafka Streams
Fast Fourier Transform (FFT) of Time Series in Kafka StreamsHostedbyConfluent
 
Matlab kod taslağı
Matlab kod taslağıMatlab kod taslağı
Matlab kod taslağıMerve Cvdr
 
Exam 6 commlab 18_119_ei0292
Exam 6 commlab 18_119_ei0292Exam 6 commlab 18_119_ei0292
Exam 6 commlab 18_119_ei0292lucky859450
 
Digitla Communication pulse shaping filter
Digitla Communication pulse shaping filterDigitla Communication pulse shaping filter
Digitla Communication pulse shaping filtermirfanjum
 
Dsp gcu lab11
Dsp gcu lab11Dsp gcu lab11
Dsp gcu lab11Jannat41
 
DIGITAL SIGNAL PROCESSING: Sampling and Reconstruction on MATLAB
DIGITAL SIGNAL PROCESSING: Sampling and Reconstruction on MATLABDIGITAL SIGNAL PROCESSING: Sampling and Reconstruction on MATLAB
DIGITAL SIGNAL PROCESSING: Sampling and Reconstruction on MATLABMartin Wachiye Wafula
 
Fourier series example
Fourier series exampleFourier series example
Fourier series exampleAbi finni
 
bask, bfsk, bpsk
bask, bfsk, bpskbask, bfsk, bpsk
bask, bfsk, bpskblzz2net
 
Matlab fair-record-model
Matlab fair-record-modelMatlab fair-record-model
Matlab fair-record-modelajaydev1111
 

Similar to Matlab code for comparing two microphone files (20)

Question I Part (a) 1.SOURCE CODE LISTING for numb.docx
Question I Part (a) 1.SOURCE CODE LISTING for numb.docxQuestion I Part (a) 1.SOURCE CODE LISTING for numb.docx
Question I Part (a) 1.SOURCE CODE LISTING for numb.docx
 
DSP Lab 1-6.pdf
DSP Lab 1-6.pdfDSP Lab 1-6.pdf
DSP Lab 1-6.pdf
 
Basic simulation lab manual1
Basic simulation lab manual1Basic simulation lab manual1
Basic simulation lab manual1
 
The method of comparing two audio files
The method of comparing two audio filesThe method of comparing two audio files
The method of comparing two audio files
 
Matlab 2
Matlab 2Matlab 2
Matlab 2
 
Dsp manual
Dsp manualDsp manual
Dsp manual
 
Fast Fourier Transform (FFT) of Time Series in Kafka Streams
Fast Fourier Transform (FFT) of Time Series in Kafka StreamsFast Fourier Transform (FFT) of Time Series in Kafka Streams
Fast Fourier Transform (FFT) of Time Series in Kafka Streams
 
Matlab kod taslağı
Matlab kod taslağıMatlab kod taslağı
Matlab kod taslağı
 
Exam 6 commlab 18_119_ei0292
Exam 6 commlab 18_119_ei0292Exam 6 commlab 18_119_ei0292
Exam 6 commlab 18_119_ei0292
 
Digitla Communication pulse shaping filter
Digitla Communication pulse shaping filterDigitla Communication pulse shaping filter
Digitla Communication pulse shaping filter
 
Dsp Lab Record
Dsp Lab RecordDsp Lab Record
Dsp Lab Record
 
Dsp gcu lab11
Dsp gcu lab11Dsp gcu lab11
Dsp gcu lab11
 
DIGITAL SIGNAL PROCESSING: Sampling and Reconstruction on MATLAB
DIGITAL SIGNAL PROCESSING: Sampling and Reconstruction on MATLABDIGITAL SIGNAL PROCESSING: Sampling and Reconstruction on MATLAB
DIGITAL SIGNAL PROCESSING: Sampling and Reconstruction on MATLAB
 
Fourier series example
Fourier series exampleFourier series example
Fourier series example
 
Matlab Señales Discretas
Matlab Señales DiscretasMatlab Señales Discretas
Matlab Señales Discretas
 
bask, bfsk, bpsk
bask, bfsk, bpskbask, bfsk, bpsk
bask, bfsk, bpsk
 
Comm lab manual_final-1
Comm lab manual_final-1Comm lab manual_final-1
Comm lab manual_final-1
 
Comm lab manual_final
Comm lab manual_finalComm lab manual_final
Comm lab manual_final
 
matlab.docx
matlab.docxmatlab.docx
matlab.docx
 
Matlab fair-record-model
Matlab fair-record-modelMatlab fair-record-model
Matlab fair-record-model
 

More from Minh Anh Nguyen

Chúc mừng năm mới 2018
Chúc mừng năm mới 2018Chúc mừng năm mới 2018
Chúc mừng năm mới 2018Minh Anh Nguyen
 
Sound and Vibration Toolkit User Manual
Sound and Vibration Toolkit User ManualSound and Vibration Toolkit User Manual
Sound and Vibration Toolkit User ManualMinh Anh Nguyen
 
Tet trung thu Happy mid-autumn moon festival
Tet trung thu  Happy mid-autumn moon festivalTet trung thu  Happy mid-autumn moon festival
Tet trung thu Happy mid-autumn moon festivalMinh Anh Nguyen
 
Electrocardiogram (ECG or EKG)
Electrocardiogram (ECG or EKG)Electrocardiogram (ECG or EKG)
Electrocardiogram (ECG or EKG)Minh Anh Nguyen
 
Results Review of iphone and Detecting of Human Errors Algorithm
Results Review of iphone and Detecting of Human Errors AlgorithmResults Review of iphone and Detecting of Human Errors Algorithm
Results Review of iphone and Detecting of Human Errors AlgorithmMinh Anh Nguyen
 
Results Review of Microphone Prototype and LabView Detecting of Human Errors ...
Results Review of Microphone Prototype and LabView Detecting of Human Errors ...Results Review of Microphone Prototype and LabView Detecting of Human Errors ...
Results Review of Microphone Prototype and LabView Detecting of Human Errors ...Minh Anh Nguyen
 
A message for my uncle on father's day
A message for my uncle on father's dayA message for my uncle on father's day
A message for my uncle on father's dayMinh Anh Nguyen
 
CENTRIFUGE LOADING HUMAN FACTORS
CENTRIFUGE LOADING HUMAN FACTORSCENTRIFUGE LOADING HUMAN FACTORS
CENTRIFUGE LOADING HUMAN FACTORSMinh Anh Nguyen
 
Green fields - The brother four
Green fields - The brother fourGreen fields - The brother four
Green fields - The brother fourMinh Anh Nguyen
 
How to perform software testing
How to perform software testing How to perform software testing
How to perform software testing Minh Anh Nguyen
 

More from Minh Anh Nguyen (20)

Chúc mừng năm mới 2018
Chúc mừng năm mới 2018Chúc mừng năm mới 2018
Chúc mừng năm mới 2018
 
Happ New Year
Happ New YearHapp New Year
Happ New Year
 
Tutorial for EDA Tools:
Tutorial for EDA Tools:Tutorial for EDA Tools:
Tutorial for EDA Tools:
 
Sound and Vibration Toolkit User Manual
Sound and Vibration Toolkit User ManualSound and Vibration Toolkit User Manual
Sound and Vibration Toolkit User Manual
 
Tet trung thu Happy mid-autumn moon festival
Tet trung thu  Happy mid-autumn moon festivalTet trung thu  Happy mid-autumn moon festival
Tet trung thu Happy mid-autumn moon festival
 
An Introduction to HFSS
An Introduction to HFSSAn Introduction to HFSS
An Introduction to HFSS
 
Electrocardiogram (ECG or EKG)
Electrocardiogram (ECG or EKG)Electrocardiogram (ECG or EKG)
Electrocardiogram (ECG or EKG)
 
Love me tender
Love me tenderLove me tender
Love me tender
 
Ni myRio and Microphone
Ni myRio and MicrophoneNi myRio and Microphone
Ni myRio and Microphone
 
Results Review of iphone and Detecting of Human Errors Algorithm
Results Review of iphone and Detecting of Human Errors AlgorithmResults Review of iphone and Detecting of Human Errors Algorithm
Results Review of iphone and Detecting of Human Errors Algorithm
 
Results Review of Microphone Prototype and LabView Detecting of Human Errors ...
Results Review of Microphone Prototype and LabView Detecting of Human Errors ...Results Review of Microphone Prototype and LabView Detecting of Human Errors ...
Results Review of Microphone Prototype and LabView Detecting of Human Errors ...
 
A message for my uncle on father's day
A message for my uncle on father's dayA message for my uncle on father's day
A message for my uncle on father's day
 
CENTRIFUGE LOADING HUMAN FACTORS
CENTRIFUGE LOADING HUMAN FACTORSCENTRIFUGE LOADING HUMAN FACTORS
CENTRIFUGE LOADING HUMAN FACTORS
 
Try to remember
Try to rememberTry to remember
Try to remember
 
Paloma
PalomaPaloma
Paloma
 
Green fields - The brother four
Green fields - The brother fourGreen fields - The brother four
Green fields - The brother four
 
Happy New Year
Happy New YearHappy New Year
Happy New Year
 
Chuc Mung Nam Moi 2016
Chuc Mung Nam Moi 2016Chuc Mung Nam Moi 2016
Chuc Mung Nam Moi 2016
 
How to perform software testing
How to perform software testing How to perform software testing
How to perform software testing
 
New Year wishes
New Year wishesNew Year wishes
New Year wishes
 

Recently uploaded

Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfROCENODodongVILLACER
 
computer application and construction management
computer application and construction managementcomputer application and construction management
computer application and construction managementMariconPadriquez1
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)dollysharma2066
 
Class 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm SystemClass 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm Systemirfanmechengr
 
welding defects observed during the welding
welding defects observed during the weldingwelding defects observed during the welding
welding defects observed during the weldingMuhammadUzairLiaqat
 
Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substationstephanwindworld
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...Chandu841456
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
lifi-technology with integration of IOT.pptx
lifi-technology with integration of IOT.pptxlifi-technology with integration of IOT.pptx
lifi-technology with integration of IOT.pptxsomshekarkn64
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxk795866
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfme23b1001
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
Vishratwadi & Ghorpadi Bridge Tender documents
Vishratwadi & Ghorpadi Bridge Tender documentsVishratwadi & Ghorpadi Bridge Tender documents
Vishratwadi & Ghorpadi Bridge Tender documentsSachinPawar510423
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 

Recently uploaded (20)

Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdf
 
computer application and construction management
computer application and construction managementcomputer application and construction management
computer application and construction management
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
 
Class 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm SystemClass 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm System
 
welding defects observed during the welding
welding defects observed during the weldingwelding defects observed during the welding
welding defects observed during the welding
 
Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substation
 
An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...An experimental study in using natural admixture as an alternative for chemic...
An experimental study in using natural admixture as an alternative for chemic...
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
lifi-technology with integration of IOT.pptx
lifi-technology with integration of IOT.pptxlifi-technology with integration of IOT.pptx
lifi-technology with integration of IOT.pptx
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptx
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdf
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
Vishratwadi & Ghorpadi Bridge Tender documents
Vishratwadi & Ghorpadi Bridge Tender documentsVishratwadi & Ghorpadi Bridge Tender documents
Vishratwadi & Ghorpadi Bridge Tender documents
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 

Matlab code for comparing two microphone files

  • 1. Contents  Matlab Code:  signal into left and right, stereo records  time for right signal only (stereo) for original signals  find new length  find new time  find new frequency  perform fft and plot of the cut orignal signal  Zoom in to signal baseline noise signal  plot two signals  plot fft compare  calculate and compare two signals  corlation Matlab Code: Author: Minh Anh Nguyen (minhanhnguyen@q.com) This script will perform the following tasks: %1. read in two "wav" files, plot the signals of these files %2. fft % 3. compare input signals, and display a message on the screen whether or not the signals are the same. % the MSE must be 0, for both signals are the same. % The script will read in a stereo data (right channel) close all;% Close all figures (except those of imtool.) clear all; % Erase all existing variables. clc;% Clear the command window. fontSize = 20; fontSize1 = 14; fontSize2 = 12; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Please edit files % set folder folder = 'C:UsersMinh anhDesktopmicrophone-project-demo'; %%Open WAV file: sound1=audioread('.good 2.wav'); [y1,fs1]=audioread('.good 2.wav'); sound2=audioread('.good 3.wav'); [y2,fs2]=audioread('.good 3.wav'); % sound2=audioread('.upper_channel 2.wav'); % [y2,fs2]=audioread('.upper_channel 2.wav'); % sound2=audioread('.upper_channel_bide 1.wav'); % [y2,fs2]=audioread('.upper_channel_bide 1.wav');
  • 2. % sound2=audioread('.lower_channel 1.wav'); % [y2,fs2]=audioread('.lower_channel 1.wav'); % sound2=audioread('.pin1.wav'); % [y2,fs2]=audioread('.pin1.wav'); sound1_baseline_noise=audioread('.good 2_noise.wav'); [y1_basenoise,fs1_basenoise]=audioread('.good 2_noise.wav'); % sound2_baseline_noise=audioread('.good 3_noise.wav'); [y2_basenoise,fs2_basenoise]=audioread('.good 3_noise.wav'); % sound2_baseline_noise=audioread('upper_channel 2_noise.wav'); % [y2_basenoise,fs2_basenoise]=audioread('.upper_channel 2_noise.wav'); % sound2_baseline_noise=audioread('upper_channel_bide 1_noise.wav'); % [y2_basenoise,fs2_basenoise]=audioread('.upper_channel_bide 1_noise.wav'); % sound2_baseline_noise=audioread('lower_channel 1_noise.wav'); % [y2_basenoise,fs2_basenoise]=audioread('.lower_channel 1_noise.wav'); % sound2_baseline_noise=audioread('.pin1_noise.wav'); % [y2_basenoise,fs2_basenoise]=audioread('.pin1_noise.wav'); signal into left and right, stereo records size(y1); left1=y1(:,1); right1=y1(:,2); [MR1,NR1] = size(right1); size(y2); left2=y2(:,1); right2=y2(:,2); [MR2,NR2] = size(right2); time for right signal only (stereo) for original signals Nl = length(right1); % number of points to analyze lsl = size (right1); % find the length of the data per second nbits = 2^(length(right1)); t1l = (0:1:length(right1)-1)/fs1; fx = fs1*(0:Nl/2-1)/Nl; %Prepare freq data for plot T1 = 1/fs1; % period between each sample N = Nl; N2 = length(right2); ls2 = size (right2); % find the length of the data per second nbits2 = 2^(length(right2)); t2 = (0:1:length(right2)-1)/fs2; fx2 = fs2*(0:N2/2-1)/N2; %Prepare freq data for plot T2 = 1/fs2; % period between each sample % baseline noise is removed from signals
  • 3. size(y1_basenoise); left1_basenoise=y1_basenoise(:,1); right1_basenoise=y1_basenoise(:,2); [MR1_basenoise,NR1_basenoise] = size(right1_basenoise); size(y2_basenoise); left2_basenoise=y2_basenoise(:,1); right2_basenoise=y2_basenoise(:,2); [MR2_basenoise,NR2_basenoise] = size(right2_basenoise); t1_basenoise = (0:1:length(right1_basenoise)-1)/fs1_basenoise; t2_basenoise = (0:1:length(right2_basenoise)-1)/fs2_basenoise; %%cut signal to the same length for comparing voice1 = right1(fs1*1 : fs1*40); voice2 = right2(fs2*1 : fs2*40); find new length N2x = length(voice2); N1x = length(voice1); find new time t1x = (0:1:length(voice1)-1)/fs1; t2x = (0:1:length(voice2)-1)/fs2; find new frequency f2x = fs2*(0:N2x/2-1)/N2x; f1x = fs1*(0:N1x/2-1)/N1x; perform fft and plot of the cut orignal signal NFFT1x = 2 ^ nextpow2(N1x); Y1x = fft(voice1, NFFT1x)/ N1x; f1xx = (fs1/ 2 * linspace(0, 1, NFFT1x / 2+1))'; % Vector containing frequencies in Hz STFFT1x = ( 2 * abs(Y1x(1: NFFT1x / 2+1))); % Vector containing corresponding amplitudes NFFT2x = 2 ^ nextpow2(N2x); Y2x = fft(voice2, NFFT2x) / N2x; f2xx = (fs2 / 2 * linspace(0, 1, NFFT2x / 2+1))'; % Vector containing frequencies in Hz STFFT2x = ( 2 * abs(Y2x(1: NFFT2x / 2+1))); % Vector containing corresponding amplitudes % plot of the cut orginal signal figure; subplot (2,2,1); plot(t1x, voice1);xlim([0,40]); ylim([-2,2]); %str1=sprintf('Correct loading with sampling rate = %d Hz, number sample = %d', fs1, N1x);
  • 4. str1=sprintf('Correct loading signal'); title(str1,'Fontsize', fontSize2); xlabel('Time (sec)','Fontsize', fontSize1); ylabel('Amplitude','Fontsize', fontSize1); grid on; subplot (2,2,2); plot(t2x, voice2); xlim([0,40]); ylim([-2,2]); %str2=sprintf(' User loading with sampling rate = %d Hz, number sample = %d', fs2, N2x); str2=sprintf('User loading signal'); title(str2,'Fontsize', fontSize2); xlabel('Time (sec)','Fontsize', fontSize1); ylabel('Amplitude','Fontsize', fontSize1); grid on; % plot of the fft cut signal2 %subplot (2,2,3); plot(f1xx, STFFT1x); xlim([0,1500]); ylim([0,.09]); figure; plot(f1xx, STFFT1x); xlim([0,1500]); ylim([0,.09]); str1ft1=sprintf('Single-sided Power spectrum for Correct loading'); title(str1ft1,'Fontsize', fontSize2); ylabel ('Magnitude','Fontsize', fontSize1); xlabel ('Frequency [Hz]','Fontsize', fontSize1); grid on; % display markers at specific data points on DFT graph indexmin1 = find(min(STFFT1x) == STFFT1x); xmin1 = f1xx(indexmin1); ymin1 = STFFT1x(indexmin1); indexmax1 = find(max(STFFT1x) == STFFT1x); xmax1 = f1xx(indexmax1); ymax1 = STFFT1x(indexmax1); strmax1 = ['Frequency = ',num2str(xmax1),' Hz',' ','Magnitude=', num2str(ymax1),'']; text(xmax1,ymax1,strmax1,'HorizontalAlignment','Left'); %subplot (2,2,4); plot(f2xx, STFFT2x); xlim([0,1500]); ylim([0,.09]); figure; plot(f2xx, STFFT2x); xlim([0,1500]); ylim([0,.09]); str1ft2=sprintf('Single-sided Power spectrum for User loading'); title(str1ft2,'Fontsize', fontSize2); ylabel ('Magnitude', 'Fontsize', fontSize1); xlabel ('Frequency [Hz]','Fontsize', fontSize1); grid on; % display markers at specific data points on DFT graph indexmin2 = find(min(STFFT2x) == STFFT2x); xmin2 = f2xx(indexmin2); ymin2 = STFFT2x(indexmin2); indexmax2 = find(max(STFFT2x) == STFFT2x); xmax2 = f2xx(indexmax2); ymax2 = STFFT2x(indexmax2); strmax2 = ['Frequency = ',num2str(xmax2),' Hz',' ','Magnitude =', num2str(ymax2),' ']; text(xmax2,ymax2,strmax2,'HorizontalAlignment','Left');
  • 5.
  • 6. Zoom in to signal baseline noise signal figure; subplot(3,2,1); plot(t1_basenoise,right1_basenoise); xlim([0,10]); ylim([-2,2]); str1=sprintf('Correct loading with Zoom in'); title(str1,'Fontsize', fontSize1); xlabel('Time (secs)','Fontsize', fontSize1); ylabel('Amplitude','Fontsize', fontSize1); grid on; subplot(3,2,3); plot(t2_basenoise,right2_basenoise,'r'); xlim([0,10]); ylim([-2,2]); str2=sprintf('User loading with Zoom in'); title(str2, 'Fontsize', fontSize1); xlabel('Time (secs)','Fontsize', fontSize1); ylabel('Amplitude','Fontsize', fontSize1); grid on;
  • 7. plot two signals figure, plot(t1_basenoise,right1_basenoise, t2_basenoise,right2_basenoise,'r'); xlim([0,10]); ylim([-2,2]); str2=sprintf('Comparing two loading signals with Zoom in '); title(str2, 'Fontsize', fontSize1); xlabel('Time (secs)','Fontsize', fontSize1); ylabel('Amplitude','Fontsize', fontSize1); grid on; legend ('Correct loading signal', 'User loading signal', 'Fontsize', fontSize); Warning: Using an integer to specify the legend location is not supported. Specify the legend location with respect to the axes using the 'Location' parameter. Warning: Ignoring extra legend entries.
  • 8. plot fft compare figure, plot(f1xx, STFFT1x,f2xx, STFFT2x,'r'); xlim([0,1500]); ylim([0,.09]); str1ft3=sprintf('Comparing FFT for two loading signals'); title(str1ft3,'Fontsize', fontSize1); ylabel ('Magnitude', 'Fontsize', fontSize1); xlabel ('Frequency [Hz]','Fontsize', fontSize1); grid on; indexmax3 = find(max(STFFT2x) == STFFT2x); xmax3 = f2xx(indexmax3); ymax3 = STFFT2x(indexmax3); strmax3 = ['Frequency = ',num2str(xmax3),' Hz',' ','Magnitude= ', num2str(ymax3),' ']; legend ('Correct loading signal', 'User loading signal','Fontsize', fontSize); Warning: Using an integer to specify the legend location is not supported. Specify the legend location with respect to the axes using the 'Location' parameter. Warning: Ignoring extra legend entries.
  • 9. calculate and compare two signals Calculate the MSE D= voice1 - voice2; MSE=mean(D.^2); %msgbox(strcat('MSE value is= ',mat2str(),' MSE')); %msgbox(strcat('MSE value is= ',mat2str(MSE))); %if MSE ==0; %if MSE <= 0.00135; %%v this will work if MSE <= 5.2731e-09 ; %%v this will work disp('Signal are the same'); else % msgbox(strcat('MSE value is= ',mat2str(MSE))); disp('Signal are not the same'); msgbox('Centrifuge loading error. Please check bearings are seated properly'); end % %% play back play back the audio files % disp('Playing (correctly loaded).'); % sound(y1,fs1); % pause; %create a 2 second pause % %
  • 10. % disp('Playing the user loading.'); % sound(y2,fs2); % pause %%Calculate variance, mean and standard deviation of sounds D1c= STFFT1x - STFFT2x; MSEfft=mean(D1c.^2); disp(['MSEfft' num2str(MSEfft)]); mean1= sum(right1)/N; mean2= sum(right2)/N2; stdev1 = sqrt ((sum(right1-mean1).^2)/2); stdev2 = sqrt ((sum(right2-mean2).^2)/2); % var(right1(1:length(right2))-right2) %for the whole signal y1-y2 var(voice1(1:length(voice2))-voice2); %for the voice fprintf('digital statitics of voice 1 a same length signalnn'); fprintf('mean of voice 1:%fn', mean(voice1)); fprintf('standard deviation of voice 1:%fn', std(voice1)); fprintf('variance of voice 1:%fn', std(voice1)^2); fprintf('average power of voice 1:%fn', mean(voice1.^2)); fprintf('average magnitude of voice 1:%fn', mean(abs(voice1))); % prod1 = sound1(1:N-1) * sound1(2:N); % crossing1 = length (find(prod1<0)); % fprintf(' zero crossing of sound 1:% 0.fn', crossing1); % fprintf('ndigital statitics of voice 2nn'); fprintf('mean of voice 2:%fn', mean(voice2)); fprintf('standard deviation of voice 2:%fn', std(voice2)); fprintf('variance of voice 2:%fn', std(voice2)^2); fprintf('average power of voice 2:%fn', mean(voice2.^2)); fprintf('average magnitude of voice 2:%fn', mean(abs(voice2))); % prod1 = sound1(1:N-1) * sound1(2:N); % crossing1 = length (find(prod1<0)); % fprintf(' zero crossing of sound 1:% 0.fn', crossing1); % % % var(right1(1:length(right2))-right2) %for the whole signal y1-y2 % var(voice1(1:length(voice2))-voice2); %for the voice % % Signal are the same MSEfft0 digital statitics of voice 1 a same length signal mean of voice 1:-0.000105 standard deviation of voice 1:0.251742 variance of voice 1:0.063374 average power of voice 1:0.063374 average magnitude of voice 1:0.197595
  • 11. digital statitics of voice 2 mean of voice 2:-0.000105 standard deviation of voice 2:0.251742 variance of voice 2:0.063374 average power of voice 2:0.063374 average magnitude of voice 2:0.197595 correlation [C1, lag1] = xcorr(abs((fft(voice1))),abs((fft(voice2)) )); figure, plot(lag1/fs1,C1); ylabel('Amplitude'); grid on title('Cross-correlation between Correct and User loading files') % %% plot orginal signal. for debug. %% team does not like long length % %% perform fft and plot of orignal signal % % % figure; subplot (2,2,1); plot(t1, sound1); % title ('Signal of sound 1 , frequency = 44100 Hz and number sample = 2742270'); % xlabel('time (sec)'); ylabel('relative signal strength'); grid on; % % % subplot (2,2,2); plot(t2, sound2); % title ('Signal of sound 2, frequency = 44100 Hz and number sample = 2674665'); % xlabel('time (sec)'); ylabel('relative signal strength'); grid on; % %% fft of orignal signal % NFFT1 = 2 ^ nextpow2(N); % Y1 = fft(y1, NFFT1)/ N; % f1 = (fs1 / 2 * linspace(0, 1, NFFT1 / 2+1))'; % Vector containing frequencies in Hz % STFFT1 = ( 2 * abs(Y1(1: NFFT1 / 2+1))); % Vector containing corresponding amplitudes % subplot (2,2,3); plot(f1, STFFT1); title ('Single-sided Power spectrum for Sound1'); % %subplot (2,2,3); plot(abs(fft(sound1))); title ('plot fft of Sound 1'); %plot Magnitude of fft % ylabel ('Magnitude |y(f)|'); xlabel ('frequency [Hz]'); grid on; % % NFFT2 = 2 ^ nextpow2(N2); % Y2 = fft(y2, NFFT2) / N2; % f2 = (fs2 / 2 * linspace(0, 1, NFFT2 / 2+1))'; % Vector containing frequencies in Hz % STFFT2 = ( 2 * abs(Y2(1: NFFT2 / 2+1))); % Vector containing corresponding amplitudes % subplot (2,2,4); plot(f2, STFFT2); title ('Single-sided Power spectrum for Sound2'); % % subplot (2,2,4); plot(abs(fft(sound2))); title ('plot fft of Sound2'); % ylabel ('Magnitude |y(f)|'); xlabel ('frequency [Hz]'); grid on;