示例#1
0
def circular_conv(request):
    if request.method == 'POST':
        form = Output(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            input1 = cd['input1']
            input2 = cd['input2']
            x=arr_conv(input1)
            h=arr_conv(input2)
            xd="x(n) = " + str(x)
            hd="h(n) = " + str(h)
            x = np.asarray(x)
            h = np.asarray(h)
            xlen=len(x)
            hlen=len(h)
            r=xlen-hlen
            if xlen>hlen:
                h=np.resize(h, xlen)
                lmax=xlen

            if hlen>xlen:
                x=np.resize(x, hlen)
                lmax=hlen

            if hlen==xlen:
                lmax=xlen
            pad_zero(r,xlen,hlen,h,x)
            h_rev=h[::-1]
            resn=np.resize(res, lmax)
            cir_conv(x,h,lmax,resn,temp,h_rev)
            resn=resn[::-1]
            num=len(resn)
            c='c'
            gp(resn,num,c)
            graphy='<img src="http://kingspp.pythonanywhere.com/media/plots/test.png" height="400px" width="500px" ></img>'
            res_rev='The Circular Convolution of x(n) and y(n) is: ' + str(resn)
        return render_to_response('dsp/circular_conv.html', {'form':form, 'input1': xd, 'input2':hd, 'output':res_rev, 'graphy':graphy,'right_now':datetime.now()}, context_instance=RequestContext(request))
    else:
        form = Output()
        return render_to_response('dsp/circular_conv.html', {'form': form,'right_now':datetime.now()}, context_instance=RequestContext(request))
示例#2
0
def linear_conv(request):
    if request.method == 'POST':
        form = Output(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            input1 = cd['input1']
            input2 = cd['input2']
            x=arr_conv(input1)
            h=arr_conv(input2)
            xd="x(n) = " + str(x)
            hd="h(n) = " + str(h)
            resultd=np.convolve(x, h)
            num=len(resultd)
            result = str(resultd)
            output = "The Linear Convolution of x(n) and y(n) is: " + result
            c='l'
            gp(resultd,num,c)
            graphy='<img src="http://kingspp.pythonanywhere.com/media/plots/test.png" height="400px" width="500px" ></img>'
        return render_to_response('dsp/linear_conv.html', {'form':form, 'input1': xd, 'input2': hd, 'output':output, 'graphy':graphy, 'right_now':datetime.now()}, context_instance=RequestContext(request))
    else:
        form = Output()
        return render_to_response('dsp/linear_conv.html', {'form': form,'right_now':datetime.now()}, context_instance=RequestContext(request))
示例#3
0
def cross_corr(request):
    if request.method == 'POST':
        form = Output(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            input1 = cd['input1']
            input2 = cd['input2']
            x=arr_conv(input1)
            h=arr_conv(input2)
            output=np.correlate(x,h,'full')
            output=np.asarray(output)
            c='cc'
            num=len(output)
            gp(output,num,c)
            graphy='<img src="http://kingspp.pythonanywhere.com/media/plots/test.png" height="400px" width="500px" ></img>'
            output = 'The Crosscorrelation of x(n) and h(n) is : ' + str(output)
            indispx='Input Sequence x(n): ' + '[' + str(input1) + ']'
            indisph='Input Sequence h(n): ' + '[' + str(input2) + ']'
        return render_to_response('dsp/cross_corr.html', {'form':form, 'input1': indispx,'input2': indisph, 'output':output, 'graphy':graphy,'right_now':datetime.now()}, context_instance=RequestContext(request))
    else:
        form = Output()
        return render_to_response('dsp/cross_corr.html', {'form': form,'right_now':datetime.now()}, context_instance=RequestContext(request))
示例#4
0
def ndft(request):
    if request.method == 'POST':
        form = Ndft_form(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            input1 = cd['input1']
            x=arr_conv(input1)
            output = np.fft.fftn(x)
            num=len(output)
            c='nd'
            gp(output,num,c)
            graphy='<img src="http://kingspp.pythonanywhere.com/media/plots/test.png" height="400px" width="500px" aligh="center"></img>'

            output = 'The N-Point Discrete Fourier Transform of x(n) is : ' + str(output)
            indisp='Input Sequence x(n): ' + '[' + str(input1) + ']'
        return render_to_response('dsp/ndft.html', {'form':form, 'input1': indisp, 'output':output, 'graphy':graphy,'right_now':datetime.now()}, context_instance=RequestContext(request))
    else:
        form = Ndft_form()
        return render_to_response('dsp/ndft.html', {'form': form,'right_now':datetime.now()}, context_instance=RequestContext(request))