1
$\begingroup$

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.

$\endgroup$

3 Answers 3

0
$\begingroup$

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:

enter image description here

$\endgroup$
10
  • $\begingroup$ 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? $\endgroup$
    – Jack
    Aug 27, 2015 at 16:49
  • $\begingroup$ 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. $\endgroup$
    – Peter K.
    Aug 27, 2015 at 16:52
  • $\begingroup$ So the value of N is the value of the acquisition time, right? $\endgroup$
    – Jack
    Aug 27, 2015 at 16:53
  • $\begingroup$ No, it will just be the length of the vector signal --- a unitless integer. $\endgroup$
    – Peter K.
    Aug 27, 2015 at 16:56
  • $\begingroup$ 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. $\endgroup$
    – Jack
    Aug 28, 2015 at 11:55
1
$\begingroup$

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.

$\endgroup$
2
  • $\begingroup$ Which is equal to acquisition time in seconds? $\endgroup$
    – Jack
    Aug 27, 2015 at 16:51
  • $\begingroup$ 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. $\endgroup$ Aug 28, 2015 at 8:20
1
$\begingroup$

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;
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.