0% found this document useful (0 votes)
1 views20 pages

Submission Assign3

The document outlines the parameters and results of generating sinusoidal signals with varying leakage conditions using different windowing techniques in a signal processing context. It compares the performance of MATLAB generated signals against lab signals, highlighting the impact of ADC bits on noise floor and signal-to-noise ratio. The results indicate that the flat top window minimizes amplitude error while rectangular windows exhibit higher leakage and noise levels.

Uploaded by

shamip105
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views20 pages

Submission Assign3

The document outlines the parameters and results of generating sinusoidal signals with varying leakage conditions using different windowing techniques in a signal processing context. It compares the performance of MATLAB generated signals against lab signals, highlighting the impact of ADC bits on noise floor and signal-to-noise ratio. The results indicate that the flat top window minimizes amplitude error while rectangular windows exhibit higher leakage and noise levels.

Uploaded by

shamip105
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

MEEM 5700 Assignment#2 Hari P Kafle

FALL 2018 [email protected]


1. Setting parameters for Generate Sinusoidal signal with no leakage
M# No. M23912976 5th Digid => 1
Sampling Frequency Fs=51,200/1=51,200 Hz Center of spectrum, Fmax1=Fs/4 = 51,200/4 =12,800 Hz
Taking Sampling frequency N=1024 delta_f = Fs/N = 51,200/1024 = 50Hz
Wndow used in NIDAQ system: Flat top
2. Setting parameters for Generate Sinusoidal signal with max leakage
Spectrum Freq Fmax2=Fmax1+(delta_f)/2 =12,800 +50/2 =12,825
Wndow used in NIDAQ system: rectangular
All other parameter will be same as point number 1.
3. Setting parameters for Generate Sinusoidal signal with smallest frequency error & smallest amplitude error
Smallest frequency error window: Rectangular window
Smallest amplitude error window: flat top window
4. Plot results
Result shows rectangular window has lower amplitude due to higher leakage. Noise floor for rectangular window is
significantly higher than flattop window. Flattop amplitude is nearly same for bith no leakage & maximum leakage
case but noise floor looks more noisy for maximum leakage case

Detailed figures are shown in appendix (4)

5. Matlab generated & Lab signal comparison


Matlab generated signal has smaller noise floor
compared to lab signal
Matlab generated rectangular windoe data has
very low noise floor and high accuracy of amplitude
MEEM 5700 Assignment#2 Hari P Kafle
FALL 2018 [email protected]

6. Effect of ADC bits on signal


Signal with higher ADC bit has lower noise
floor and hence higher SNR
For Matlab generated no leakage signal
All three bit spectrum got overlapped

7. Signal processing parameter for accelerometer calibration


%% To estimate amplitude in time domain
% Minimum sampling frequency required
fs_min=2*f
fs=1652 % Minimum sample rate available for NI 9234 which is greater than fs_min
n_min=fs/f=10.37 %minimum no. of points required to complete one cycle
n=2^nextpow2(n_min)=16 %Next blocksize available in NI 9234
%%To estimate in frequency domain
% Apply flattop window in the time domain data
% Do FFT on the data acquired and apply amplitude correction factor and FFT other scalings.
% Find the amplitude by taking absolute value of the spectrum
Refer appendix for detailed calculation

8. All 3 windows applied on my code and results are in Appendix(8)

9. FFT block averaging done and plotted on Annexure (9)

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)

t_min_flat=xlsread('No leak.xlsx',1,'A:A'); %time : minimum leakage in flat top window


y_min_flat=xlsread('No leak.xlsx',1,'B:B'); %AMP: minimum leakage in flat top window
t_min_rect=xlsread('No leak.xlsx',4,'A:A'); %time : maximum leakage in rectangular window%
y_min_rect=xlsread('No leak.xlsx',4,'B:B'); %Amplitude : minimum leakage in rectangular window%
t_max_flat=xlsread('Max leak.xlsx',1,'A:A'); %time : maximum leakage in flat top window
y_max_flat=xlsread('Max leak.xlsx',1,'B:B'); %AMP: maximum leakage in flat top window
t_max_rect=xlsread('Max leak.xlsx',3,'A:A'); %%time : maximum leakage in rectangular window
y_max_rect=xlsread('Max leak.xlsx',3,'B:B'); %Amplitude : maximum leakage in rectangular window

t_exp_maxleak=xlsread('Max leak.xlsx',4,'A:A'); %%time : analog signal


y_exp_maxleak=xlsread('Max leak.xlsx',4,'B:B'); %Amplitude : maximum leakage in rectangular win
t_exp_noleak=xlsread('No leak.xlsx',5,'A9:A1032'); %%time : analog signal
y_exp_noleak=xlsread('No leak.xlsx',5,'B9:B1032'); %Amplitude : maximum leakage in rectangular
t_phase_noleak=t_exp_noleak(min(find(y_exp_noleak<0)));
t_phase_maxleak=t_exp_maxleak(min(find(y_exp_maxleak>0)));

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)

