Пример #1
0
def conv2dsep(x,h,v):
    (Nrx,Ncx)=x.shape
    y=np.zeros((Nrx+len(h)-1, Ncx+len(v)-1))
    for m in range(Nrx):
        y[m,:]=mm.conv(x[m,:],h)
    for n in range(Ncx+len(v)-1):
        y[:,n]=mm.conv(y[:Nrx,n],v)
    return(y)
Пример #2
0
import math
import cmath
import numpy as np
import imageio
import MyModule as mm
import time

x=[1,2,3,4]
x1=mm.complex_idft(mm.complex_dft(x))
x2=mm.complex_idft(mm.fft(x))
x3=mm.ifft(mm.complex_dft(x))
x4=mm.ifft(mm.fft(x))

y=[5,6,7,8]
output1=mm.conv(x,y)
output2=mm.ifft(mm.fft(x)*mm.fft(y))


img=imageio.imread('lena.png')#[256-128:256+128,256-128:256+128]

t1=time.time()
imageio.imwrite('lenareconstructed.png',mm.ifft2d(mm.fft2d(img)))

t2=time.time()
print('img ifft takes %10.2f sec' %( t2-t1))

Пример #3
0
    window[N//2-M//2+n]=0.54-0.46*math.cos(2*math.pi*n/M)
lp_windowed=lpr*window
LP_windowed=mm.fft(lp_windowed)

plt.plot(lp_windowed.real)
plt.plot(np.abs(LP_windowed))

'''hp-windowed'''
hp=-1.0*lp_windowed
hp[N//2]+=1.0
plt.figure()
plt.plot(hp.real)
plt.plot(np.abs(mm.fft(hp)))


plt.plot(mm.conv(x,lp_windowed))

'''filter design'''
PP=np.zeros((N),dtype=complex)
Nc1=int(0.15*N)
Nc2=int(0.2*N)
Nc3=int(0.3*N)
Nc4=int(0.4*N)
Nc5=int(0.45*N)
for n in range(Nc1):
    PP[n]=1.0
    PP[(N-n)%N]=1.0
for n in range(Nc1,Nc2):
    PP[n]=0.5
    PP[(N-n)%N]=0.5
for n in range(Nc2,Nc3):