Skip to content
Snippets Groups Projects
Hann_Windowed_Complex_Sinusoid.py 1.12 KiB
#!/usr/bin/env python

import numpy as np
from numpy import cos,pi
import scipy as sp
from pylab import *


""" Hann-Windowed Complex Sinusoid """
 
# Analysis parameters:
M = 31         # Window length 
N = 64         # FFT length (zero padding factor near 2)

# Signal parameters:
wxT = 2.*pi/4.  # Sinusoid frequency (rad/sample)
A = 1.          # Sinusoid amplitude
phix = 0.       # Sinusoid phase

# Compute the signal x:
n = np.arange(N)    # time indices for sinusoid and FFT
x = A * exp(1j*wxT*n+phix) # complex sine [1,j,-1,-j...]

# Compute Hann window:
nm = np.arange(M)   # time indices for window computation

# Hann window = "raised cosine", normalization (1/M)
# chosen to give spectral peak magnitude at 1/2:
w = (1./M) * (cos((pi/M)*(nm-(M-1.)/2.)))**2.  

wzp = concatenate((w,np.zeros(N-M))) # zero-pad out to the length of x
xw = x * wzp          # apply the window w to signal x

figure()
subplot(1,1,1)

# Display real part of windowed signal and Hann window
plot(n,wzp,'-k')
plot(n,real(xw),'*b')
title(['Hann Window and Windowed, Zero-Padded, Sinusoid (Real Part)'])
xlabel('Time (samples)')
ylabel('Amplitude')

show()