ssnrs = [] hsnrs = [] thsemissnrs = [] thf1snrs = [] thf2snrs = [] thf3snrs = [] smses = [] hmses = [] thsemismses = [] thf1mses = [] thf2mses = [] thf3mses = [] tds = [s.createSin(50, 60, 0), s.createPulse(50, 60, 0), s.createSpikes(0)] for i in range(len(ods)): sdr = DenoiseRsult(tds[i], spds[i]) hdr = DenoiseRsult(tds[i], hpds[i]) thsemisdr = DenoiseRsult(tds[i], thsemispds[i]) thf1dr = DenoiseRsult(tds[i], thf1pds[i]) thf2dr = DenoiseRsult(tds[i], thf2pds[i]) thf3dr = DenoiseRsult(tds[i], thf3pds[i]) ssnrs.append(sdr.snr()) hsnrs.append(hdr.snr()) thsemissnrs.append(thsemisdr.snr()) thf1snrs.append(thf1dr.snr()) thf2snrs.append(thf2dr.snr()) thf3snrs.append(thf3dr.snr()) smses.append(sdr.mse()) hmses.append(hdr.mse()) thsemismses.append(thsemisdr.mse())
sfp2pd = swt.swtrec(npce2s, wtname='sym6') sfp1pds.append(sfp1pd) sfp2pds.append(sfp2pd) sf1snrs = [] sf2snrs = [] sfwp1snrs = [] sfwp2snrs = [] sf1mses = [] sf2mses = [] sfwp1mses = [] sfwp2mses = [] tds = [s.createSin(50, 60, 0), s.createPulse(50, 60, 0), s.createSpikes(0)] for i in range(len(tds)): sf1dr = DenoiseRsult(tds[i], sf1pds[i]) sf2dr = DenoiseRsult(tds[i], sf2pds[i]) sfwp1dr = DenoiseRsult(tds[i], sfp1pds[i]) sfwp2dr = DenoiseRsult(tds[i], sfp2pds[i]) sf1snrs.append(sf1dr.snr()) sf2snrs.append(sf2dr.snr()) sfwp1snrs.append(sfwp1dr.snr()) sfwp2snrs.append(sfwp2dr.snr()) sf1mses.append(sf1dr.mse()) sf2mses.append(sf2dr.mse()) sfwp1mses.append(sfwp1dr.mse()) sfwp2mses.append(sfwp2dr.mse()) snrss = [sf1snrs, sf2snrs, sfwp1snrs, sfwp2snrs] snrsn = ['sf1snrs', 'sf2snrs', 'sfwp1snrs', 'sfwp2snrs']
ncoeffs2 = dwd.thprocess2(coeffs, ths=bsths, thf='thf3', thps=[2 + 2 * k for k in range(dl)]) gthpd = dwd.dwtrec(ncoeffs1, wtname='db4') bsthpd = dwd.dwtrec(ncoeffs2, wtname='db4') gthpds.append(gthpd) bsthpds.append(bsthpd) gthsnrs = [] bsthsnrs = [] gthmses = [] bsthmses = [] tds = [s.createSin(50, 60, 0), s.createPulse(50, 60, 0), s.createSpikes(0)] for i in range(len(tds)): gthdr = DenoiseRsult(tds[i], gthpds[i]) bsthdr = DenoiseRsult(tds[i], bsthpds[i]) gthsnrs.append(gthdr.snr()) bsthsnrs.append(bsthdr.snr()) gthmses.append(gthdr.mse()) bsthmses.append(bsthdr.mse()) print('gthsnrs = {0}'.format(gthsnrs)) print('bsthsnrs = {0}'.format(bsthsnrs)) print('gthmses = {0}'.format(gthmses)) print('bsthmses = {0}'.format(bsthmses)) x = [x for x in range(1000)] plt.figure() for i in range(len(ods)): plt.subplot(3, 2, 2 * i + 1) plt.title('{0} signal processed by gth'.format(dnames[i]))
ssms = [] hsms = [] thsemissms = [] thf1sms = [] thf2sms = [] thf3sms = [] slrepvs = [] hlrepvs = [] thsemislrepvs = [] thf1lrepvs = [] thf2lrepvs = [] thf3lrepvs = [] tds = [s.createSin(50, 60, 0), s.createPulse(50, 60, 0), s.createSpikes(0)] for i in range(len(ods)): sdr = DenoiseRsult(tds[i], spds[i]) hdr = DenoiseRsult(tds[i], hpds[i]) thsemisdr = DenoiseRsult(tds[i], thsemispds[i]) thf1dr = DenoiseRsult(tds[i], thf1pds[i]) thf2dr = DenoiseRsult(tds[i], thf2pds[i]) thf3dr = DenoiseRsult(tds[i], thf3pds[i]) ssnrs.append(sdr.snr()) hsnrs.append(hdr.snr()) thsemissnrs.append(thsemisdr.snr()) thf1snrs.append(thf1dr.snr()) thf2snrs.append(thf2dr.snr()) thf3snrs.append(thf3dr.snr()) smses.append(sdr.mse()) hmses.append(hdr.mse()) thsemismses.append(thsemisdr.mse())
pd = dwd.dwtrec(ncoeffs, wtname='db4') pdsmatrix[i].append(pd) ssnrs = [] cvsnrs = [] gcvsnrs = [] srmsnrs = [] smses = [] cvmses = [] gcvmses = [] srmmses = [] tds = [s.createSin(50, 60, 0), s.createPulse(50, 60, 0), s.createSpikes(0)] for i in range(len(tds)): sdr = DenoiseRsult(tds[i], gpds[i]) cvdr = DenoiseRsult(tds[i], cvpds[i]) gcvdr = DenoiseRsult(tds[i], gcvpds[i]) srmdr = DenoiseRsult(tds[i], srmpds[i]) ssnrs.append(sdr.snr()) cvsnrs.append(cvdr.snr()) gcvsnrs.append(gcvdr.snr()) srmsnrs.append(srmdr.snr()) smses.append(sdr.mse()) cvmses.append(cvdr.mse()) gcvmses.append(gcvdr.mse()) srmmses.append(srmdr.mse()) snrss = [ssnrs, cvsnrs, gcvsnrs, srmsnrs]
if __name__ == '__main__': ad = GetActualSignal() ad.getwhvalue() od1 = ad.selectvalue(start=11000, end=12024) dl = 4 swt = SWTP(od1) coeffs = swt.swtdec(wtname='db2', delevel=dl) n1coeffs = swt.thprocess(coeffs, thf='soft') n2coeffs = swt.thprocess(coeffs, thf='hard') n3coeffs = swt.thprocess(coeffs, thf='thsemisf') spd = swt.swtrec(n1coeffs, wtname='db2') hpd = swt.swtrec(n2coeffs, wtname='db2') thf1pd = swt.swtrec(n3coeffs, wtname='db2') ad.outputdata(startidex=0, ogdata=od1, pddata=hpd) ssm = DenoiseRsult([], spd).smooth(od1) hsm = DenoiseRsult([], hpd).smooth(od1) thf1sm = DenoiseRsult([], thf1pd).smooth(od1) slrepv = DenoiseRsult([], spd).lrepv(od1, 128) hlrepv = DenoiseRsult([], hpd).lrepv(od1, 128) thf1lrepv = DenoiseRsult([], thf1pd).lrepv(od1, 128) print('sf1sm = {0}'.format(ssm)) print('sfp1sm = {0}'.format(hsm)) print('sfp2sm = {0}'.format(thf1sm)) print('slrepv = {0}'.format(slrepv)) print('hlrepv = {0}'.format(hlrepv)) print('sfp2lrepv = {0}'.format(thf1lrepv))
hsnrs = [] thf3snrs = [] thf3wpsnrs = [] smses = [] hmses = [] thf3mses = [] thf3wpmses = [] tds = [ s.createSin(200, 60, 0), s.createPulse(200, 60, 0), s.createSpikes(0) ] for i in range(len(tds)): sdr = DenoiseRsult(tds[i], spds[i]) hdr = DenoiseRsult(tds[i], hpds[i]) thf3dr = DenoiseRsult(tds[i], thf3pds[i]) thf3wpdr = DenoiseRsult(tds[i], thf3wppds[i]) ssnrs.append(sdr.snr()) hsnrs.append(hdr.snr()) thf3snrs.append(thf3dr.snr()) thf3wpsnrs.append(thf3wpdr.snr()) smses.append(sdr.mse()) hmses.append(hdr.mse()) thf3mses.append(thf3dr.mse()) thf3wpmses.append(thf3wpdr.mse()) snrss = [ssnrs, hsnrs, thf3snrs, thf3wpsnrs]
ad = GetActualSignal() ad.getwhvalue() od1 = ad.selectvalue(start=6000, end=7024) dl = 4 dwd = DWTP(od1) coeffs = dwd.dwtdec(wtname='db2', delevel=dl) gths = [] bsths = [] for i in range(1, len(coeffs)): bthe = BestThEstimate(coeffs[i], thfunction='thf3', thp=2 + 2 * i) thsa = ThSearchAlgorithm() gth = ThSelect(coeffs[i]).DonohoThEx() bsth = thsa.FibonacciSearch(bthe.msesurefuction, [0, 1.5 * gth], 0.01) gths.append(gth) bsths.append(bsth) ncoeffs1 = dwd.thprocess2(coeffs, ths=gths, thf='thf3', thps=[2 + 2 * k for k in range(dl)]) ncoeffs2 = dwd.thprocess2(coeffs, ths=bsths, thf='thf3', thps=[2 + 2 * k for k in range(dl)]) gthpd = dwd.dwtrec(ncoeffs1, wtname='db2') bsthpd = dwd.dwtrec(ncoeffs2, wtname='db2') ad.outputdata(startidex=5000, ogdata=od1, pddata=bsthpd) bsm = DenoiseRsult([], bsthpd).smooth(od1) blrepv = DenoiseRsult([], bsthpd).lrepv(od1, 128) print('bsm = {0}'.format(bsm)) print('blrepv = {0}'.format(blrepv))
P = spta2.spcoCors() for i in range(1, len(coeffs) - 1): spta2.BTHassitIndex(i, pk=0.1, pa=4, mode='srmse') gpth = ThSelect(P[i - 1]).DonohoThEx() sfp1th = ThSearchAlgorithm().FibonacciSearch(spta2.BTHspcothfwp1, [0, 1.5 * gpth], 0.01) sfp2th = ThSearchAlgorithm().FibonacciSearch(spta2.BTHspcothfwp2, [0, 1.5 * gpth], 0.01) gpths.append(gpth) sfp1ths.append(sfp1th) sfp2ths.append(sfp2th) npce1s = spta2.spcoThfwp1(sfp1ths, 0.05) npce2s = spta2.spcoThfwp2(sfp2ths, 4) sfp1pd = swt.swtrec(npce1s, wtname='sym6') sfp2pd = swt.swtrec(npce2s, wtname='sym6') ad.outputdata(startidex=10000, ogdata=od1, pddata=sfp2pd) sf1sm = DenoiseRsult([], sf1pd).smooth(od1) sfp1sm = DenoiseRsult([], sfp1pd).smooth(od1) sfp2sm = DenoiseRsult([], sfp2pd).smooth(od1) sf1lrepv = DenoiseRsult([], sf1pd).lrepv(od1, 128) sfp1lrepv = DenoiseRsult([], sfp1pd).lrepv(od1, 128) sfp2lrepv = DenoiseRsult([], sfp2pd).lrepv(od1, 128) print('sf1sm = {0}'.format(sf1sm)) print('sfp1sm = {0}'.format(sfp1sm)) print('sfp2sm = {0}'.format(sfp2sm)) print('sf1lrepv = {0}'.format(sf1lrepv)) print('sfp1lrepv = {0}'.format(sfp1lrepv)) print('sfp2lrepv = {0}'.format(sfp2lrepv))
hpd = pywt.waverec(nhcoeffs, 'db4') spds.append(spd) hpds.append(hpd) ssnrs = [] hsnrs = [] smses = [] hmses = [] ssms = [] hsms = [] slrepvs = [] hlrepvs = [] tds = [s.createSin(50, 60, 0), s.createPulse(50, 60, 0), s.createSpikes(0)] for i in range(len(tds)): sdr = DenoiseRsult(tds[i], spds[i]) hdr = DenoiseRsult(tds[i], hpds[i]) ssnrs.append(sdr.snr()) hsnrs.append(hdr.snr()) smses.append(sdr.mse()) hmses.append(hdr.mse()) ssms.append(sdr.smooth(ods[i])) hsms.append(hdr.smooth(ods[i])) slrepvs.append(sdr.lrepv(ods[i], 32)) hlrepvs.append(hdr.lrepv(ods[i], 32)) print('ssnrs = {0}'.format(ssnrs)) print('hsnrs = {0}'.format(hsnrs)) print('smses = {0}'.format(smses)) print('hmses = {0}'.format(hmses)) print()
x = [x for x in range(1000)] plt.figure() plt.subplot(3, 2, 1) plt.plot(x, td1) plt.title("True sine signal") plt.subplot(3, 2, 2) plt.plot(x, od1) plt.title("Noisy sine signal") plt.subplot(3, 2, 3) plt.plot(x, td2) plt.title("True pulse signal") plt.subplot(3, 2, 4) plt.plot(x, od2) plt.title("Noisy pulse signal") plt.subplot(3, 2, 5) plt.plot(x, td3) plt.title("True spike signal") plt.subplot(3, 2, 6) plt.plot(x, od3) plt.title("Noisy spike signal") dn1 = DenoiseRsult(td1, od1) dn2 = DenoiseRsult(td2, od2) dn3 = DenoiseRsult(td3, od3) print(dn1.snr(), dn2.snr(), dn3.snr()) plt.tight_layout() plt.show()
b = len(bceths) nbces = DWTP(od).thprocess(bces, ths=bceths, thf='soft') nbcoeff = BlockThMethod(coeffs[j]).recoverdata( nbces[1:]) # 除去添加的[0]系数 nbcoeffs.append(np.asarray(nbcoeff)) blpd = DWTP(od).dwtrec(nbcoeffs, 'db4') blpds.append(blpd) ssnrs = [] blsnrs = [] smses = [] blmses = [] tds = [s.createSin(50, 60, 0), s.createPulse(50, 60, 0), s.createSpikes(0)] for i in range(len(tds)): sdr = DenoiseRsult(tds[i], spds[i]) bldr = DenoiseRsult(tds[i], blpds[i]) ssnrs.append(sdr.snr()) blsnrs.append(bldr.snr()) smses.append(sdr.mse()) blmses.append(bldr.mse()) print('ssnrs = {0}'.format(ssnrs)) print('blsnrs = {0}'.format(blsnrs)) print('smses = {0}'.format(smses)) print('blmses = {0}'.format(blmses)) x = [x for x in range(1000)] plt.figure() plt.subplot(3, 2, 1) plt.title('Sine signal processed by soft threshold') plt.plot(x, spds[0])
od3 = s.createSpikes(4) ods = [od1, od2, od3] td1 = s.createSin(50, 60, 0) td2 = s.createPulse(50, 60, 0) td3 = s.createSpikes(0) tds = [td1, td2, td3] for i in range(len(ods)): dwd = DWTP(ods[i]) dwtd = DWTP(tds[i]) coeffs = dwd.dwtdec(wtname='db4', delevel=4) tcoeffs = dwtd.dwtdec(wtname='db4', delevel=4) gcvths = [] srmths = [] mses = [] bthe = BestThEstimate(coeffs[2], thfunction='thf3', thp=4) for k in range(1, 100): gcvth = bthe.gcvfunction(k / 10) srmth = bthe.msesurefuction(k / 10) thc = ThFuction(coeffs[2]).thf3(k / 10, 4) mse = DenoiseRsult(tcoeffs[2], thc).mse() gcvths.append(gcvth) srmths.append(srmth) mses.append(mse) x = [x / 10 for x in range(1, 100)] plt.figure() l1, = plt.plot( x, [y + 1 for y in srmths / np.max([abs(x) for x in srmths])], linestyle='-') l2, = plt.plot(x, mses / np.max(mses), linestyle='solid') plt.legend(handles=[l1, l2], labels=['Sure estimation', 'MSE']) plt.show()