How to plot the frequency response of a window?
4 views (last 30 days)
Show older comments
Hi,
I am using hann(N), to generate a hanning window of length N. I want to plot the fft response of the window, I am using the below code:
N=16384;
Fs=1.024e6; Ts=1/Fs;
hn=hann(N);
y_hn=fft(hn,N);
y1_hn=(abs(y_hn))/N;
y2_hn=y1_hn(1:N/2);
y3_hn(1)=y2_hn(1);
y3_hn(2:N/2)=2*y2_hn(2:N/2);
y4_hn(1)=y3_hn(1);
y4_hn(2:N/2)=(y3_hn(2:N/2))/(2^(0.5));
y5_hn=20*log10(y4_hn);
f=(0:Fs/N:(Fs/2-Fs/N));
plot(f,y5_hn);
However the generate plot doesn't show any sidelobes (I compare with the plot generated by wvtool).
Could someone suggest how I can fix this?
1 Comment
Chinmay Joshi
on 31 Jan 2019
Try using
N=16384;
Fs=1.024e6;
Ts=1/Fs;
hn=hann(2048);
f = [0:N-1]/N;
hn_abs=(abs(fft(hn,N)));
hn_ss=hn_abs(1:N/2);
hn_dc(1)=hn_ss(1);
hn_rest(2:N/2)=2*hn_ss(2:N/2);
hn_final(1)=hn_rest(1);
hn_final(2:N/2)=(hn_rest(2:N/2))./sqrt(2);
op=mag2db(hn_final);
%f=(0:Fs/N:(Fs/2-Fs/N));
plot(f(1:N/2),op);
the reason you were not getting the response that you were hoping for was that you were using too many data points (16384) for the window. you don't need to use as many window points as much as your fft points.
Answers (1)
Sanjana Chintalacheruvu
on 22 Feb 2021
Edited: Sanjana Chintalacheruvu
on 22 Feb 2021
Hi Ashutosh and Chinmay, I have a question. I have signal values ( not a function) from the testing data. where can I input these signal values in the code above? I am not familiar with this frequency analysis and I am trying to regenerate shaker result plots using different filters such as overlap, windowing in matlab. I only have excel file with signal values and time value. Thanks in advance!
0 Comments
See Also
Categories
Find more on Audio I/O and Waveform Generation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!