Submission Assign3
Submission Assign3
10. FFT done with block averaging on lab generated square wave
Spectrum plot show four major harmonics frequencies present in the wave
Hanning window shows significant leakage compared to Flattop
Detailed plot is available in Appendix (10)
Appendix
Matlab scripts and plots
(4)
plot(t_min_flat,y_min_flat,t_max_rect,y_max_rect)
xlim([0 25600])
legend('No leak Spectrum with hanning window','Max leak Spectrum with rectangular window','loca
title('No leakage and greatest leakage spectrum with different windows')
xlabel('Frequency Hz')
ylabel('pressure dB')
1
plot(t_max_flat,y_max_flat,t_max_rect,y_max_rect)
xlim([0 25600])
legend('Smallest amplitude error Spectrum with hanning window','Smallest frequency error Spectr
title('Greatest leakage spectrum with different windows')
xlabel('Frequency Hz')
ylabel('pressure dB')
2
(5)
f_noleak = 12800
phi_noleak=2*pi*f_noleak*t_phase_noleak;
delta_t=t_exp_noleak(2)-t_exp_noleak(1)
delta_t = 1.9531e-05
Fs=1/delta_t
Fs = 51200
v=2.5
v = 2.5000
T=delta_t*length(t_exp_maxleak)
T = 0.0200
3
delta_f = 50
t_axis=0:delta_t:T-delta_t;
y_noleak=v*sin(2*pi*f_noleak*t_axis);
f_maxleak = 12825
phi_maxleak=2*pi*f_noleak*t_phase_maxleak;
y_maxleak=v*sin(2*pi*f_maxleak*t_axis+phi_maxleak);
b = 1×3
24 8 16
v=5
v = 5
4
Y=abs(Y);
%Y=Y.*Y;
Y=Y*ACF; %applying ACF
f_a=m*delta_f; % frequency vector for FFT
Y_rect_noleak=20*log10(Y/(10^3)); %Magnitude
5
%Y=Y.*Y;
Y=Y*ACF; %applying ACF
f_a=m*delta_f; % frequency vector for FFT
Y_flat_maxleak=20*log10(Y/(10^3)); %Magnitude
plot(t_min_flat,y_min_flat,t_min_rect,y_min_rect,f_a,Y_flat_noleak,f_a,Y_rect_noleak)
xlim([0 25600])
legend('Lab: No leak Spectrum with hanning window','Lab: no leak Spectrum with rectangular wind
title('No leakage spectrum comparisonfor lab and matlab generated data in different windows')
xlabel('Frequency Hz')
ylabel('pressure dB')
6
plot(t_max_flat,y_max_flat,t_max_rect,y_max_rect,f_a,Y_flat_maxleak,f_a,Y_rect_maxleak)
xlim([0 25600])
legend('Lab: Max leak Spectrum with hanning window','Lab: Max leak Spectrum with rectangular wi
title('Greatest leakage spectrum with different windows')
xlabel('Frequency Hz')
ylabel('pressure dB')
7
(6)
8
Y=Y(m+1); %keeping only +ve frequencies of FFT
Y(2:end-1) = 2* Y(2:end-1); %Multiplying all values except DC & Nyquest by 2 for compensating -
ACF=1/mean(flattopwin(n)); %amplitude correction factor for hanning window
Y=abs(Y);
%Y=Y.*Y;
Y=Y*ACF; %applying ACF
f_a=m*delta_f; % frequency vector for FFT
Y_flat_noleak8=20*log10(Y/(10^3)); %Magnitude
plot(f_a,Y_rect_noleak8,f_a,Y_rect_noleak16,f_a,Y_rect_noleak,f_a,Y_rect_maxleak8,f_a,Y_rect_ma
xlim([0 25600])
legend('No leak Spectrum 8 bit','No leak Spectrum 16 bit','No leak Spectrum 24 bit','Maximum le
title('Rectangulat window for different bit sizes and leakage condition')
xlabel('Frequency Hz')
10
ylabel('pressure dB')
plot(f_a,Y_flat_noleak8,f_a,Y_flat_noleak16,f_a,Y_flat_noleak,f_a,Y_flat_maxleak8,f_a,Y_flat_ma
xlim([0 25600])
legend('No leak Spectrum 8 bit','No leak Spectrum 16 bit','No leak Spectrum 24 bit','Maximum le
title('Flattop window for different bit sizes and leakage condition')
xlabel('Frequency Hz')
ylabel('pressure dB')
11
(7)
f = 159.2000
% Amplitude in g
A=1
A = 1
cf = 100
%Amplitude in mV
a=A*cf
a = 100
12
fs_min = 318.4000
fs=1652 % Minimum sample rate available for NI 9234 which is greater than fs_min
fs = 1652
n_min = 10.3769
n = 16
(8)
%% Flattop and rectangular window with amplitude correction factor is already applied above.
13
Y_hann_maxleak_ECF=20*log10(Y/(10^3)); %Magnitude
plot(f_a,Y_hann_maxleak_ACF,f_a,Y_rect_maxleak,f_a,Y_flat_maxleak)
xlim([0 25600])
legend('hanning','rectangular','flattop')
title('Output spectrum in different windows')
xlabel('Frequency Hz')
ylabel('pressure dB')
plot(f_a,Y_hann_maxleak_ACF,f_a,Y_hann_maxleak_ECF)
xlim([0 25600])
legend('spectrum with ACF','Spectrum with ECF','location','best')
title('ACF & ECF output comparisonfor Hanning window')
xlabel('Frequency Hz')
ylabel('pressure dB')
14
(9)
% Taking 50 averages
T1=T*50;
delta_f=1/T;
t=0:delta_t:T1-delta_t;
y_noleak=v*sin(2*pi*f_noleak*t);
y1=uencode(y_noleak,b,v);
y=udecode(y1,b,v);
N = 50
clear Y1
for a=1:N
y2=y(n); % one measurement period data
y3=y2.*hanning(length(n))'; %applying hanning window
Y=fft(y3)/length(n); %normalized fft
15
m=(0:ceil(length(Y)/2-1)); %half of measurement period
Y=Y(m+1); %keeping only +ve frequencies of FFT
Y(2:end-1) = 2* Y(2:end-1); %Multiplying all values except DC & Nyquest by 2 for compensati
% Saving FFT Value in Matrices form
Y1(a,:)=Y;
n=n+length(n); %next measurement period points with no overlap
end
ACF=1/mean(hanning(length(n))); %amplitude correction factor for hanning window
Y1=abs(Y1);
Y1=Y1*ACF; %applying ACF
f_a=m*delta_f; % frequency vector for FFT
Y_avg=mean(Y1,1);% mean fft
plot(f_a,20*log(Y_avg/10^3))
xlim([0 25600])
legend('Hanning window')
title('spectrum with 50 Averages')
xlabel('Frequency Hz')
ylabel('pressure dB')
(10)
t_square=xlsread('3_10.xlsx',1,'A:A'); %time
y_square=xlsread('3_10.xlsx',1,'B:B'); %AMP
16
n=(1:2024); %measurement period points
T=length(n)*delta_t;
delta_f=1/T;
N=length(t_square)/length(n) %no of measurement periods without overlab
N = 50
clear Y1
% With Hanning Window
n=1:2024;
for a=1:N
y2=y_square(n); % one measurement period data
y3=y2.*hanning(length(n)); %applying hanning window
Y=fft(y3)/length(n); %normalized fft
m=(0:ceil(length(Y)/2-1)); %half of measurement period
Y=Y(m+1); %keeping only +ve frequencies of FFT
Y(2:end-1) = 2* Y(2:end-1); %Multiplying all values except DC & Nyquest by 2 for compensati
% Saving FFT Value in Matrices form
Y1(a,:)=Y;
n=n+length(n); %next measurement period points with no overlap
end
ACF=1/mean(hanning(length(n))); %amplitude correction factor for hanning window
Y1=abs(Y1);
Y1=Y1*ACF; %applying ACF
f_a=m*delta_f; % frequency vector for FFT
Y_avg_hann=mean(Y1,1);% mean fft
plot(f_a,20*log(Y_avg_hann/10^3),f_a,20*log(Y_avg_flat/10^3))
xlim([0 25600])
17
legend('Hanning window','Flattop window')
title('Square Wave spectrum')
xlabel('Frequency Hz')
ylabel('pressure dB')
18