%Sine wave generate for No leakage


f_noleak=12800

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

delta_f= 1/T % 1/T--> Frequency resolution of FFT

3
delta_f = 50

t_axis=0:delta_t:T-delta_t;
y_noleak=v*sin(2*pi*f_noleak*t_axis);

%Sine wave generate for Max leakage


f_maxleak=f_noleak+delta_f/2

f_maxleak = 12825

phi_maxleak=2*pi*f_noleak*t_phase_maxleak;
y_maxleak=v*sin(2*pi*f_maxleak*t_axis+phi_maxleak);

%Quantize signal with virtual ADC


%Quantize data with virtual ADC normal range
b=[24 8 16] %ADC bits

b = 1×3
24 8 16

v=5

v = 5

%for no leakage signal


for a=1:3
y1=uencode(y_noleak,b(a),v);
y_quant_noleak(a,:)=udecode(y1,b(a),v);
end

%for maximum leakage signal


for a=1:3
y1=uencode(y_maxleak,b(a),v);
y_quant_maxleak(a,:)=udecode(y1,b(a),v);
end

%FFT of Matlab generated signals for 24 bit ADC

% with rectangular window & no leak


n=length(y_quant_noleak(1,:)); %measurement period points
y2=y_quant_noleak(1,:).*rectwin(n)'; %applying rectangular window
Y=fft(y2)/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 compensating -
ACF=1/mean(rectwin(n)); %amplitude correction factor

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

% with flattop window & no leak


n=length(y_quant_noleak(1,:)); %measurement period points
y2=y_quant_noleak(1,:).*flattopwin(n)'; %applying flattop window
Y=fft(y2)/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 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_noleak=20*log10(Y/(10^3)); %Magnitude

% with rectangular window & max leak


n=length(y_quant_maxleak(1,:)); %measurement period points
y2=y_quant_maxleak(1,:).*rectwin(n)'; %applying rectangular window
Y=fft(y2)/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 compensating -
ACF=1/mean(rectwin(n)); %amplitude correction factor
Y=abs(Y);
%Y=Y.*Y;
Y=Y*ACF; %applying ACF
f_a=m*delta_f; % frequency vector for FFT
Y_rect_maxleak=20*log10(Y/(10^3)); %Magnitude

% with flattop window & max leak


n=length(y_quant_maxleak(1,:)); %measurement period points
y2=y_quant_maxleak(1,:).*flattopwin(n)'; %applying rectangular window
Y=fft(y2)/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 compensating -
ACF=1/mean(flattopwin(n)); %amplitude correction factor for hanning window
Y=abs(Y);

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

%FFT of Matlab signal


% with rectangular window & no leak
n=length(y_exp_noleak); %measurement period points
y21=y_exp_noleak.*rectwin(n); %applying hanning window
Y=fft(y21)/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 compensating -
ACF=1/mean(rectwin(n)); %amplitude correction factor for hanning window
Yr=abs(Y);
%Y=Y.*Y;
Y=Yr*ACF; %applying ACF
f_a=m*delta_f; % frequency vector for FFT
Y_exp_rect=20*log10(Y/(10^3)); %Magnitude

% with flattop window & no leak


n=length(y_exp_noleak); %measurement period points
y22=y_exp_noleak.*flattopwin(n); %applying hanning window
Y=fft(y22)/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 compensating -
ACF=1/mean(flattopwin(n)); %amplitude correction factor for hanning window
Yf=abs(Y);
%Y=Y.*Y;
Y=Yf*ACF; %applying ACF
f_a=m*delta_f; % frequency vector for FFT
Y_exp_flat=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)

%FFT of Matlab generated signals for 8 bit ADC

% with rectangular window & no leak


n=length(y_quant_noleak(2,:)); %measurement period points
y2=y_quant_noleak(2,:).*rectwin(n)'; %applying rectangular window
Y=fft(y2)/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 compensating -
ACF=1/mean(rectwin(n)); %amplitude correction factor
Y=abs(Y);
%Y=Y.*Y;
Y=Y*ACF; %applying ACF
f_a=m*delta_f; % frequency vector for FFT
Y_rect_noleak8=20*log10(Y/(10^3)); %Magnitude

% with flattop window & no leak


n=length(y_quant_noleak(2,:)); %measurement period points
y2=y_quant_noleak(2,:).*flattopwin(n)'; %applying flattop window
Y=fft(y2)/length(n); %normalized fft
m=(0:ceil(length(Y)/2-1)); %half of measurement period

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

