I am given the coefficients of an FIR filter. I have created its impulse response through a convolution with a unit pulse. Now I want to plot the frequency spectrum. I perform zero-padding and windowing with a blackman-window. This does not seem to have a big effect on my result though. Still, I wonder: For some reason my amplitude of the resulting spectrum is not normalized correctly. Can somebody see what I am doing wrong?
fs = 44100;%sampling frequency Ts = 1/fs; %time step t = 0:1/fs:2-Ts; %signal duration unit_pulse = zeros(length(t),1); unit_pulse(1) = 1; b = [1/8 1/8 1/8 1/8 1/8 1/8 1/8 1/8]; ir_filter = filter(b,1,unit_pulse); nfft = length(ir_filter); %length of the time domain signal %in order to obtain a good frequency resolution, pad the signal with zeros %such that the length of the signal is a power of 2 no_zeros = (2^nextpow2(nfft)-nfft)/2; padding = zeros(no_zeros,1); signal = vertcat(padding, ir_filter, padding); windowed_signal = signal .* blackman(length(signal)); spectrum_2side = real(fftshift(fft(windowed_signal))) ./ nfft; f_2side = linspace(-fs/2, fs/2, length(windowed_signal)); spectrum_1side = 2*spectrum_2side(end/2+1:end); f_1side = f_2side(end/2+1:end); fig2 = figure(); hold on grid on plot(f_1side, spectrum_1side, 'b'); plot(f_2side, spectrum_2side, 'r');