Code Examples (Advanced DSP)

Matlab file for the comparison of window sequences

%**************************************************************************
% Comparison of "standard" and a bit more "advanced" window functions
%**************************************************************************

%**************************************************************************
% Basis parameters
%**************************************************************************
N_win =   64;
N_dft = 1024*16;

%**************************************************************************
% Basic windows - rectangle window
%**************************************************************************
h_rec     = ones(N_win,1);
h_rec     = h_rec / sum(h_rec);

H_rec     = fft(h_rec,N_dft);
H_rec     = H_rec(1:N_dft/2+1);
H_rec_log = 20*log10(abs(H_rec)+eps);

%**************************************************************************
% Basic windows - Hann window
%**************************************************************************
h_han     = hann(N_win);
h_han     = h_han / sum(h_han);

H_han     = fft(h_han,N_dft);
H_han     = H_han(1:N_dft/2+1);
H_han_log = 20*log10(abs(H_han)+eps);

%**************************************************************************
% Basic windows - Hamming window
%**************************************************************************
h_ham     = hamming(N_win);
h_ham     = h_ham / sum(h_ham);

H_ham     = fft(h_ham,N_dft);
H_ham     = H_ham(1:N_dft/2+1);
H_ham_log = 20*log10(abs(H_ham)+eps);

%**************************************************************************
% Advanced windows - "Chebyshev" window
%**************************************************************************
h_che     = chebwin(N_win,10);
h_che     = h_che / sum(h_che);

H_che     = fft(h_che,N_dft);
H_che     = H_che(1:N_dft/2+1);
H_che_log = 20*log10(abs(H_che)+eps);

%**************************************************************************
% Advanced windows - "Prolate" window
%**************************************************************************
h_pro     = dpss(N_win,1.18);
h_pro     = h_pro / sum(h_pro);

H_pro     = fft(h_pro,N_dft);
H_pro     = H_pro(1:N_dft/2+1);
H_pro_log = 20*log10(abs(H_pro)+eps);

%**************************************************************************
% Show results
%**************************************************************************
fig = figure(1);
f = (0:N_dft/2)/N_dft*2;

plot(f,H_rec_log,'b', ...
     f,H_han_log,'r', ...
     f,H_ham_log,'k', ...
     f,H_che_log,'m', ...
     f,H_pro_log,'c', ...
     'LineWidth',2);
legend('Rectangle window', ...
       'Hann window', ...
       'Hamming window', ...
       'Chebyshev window', ...
       'Prolate spheroidal window')
grid on;
xlabel('Normalized frequency \(\Omega/\pi\)','interpreter','latex');
ylabel('dB')
ylim([-90 10])

 

Matlab file for the effects of quantization on filter design

%**************************************************************************
% Design parameters
%**************************************************************************
N   =  8;     % Filter order
f_c =  0.1;   % Normalized cut-off frequency (0 ... 1)
R_p =  0.5;   % Ripple in dB in passband
R_s = 80;     % Stopband attenuation in dB

%**************************************************************************
% Design of an elliptic lowpass filter
%**************************************************************************
[b,a] = ellip(N, R_p, R_s, f_c);

%**************************************************************************
% Show frequency response
%**************************************************************************
fig = figure(1);
set(fig,'Units','Normalized');
set(fig,'Position',[0.1 0.1 0.8 0.8]);
[H,Omega] = freqz(b,a,2048*4,'whole',2);
plot(Omega,20*log10(abs(H)+eps),'b','LineWidth',2);
grid on
axis([0 2 (-R_s -20) 20])
xlabel('Normalized frequency \Omega/\pi')
ylabel('dB')


%**************************************************************************
% Quantization
%**************************************************************************
B = 32; % Number of bits

a_max = max(abs(a));
b_max = max(abs(b));

a_q = round(a / a_max * 2^B) / 2^B * a_max;
b_q = round(b / b_max * 2^B) / 2^B * b_max;

%**************************************************************************
% Show frequency response of quantized filter
%**************************************************************************
[H_q,Omega] = freqz(b_q,a_q,2048*4,'whole',2);
hold on;
plot(Omega,20*log10(abs(H_q)+eps),'r','LineWidth',2);
hold off;
legend('Non-quantized',['Quantized with ',num2str(B),' bits'])

%**************************************************************************
% Show coefficients
%**************************************************************************
format long;
a
a_q
b
b_q

%**************************************************************************
% Transform to cascade of biquad filters
%**************************************************************************
[sos,g] = tf2sos(b,a);

[L,L_tmp] = size(sos);

sos_q = round(sos / max(max(abs(sos))) * 2^B) / 2^B * max(max(abs(sos)));
g_q   = round(g^(1/L) * 2^B) / 2^B;

H_bq_q = freqz(g_q*sos_q(1,1:3),sos_q(1,4:6),2048*4,'whole',2);
for k = 2:L
    H_bq_q = H_bq_q .* freqz(g_q*sos_q(k,1:3),sos_q(k,4:6),2048*4,'whole',2);
end;

%**************************************************************************
% Show frequency response of quantized biquad filters
%**************************************************************************
[H_q,Omega] = freqz(b_q,a_q,2048*4,'whole',2);
hold on;
plot(Omega,20*log10(abs(H_bq_q)+eps),'k','LineWidth',2);
hold off;
legend('Non-quantized',['Quantized with ',num2str(B),' bits'],...
       'Biquad structure (also qunatized)');

 

Website News

01.10.2017: Started with a Tips and Tricks section for KiRAT.

01.10.2017: Talks from Jonas Sauter (Nuance) and Vasudev Kandade Rajan (Harman/Samsung) added.

13.08.2017: New Gas e.V. sections (e.g. pictures or prices) added.

05.08.2017: The first "slide carousel" added.

Recent Publications

J. Reermann, P. Durdaut, S. Salzer, T. Demming,A. Piorra, E. Quandt, N. Frey, M. Höft, and G. Schmidt: Evaluation of Magnetoelectric Sensor Systems for Cardiological Applications, Measurement (Elsevier), ISSN 0263-2241, https://doi.org/10.1016/j.measurement.2017.09.047, 2017

S. Graf, T. Herbig, M. Buck, G. Schmidt: Low-Complexity Pitch Estimation Based on Phase Differences Between Low-Resolution Spectra, Proc. Interspeech, pp. 2316 -2320, 2017

Contact

Prof. Dr.-Ing. Gerhard Schmidt

E-Mail: gus@tf.uni-kiel.de

Christian-Albrechts-Universität zu Kiel
Faculty of Engineering
Institute for Electrical Engineering and Information Engineering
Digital Signal Processing and System Theory

Kaiserstr. 2
24143 Kiel, Germany

Recent News

Jens Reermann Defended his Dissertation with Distinction

On Friday, 21st of June, Jens Reermann defended his research on signals processing for magnetoelectric sensor systems very successfully. After 90 minutes of talk and question time he finished his PhD with distinction. Congratulations, Jens, from the entire DSS team.

Jens worked for about three and a half years - as part of the collaborative research center (SFB) 1261 - on all kinds of signal ...


Read more ...