% with rectangular window & max leak


n=length(y_quant_maxleak(2,:)); %measurement period points
y2=y_quant_maxleak(2,:).*rectwin(n)'; %applying rectangular window
Y=fft(y2)/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 compensating -
ACF=1/mean(rectwin(n)); %amplitude correction factor
Y=abs(Y);
%Y=Y.*Y;
Y=Y*ACF; %applying ACF
f_a=m*delta_f; % frequency vector for FFT
Y_rect_maxleak8=20*log10(Y/(10^3)); %Magnitude

% with flattop window & no leak


n=length(y_quant_noleak(2,:)); %measurement period points
y2=y_quant_maxleak(2,:).*flattopwin(n)'; %applying rectangular window
Y=fft(y2)/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 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_maxleak8=20*log10(Y/(10^3)); %Magnitude

%FFT of Matlab generated signals for 16 bit ADC

% with rectangular window & no leak


n=length(y_quant_noleak(3,:)); %measurement period points
y2=y_quant_noleak(2,:).*rectwin(n)'; %applying rectangular window
Y=fft(y2)/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 compensating -
ACF=1/mean(rectwin(n)); %amplitude correction factor
Y=abs(Y);
%Y=Y.*Y;
Y=Y*ACF; %applying ACF
f_a=m*delta_f; % frequency vector for FFT
9
Y_rect_noleak16=20*log10(Y/(10^3)); %Magnitude

% with flattop window & no leak


n=length(y_quant_noleak(3,:)); %measurement period points
y2=y_quant_noleak(2,:).*flattopwin(n)'; %applying flattop window
Y=fft(y2)/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 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_noleak16=20*log10(Y/(10^3)); %Magnitude

% with rectangular window & max leak


n=length(y_quant_maxleak(3,:)); %measurement period points
y2=y_quant_maxleak(2,:).*rectwin(n)'; %applying rectangular window
Y=fft(y2)/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 compensating -
ACF=1/mean(rectwin(n)); %amplitude correction factor
Y=abs(Y);
%Y=Y.*Y;
Y=Y*ACF; %applying ACF
f_a=m*delta_f; % frequency vector for FFT
Y_rect_maxleak16=20*log10(Y/(10^3)); %Magnitude

% with flattop window & no leak


n=length(y_quant_noleak(3,:)); %measurement period points
y2=y_quant_maxleak(2,:).*flattopwin(n)'; %applying rectangular window
Y=fft(y2)/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 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_maxleak16=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)

% Accelerometer calibrating frequency = 159.2Hz


f=159.2

f = 159.2000

% Amplitude in g
A=1

A = 1

% Calibration factor in mV/g


cf=100

cf = 100

%Amplitude in mV
a=A*cf

a = 100

%% To estimate amplitude in time domain


% Minimum sampling frequency required
fs_min=2*f

12
fs_min = 318.4000

fs=1652 % Minimum sample rate available for NI 9234 which is greater than fs_min

fs = 1652

n_min=fs/f %minimum no. of points required to complete one cycle

n_min = 10.3769

n=2^nextpow2(n_min) %Next blocksize available in NI 9234

n = 16

%%To estimate in frequency domain


% Apply flattop window in the time domain data
% Do FFT on the data acquired and apply amplitude correction factor and FFT other scalings.
% Find the amplitude by taking absolute value of the spectrum

(8)

%% Flattop and rectangular window with amplitude correction factor is already applied above.

% with hanning window & ACF


n=length(y_quant_maxleak(1,:)); %measurement period points
y2=y_quant_maxleak(1,:).*hanning(n)'; %applying window
Y=fft(y2)/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 compensating -
ACF=1/mean(hanning(n)); %amplitude correction factor
Y=abs(Y);
%Y=Y.*Y;
Y=Y*ACF; %applying ACF
f_a=m*delta_f; % frequency vector for FFT
Y_hann_maxleak_ACF=20*log10(Y/(10^3)); %Magnitude

% with hanning window & ECF


n=length(y_quant_maxleak(1,:)); %measurement period points
y2=y_quant_maxleak(1,:).*hanning(n)'; %applying window
Y=fft(y2)/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 compensating -
ACF=1/rms(hanning(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

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);

%Quantize signal with virtual ADC


b=24; %ADC bits
v=5; %ADC Range

y1=uencode(y_noleak,b,v);
y=udecode(y1,b,v);

n=(1:T/delta_t); %measurement period points


N=length(t)/length(n) %no of measurement periods without overlab

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

% With Flattop Window


clear Y1
n=1:2024;
for a=1:N
y2=y_square(n); % one measurement period data
y3=y2.*flattopwin(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(flattopwin(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_flat=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

You might also like