# Apply the Hamming window to a sinusoidal signal

I am a novice in signal processing. I am writing a code to apply the hamming window to a sinusoidal signal. So first I have digitized my sinusoidal signal by choosing a sampling rate more than twice its frequency.

These are the values for the signal: F=500 Hz, T=2 ms, and sampling rate=2000 Hz.

Now, I guess I have to multiply the function of the window to the signal so:

for (i=0; i<windowSize; i++)
data(i)=signal(i)*window(i)
i=i+0.5;  //sampling time


My question is when we multiply the window to the signal, does the window function has to be digitized by the sampling rate of the signal or it can be digitized anyway we want? In the code I have digitized the window function according to the sampling rate. Thank you.

Generally, you're better of just indexing via integers:

for (i=0; i<windowsize; i++)
data(i)=signal(i)*window(i)


and keeping track of actual times separately.

As @CMDoolittle says, the window isn't really a signal so it's not really sampled. And most window definitions just assume that the window is integer indexed: • So if the windowsize is equal to the length of the signal, is it correct to assume that the window size is equal to the acquisition time?, in other words: is the unit of windowsize seconds?
– Jack
Aug 27 '15 at 16:49
• Effectively, yes, the window duration is in sections, but the value of the window length ($N$ in the equation) will be just an integer without units.
– Peter K.
Aug 27 '15 at 16:52
• So the value of N is the value of the acquisition time, right?
– Jack
Aug 27 '15 at 16:53
• No, it will just be the length of the vector signal --- a unitless integer.
– Peter K.
Aug 27 '15 at 16:56
• So if I apply FFT to this chunck (window), how would I know the length of my signal in time that is converted in to frequency domain? Say I have a chirped signal and I wat to apply the window function only on a part of my signal.
– Jack
Aug 28 '15 at 11:55

The window isn't "sampled" as it isn't a signal, really. It's a vector that you construct, and it doesn't matter how you construct it. The window vector just has to be the same length as your signal vector.

• Which is equal to acquisition time in seconds?
– Jack
Aug 27 '15 at 16:51
• We usually don't think about a window sequence as having a time duration (measured in seconds). We generally think of a window sequence as merely having some integer number of samples. If you wrote, “I want to multiply a signal sequence by Peter K’s Hamming window sequence. What should be the value of N?” To answer that question we don’t need to know the sample rate, or the start/stop time duration, of your signal. All we need to know is what is the length of your signal sequence measured in samples. If you said your signal sequence length is 2000 samples, then N = 2000. Aug 28 '15 at 8:20

You can also use a more efficient way to program this by vectorizing the for loop, e.g.

T=2e-3;
F=500;
fs=2000;
N=round(T*fs);
n=0:N-1;
signal=sin(2*pi*F*n/fs);
a=0.54;
b=1-a;
w=a-b*cos(2*pi*n/(N-1));
data=w.*signal;