From 524ec7bf090ac9e3b9c8c5045a983c0f09d1cd82 Mon Sep 17 00:00:00 2001 From: hackens-bot Date: Thu, 16 Jan 2025 13:42:30 +0100 Subject: [PATCH] =?UTF-8?q?Partie=20HW=20faite=20a=20peu=20pr=C3=A8s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- releves_experimentaux/data.md | 6 + releves_experimentaux/data_8Ohm.md | 7 + releves_experimentaux/mic_impedance.md | 8 + xfer_tracer/script.py | 273 ++++++++++++++++--------- 4 files changed, 195 insertions(+), 99 deletions(-) create mode 100644 releves_experimentaux/data.md create mode 100644 releves_experimentaux/data_8Ohm.md create mode 100644 releves_experimentaux/mic_impedance.md diff --git a/releves_experimentaux/data.md b/releves_experimentaux/data.md new file mode 100644 index 0000000..0e165f3 --- /dev/null +++ b/releves_experimentaux/data.md @@ -0,0 +1,6 @@ +Fct de transfert; sans écho, sans ampli active. Sortie audio -> HP -> Micro + +X = [61.900000000000006, 64.9, 68.1, 71.5, 75.0, 78.7, 82.5, 86.6, 90.9, 95.3, 100.0, 105.0, 110.00000000000001, 114.99999999999999, 121.0, 127.0, 133.0, 140.0, 147.0, 154.0, 162.0, 169.0, 178.0, 187.0, 196.0, 204.99999999999997, 215.0, 225.99999999999997, 237.0, 249.00000000000003, 261.0, 274.0, 287.0, 301.0, 316.0, 332.0, 348.0, 365.0, 383.0, 401.99999999999994, 422.0, 442.0, 463.99999999999994, 487.0, 511.00000000000006, 536.0, 562.0, 590.0, 619.0, 649.0, 681.0, 715.0, 750.0, 787.0, 825.0, 866.0, 909.0, 952.9999999999999, 1000.0, 1050.0, 1100.0, 1150.0, 1210.0, 1270.0, 1330.0, 1400.0, 1470.0, 1540.0, 1620.0, 1690.0, 1780.0, 1870.0, 1960.0, 2050.0, 2150.0, 2260.0, 2370.0, 2490.0, 2610.0, 2740.0, 2870.0, 3010.0, 3160.0, 3320.0, 3480.0, 3650.0, 3830.0, 4019.9999999999995, 4220.0, 4420.0, 4640.0, 4870.0, 5110.0, 5360.0, 5620.0, 5900.0, 6190.0, 6490.0, 6810.0, 7150.0, 7500.0, 7870.0, 8250.0, 8660.0, 9090.0, 9530.0, 10000.0, 10500.0, 11000.0, 11500.0, 12100.0, 12700.0, 13300.0, 14000.0, 14700.0, 15400.0, 16200.000000000002, 16900.0, 17800.0, 18700.0, 19600.0] + +H = [(-0.003084028020196348-0.0002298275962775344j), (-0.003678459869987419-0.001269262714219824j), (-0.0040725795066086905-0.0006918289331989035j), (-0.005174202142953045-0.0005741321907548909j), (-0.005349156896629843-0.0007972384793902896j), (-0.006411854176717437+0.00037527354586796473j), (-0.006953297795439259+0.00019751115629307943j), (-0.007918195826850808+0.00039588258355878757j), (-0.008309377541740992+0.00016893539098912952j), (-0.008653773438586452+0.0008717037060614507j), (-0.009614187118781833+0.000696745912413337j), (-0.01039188907107941+0.001320762639637991j), (-0.011130833496354332+0.0017937136707531019j), (-0.01218488161927166+0.0020663851664433426j), (-0.013449144497426733+0.002528668986439603j), (-0.014931186608430291+0.0028105633715724367j), (-0.015773027148885357+0.0026686286122286325j), (-0.01880704696276467+0.0030433824534241575j), (-0.02190071024190813+0.003334511217948567j), (-0.024781848215226197+0.0049687225811330836j), (-0.028251644223051632+0.007030761081382777j), (-0.031112691438038867+0.01027039833618901j), (-0.03536846717855656+0.012708839887580847j), (-0.03919777472777372+0.016790322285714733j), (-0.04362940288138214+0.021897650416024546j), (-0.04763082952704437+0.029006208869780073j), (-0.05056688953021778+0.0366794820417554j), (-0.051309002636166993+0.04601105072036714j), (-0.05379595923667125+0.056225274872697496j), (-0.051081631441472944+0.06793993915838437j), (-0.046604387475187775+0.08003611024470858j), (-0.03688586908443868+0.08943104151963216j), (-0.029170430705639808+0.09369049435671925j), (-0.025078454627710488+0.09864417154436816j), (-0.015636577054236708+0.10723696229162136j), (-0.010372108051619842+0.10697786123178013j), (-0.005666212019364359+0.11107111629957181j), (-0.003681908847824321+0.11835939542285648j), (0.0021815576086929903+0.12403366280838077j), (0.004288907613477094+0.12879127926807413j), (0.011655356086272262+0.1433411549194658j), (0.014457137341259795+0.15754990734668617j), (0.03369443722180802+0.1802242066287651j), (0.06530269126385292+0.19239069288449676j), (0.0943342160929837+0.1968006802238332j), (0.12848531203565092+0.19931759431783053j), (0.16993447384357677+0.18293618201909218j), (0.20226699962332634+0.15710130075221995j), (0.21409120289057407+0.11800617563586964j), (0.22107080704002502+0.08716648766381459j), (0.21952945164096602+0.05927724955852504j), (0.2120391862696983+0.033724484841952354j), (0.20144223917048173+0.014511016320757924j), (0.18519710500908992+0.0045412731395747755j), (0.17835323585450258+0.00030046067916301587j), (0.17284732513190543-0.003289539029065805j), (0.16751666000627416-0.007754615624967031j), (0.16714329246176057-0.009711615710601688j), (0.16795227777343932-0.011908999947386487j), (0.1699727116947468-0.01620800950033761j), (0.17393506135418899-0.02073441775329744j), (0.17793670369143885-0.03152834696047429j), (0.1804143873687475-0.04344933171303302j), (0.18038257200549324-0.05344064035856887j), (0.18215515052974154-0.058860138960908165j), (0.18399098005690673-0.07578233916888842j), (0.18157711605367272-0.09124940387329811j), (0.1780065439686103-0.10623669774415866j), (0.17280104903656182-0.12354943299082968j), (0.16432609079570595-0.13347587716886467j), (0.15980575388057533-0.15686009582447807j), (0.14906631039267798-0.1738362244364557j), (0.12799936682448582-0.2017612992736399j), (0.10082034244707763-0.21297129249061242j), (0.07133886809259808-0.23254138499403113j), (0.02723668450331302-0.247472936376958j), (-0.0173772927057526-0.2247601085256726j), (-0.0503253098243235-0.19261516080604432j), (-0.06527971496189079-0.1772587380282393j), (-0.08166146643319423-0.1418901600528498j), (-0.0830245454363356-0.12074722397413215j), (-0.06558796788889462-0.10196939321266518j), (-0.06426344420797613-0.09790791493525457j), (-0.05481571292339482-0.08218855750758271j), (-0.04771012026038483-0.08799057414235223j), (-0.043524180668990615-0.08701777150633161j), (-0.05152500188347851-0.10107504742486655j), (-0.058323844399204405-0.10668011476075405j), (-0.07262405322929918-0.10579953192538541j), (-0.08546967506250684-0.11267769980797894j), (-0.11002726924440258-0.11284415909215388j), (-0.15195645829259893-0.1261258529392712j), (-0.19221934488547557-0.09710606558251071j), (-0.2530457267632092-0.06095238829159088j), (-0.33125926563983943+0.0357473367129661j), (-0.36409413204057595+0.291251680247731j), (0.07152502923662092+0.39526012002455474j), (0.13877154847176223+0.07640873559323685j), (-0.013629630021456526+0.057217604533440866j), (-0.016983568536126634+0.12874523688885284j), (0.06005833817098943+0.10157318741546631j), (0.07991462811266484+0.0787558999131979j), (0.08549752839965935+0.04321977233617893j), (0.08505608580827069-0.0217492564720711j), (0.012369246855414745-0.02072948930244569j), (0.03480687218414737+0.014890285773117731j), (0.03885348753312723+5.267733966761992e-05j), (0.053900689746646545-0.028253593286202413j), (-0.0008468452882705293-0.02875172680881279j), (0.00447116334329574-0.006387194650801876j), (0.016967573251664946-0.00418168741206336j), (0.026063059719631153-0.027967118903035736j), (-0.002755118783783279-0.04726719040925738j), (-0.027857058872544443-0.002134786021886189j), (-0.010037807456857758+0.00379883192835497j), (-0.0030615571609302894-0.0008808903978466484j), (-0.016350766577888174+0.004242664632131824j), (0.00451497175362139+0.0013193127270703523j), (-0.003934235661373819+0.001616253975484484j), (-0.0008359629772504203+0.0035183175616491347j), (0.00043678806566431174+0.001811361226718626j)] + diff --git a/releves_experimentaux/data_8Ohm.md b/releves_experimentaux/data_8Ohm.md new file mode 100644 index 0000000..ef69ffe --- /dev/null +++ b/releves_experimentaux/data_8Ohm.md @@ -0,0 +1,7 @@ +Fct de transfert; sans écho, sans ampli active. Sortie audio -> 10 Ohm -> HP -> Micro + + +X = [61.900000000000006, 64.9, 68.1, 71.5, 75.0, 78.7, 82.5, 86.6, 90.9, 95.3, 100.0, 105.0, 110.00000000000001, 114.99999999999999, 121.0, 127.0, 133.0, 140.0, 147.0, 154.0, 162.0, 169.0, 178.0, 187.0, 196.0, 204.99999999999997, 215.0, 225.99999999999997, 237.0, 249.00000000000003, 261.0, 274.0, 287.0, 301.0, 316.0, 332.0, 348.0, 365.0, 383.0, 401.99999999999994, 422.0, 442.0, 463.99999999999994, 487.0, 511.00000000000006, 536.0, 562.0, 590.0, 619.0, 649.0, 681.0, 715.0, 750.0, 787.0, 825.0, 866.0, 909.0, 952.9999999999999, 1000.0, 1050.0, 1100.0, 1150.0, 1210.0, 1270.0, 1330.0, 1400.0, 1470.0, 1540.0, 1620.0, 1690.0, 1780.0, 1870.0, 1960.0, 2050.0, 2150.0, 2260.0, 2370.0, 2490.0, 2610.0, 2740.0, 2870.0, 3010.0, 3160.0, 3320.0, 3480.0, 3650.0, 3830.0, 4019.9999999999995, 4220.0, 4420.0, 4640.0, 4870.0, 5110.0, 5360.0, 5620.0, 5900.0, 6190.0, 6490.0, 6810.0, 7150.0, 7500.0, 7870.0, 8250.0, 8660.0, 9090.0, 9530.0, 10000.0, 10500.0, 11000.0, 11500.0, 12100.0, 12700.0, 13300.0, 14000.0, 14700.0, 15400.0, 16200.000000000002, 16900.0, 17800.0, 18700.0, 19600.0] + +H = [(-0.001515313992622782-0.00028749345096398555j), (-0.001364103338555784-0.00021094532964407357j), (-0.0022814439902865517-0.0007854846561657871j), (-0.002380144604739787-3.0315136256126943e-05j), (-0.002563257570368207-0.00013936355708156346j), (-0.003074680734677604+1.6815141357369384e-05j), (-0.0034054999926641755-0.000530554243528603j), (-0.0032309768892565182-0.0001333291180151299j), (-0.003425433144666232+8.480885685641418e-05j), (-0.004742153392026202+0.00028526504659023307j), (-0.005005351784365765-0.00015818899842708967j), (-0.005584121989639443+0.00010161434283164002j), (-0.006290586425964728+0.0002996592696360388j), (-0.006530387306447918+0.0003226406889173222j), (-0.007268462730940787+0.0008018092500006619j), (-0.007474362889540876+0.0005410715682392376j), (-0.009391034528476436+0.0007269968711879424j), (-0.009940880564567442+0.0006946750108567431j), (-0.011175752817885005+0.0003959040606347381j), (-0.013529168164884434+0.0005629077150424926j), (-0.015406606610718975+0.0008702932902428113j), (-0.017235982657271807+0.002500757757962923j), (-0.02037492649272507+0.0033578485280630704j), (-0.02396979948968109+0.005173732505359233j), (-0.027388404849697394+0.007439124048338085j), (-0.030794793039108575+0.011047162367117908j), (-0.0353719334913137+0.015782612546125955j), (-0.039497649255145054+0.0228938168146562j), (-0.040853356968997875+0.033022240966841004j), (-0.04044790362651503+0.04474485286574963j), (-0.035595339869245776+0.056119934574573725j), (-0.024224069841504617+0.06495554846330072j), (-0.014889783280888908+0.06828357578609111j), (-0.006051812464522673+0.06730806661885422j), (0.0016585844398694031+0.06855033738055677j), (0.004255135728226178+0.06412477495149455j), (0.0056361327345720285+0.06412199922854434j), (0.007547015793621568+0.06632930719619719j), (0.010448349702883353+0.06744670137312811j), (0.012032480319727472+0.0709285171289383j), (0.014816002799744715+0.07489414528378373j), (0.016970380171382134+0.08260638820360568j), (0.026524911927221808+0.09308219724000284j), (0.04197835583388583+0.09985608952199543j), (0.06021552526299225+0.09754985161776714j), (0.07607423715319524+0.0977069584298985j), (0.0931095567786713+0.08856848614100932j), (0.10903613271240573+0.07328412650344648j), (0.11223511365085571+0.05469277600417999j), (0.1137097081677629+0.03997137185277147j), (0.1116391420696327+0.026721107187974314j), (0.10786027214819709+0.01262029327299773j), (0.0986791405348264+0.006784143131145287j), (0.09425484012595536+0.0033853293127317705j), (0.09028978895682029-0.00019038966815260893j), (0.08780223278184887-0.0016470063518605133j), (0.08570312339827267-0.002984790178374343j), (0.08461685820387171-0.0036833235515972705j), (0.08565081601687023-0.0038194838020005825j), (0.08651254897203632-0.006128340283861206j), (0.08833846067688828-0.008062507065809467j), (0.09095774763975943-0.010968688815015839j), (0.09238476287504979-0.01729495264315235j), (0.09317944378691258-0.022604835792000448j), (0.09283493079907519-0.029322980915639448j), (0.09466620184386938-0.029578829328622734j), (0.09697290340086635-0.038825979717728505j), (0.09630288776991891-0.04659667641077091j), (0.09468050439786933-0.05514724293515966j), (0.09193045404557024-0.061805611968108416j), (0.0895246615516347-0.07216874259031604j), (0.08753488313344232-0.08203054537835652j), (0.0814307152833825-0.09609701287273362j), (0.06582303038055937-0.10986238630737483j), (0.048681404552504914-0.12133763106031666j), (0.027990659216503518-0.12060218098703562j), (0.004823845412239694-0.12370737873046163j), (-0.004228391572542949-0.10440771297266316j), (-0.02163727105328356-0.09803835037267705j), (-0.030513833357160847-0.07870457608502338j), (-0.03153292034469607-0.06670360358306156j), (-0.0246427672747726-0.0596905860475204j), (-0.023425769690000774-0.056559370693203014j), (-0.0214321009330849-0.050061046653946235j), (-0.01869714825306017-0.05196140167144543j), (-0.015531862175382778-0.05328576544935796j), (-0.012987222460953051-0.0595152913377811j), (-0.019037365890433214-0.06602976992861036j), (-0.02640574018910192-0.06652255831894364j), (-0.03166228237926156-0.07115661779074325j), (-0.049657721308505764-0.07963232472909407j), (-0.06712088185871067-0.08794919642274096j), (-0.1013512619317172-0.08277778585289214j), (-0.13728656919497598-0.07026117557845366j), (-0.19237028576055515-0.02729485595964707j), (-0.24416512019556574+0.12532019899392285j), (-0.014613250084304944+0.2393644299773319j), (0.07367957654571607+0.06092913784656749j), (-0.022024336069602062+0.03292577140845581j), (-0.03205979304004028+0.07780425286963509j), (0.021303467096837777+0.07336218452863713j), (0.038129863747984466+0.061696527132838457j), (0.04735119217509645+0.04047260500860582j), (0.05687545646944222+0.0010873727958654361j), (0.011429380806807504-0.011179094750003307j), (0.01910848928580914+0.015228576924045846j), (0.025159222838989376+0.00734325562581579j), (0.03982668859710029-0.007802028848189725j), (0.004629894993664228-0.01817893575713609j), (0.004159139041554302-0.0037516442936611264j), (0.011973198970360166+0.00037463742492843015j), (0.02286361472361937-0.014457641505664807j), (0.007063309011057366-0.03195181849209164j), (-0.018024170059458992-0.006794809131687788j), (-0.008165868668059016+0.0003007361611398655j), (-0.0015689017862985804-0.00040699670757220793j), (-0.011801960795516502+0.0003407120265465242j), (0.0034238882132531065+0.0023351828997258558j), (-0.003560447721145819-8.101102101973244e-05j), (-0.0012376187238081085+0.0015765046294489305j), (-0.00010860688941523567+0.0012259368714117337j)] + diff --git a/releves_experimentaux/mic_impedance.md b/releves_experimentaux/mic_impedance.md new file mode 100644 index 0000000..76c43f8 --- /dev/null +++ b/releves_experimentaux/mic_impedance.md @@ -0,0 +1,8 @@ +Microphone as source follower. 175uA DC @ ~3V Vds + +X = [62.0, 68.0, 75.0, 82.0, 91.0, 100.0, 110.00000000000001, 120.0, 130.0, 150.0, 160.0, 180.0, 200.0, 220.00000000000003, 240.0, 270.0, 300.0, 330.0, 360.0, 390.0, 430.0, 470.0, 509.99999999999994, 560.0, 620.0, 680.0, 750.0, 819.9999999999999, 910.0, 1000.0, 1100.0, 1200.0, 1300.0, 1500.0, 1600.0, 1800.0, 2000.0, 2200.0, 2400.0, 2700.0, 3000.0, 3300.0, 3600.0, 3900.0, 4300.0, 4700.0, 5100.0, 5600.0, 6200.0, 6800.0, 7500.0, 8200.0, 9100.0, 10000.0, 11000.0, 12000.0, 13000.0, 15000.0, 16000.0, 18000.0, 20000.0] + +H = [(0.47012032175840673+0.01812983402014712j), (0.470773859825163+0.01694020487348213j), (0.47014391070243977+0.015085538991270814j), (0.47015580025611164+0.01290140838256883j), (0.4707965853705939+0.012540456593345836j), (0.4702655782670737+0.01146515427066669j), (0.47001958941149374+0.009066724097094081j), (0.4698897845061736+0.008590954654956465j), (0.4703328317106061+0.007680708662404258j), (0.47059597197084874+0.006947035949722949j), (0.4704696033876575+0.00577097334067109j), (0.4706101838316291+0.004496916581939091j), (0.4700645514757954+0.004640777774023917j), (0.46970384793911085+0.0038522275542666844j), (0.47072172644838994+0.004356868460710158j), (0.46985620214068086+0.0027604993703299464j), (0.4706992493463072+0.002204339769185796j), (0.47106305332005566+0.0021205228985848017j), (0.47028285448669327+0.0018612810692497153j), (0.4691514968724328+0.002292957901098495j), (0.4701873122263507+0.0002420230304226658j), (0.4689285261898509+0.0007289920633161568j), (0.46956552462586804-0.0007236174387345418j), (0.4678562305849072-0.0006907393785490914j), (0.46836755615019-0.0006038427857997494j), (0.4689235574748159-0.0016181768655454802j), (0.46876318278299123-0.0017764947735754034j), (0.4683097999229312-0.0027640827428271906j), (0.46786090676077974-0.002610856644027095j), (0.46753731928396514-0.002241714250446953j), (0.46801984732360963-0.002119721318204412j), (0.4663227653685854-0.0016727148025411536j), (0.4663031260029301-0.0022085460059039328j), (0.4658401896506971-0.0020177518020752486j), (0.46612388968980756-0.002207265245165768j), (0.4645078371101538-0.0028048732307074937j), (0.46394264877360886-0.0021639899863904162j), (0.4642719966632143-0.0015964764527535004j), (0.4632949784333158-0.0018359364430161399j), (0.46339335082824507-0.0007557123371271958j), (0.46374916001466004-0.0006997385251981024j), (0.46251209195262455-0.00011522690154944387j), (0.46177373985629666+0.0005354488426995059j), (0.4630923556768662+0.0009618057371807924j), (0.46250026655427934+0.002019603274076546j), (0.46115066695013796+0.002618340722087239j), (0.4599367294994153+0.001487858985361092j), (0.45947368133692446+0.0026319865902357893j), (0.4607616438306012+0.004473565837816463j), (0.46123373027180997+0.0039563877327196545j), (0.4612432999999601+0.004773317207737592j), (0.46113397679743406+0.006135235798210173j), (0.46122910037870635+0.005727347168252464j), (0.46150279974005726+0.007471744392586996j), (0.46260297120248955+0.007760981385780426j), (0.461474728572703+0.010231892504492484j), (0.46216777324979+0.009433273729074564j), (0.46091102876674295+0.010621600555034331j), (0.46093670915980167+0.012440290976269985j), (0.46216882884840704+0.014888096834763371j), (0.46407411135079274+0.015274025203592433j)] + + +We get a ~12kOhm output impedance, and negligible output capacitance. diff --git a/xfer_tracer/script.py b/xfer_tracer/script.py index 2f8a8e5..3a883ae 100755 --- a/xfer_tracer/script.py +++ b/xfer_tracer/script.py @@ -25,130 +25,169 @@ fade_time = 0 def audio_callback(in_data, frame_count, time_info, status): - global fade_time - global change_f - global new_f - global current_phase - global normalized_f - global trans_done + global fade_time + global change_f + global new_f + global current_phase + global normalized_f + global trans_done - if change_f == True: - change_f = False - trans_done = False - fade_time = 0 + if change_f == True: + change_f = False + trans_done = False + fade_time = 0 - if(fade_time != 2*trans_len): - if(fade_time < trans_len): - last_fade = fade_time + frame_count - envelope = outro[fade_time:last_fade] - fade_time = min(last_fade, trans_len) - elif(fade_time >= trans_len and fade_time < 2*trans_len): - normalized_f = new_f - if(new_f == 0): - current_phase = 0. # Avoid weird sub-audio behavior - last_fade = fade_time + frame_count - envelope = intro[fade_time - trans_len:last_fade - trans_len] - fade_time = min(last_fade, 2*trans_len) + if(fade_time != 2*trans_len): + if(fade_time < trans_len): + last_fade = fade_time + frame_count + envelope = outro[fade_time:last_fade] + fade_time = min(last_fade, trans_len) + elif(fade_time >= trans_len and fade_time < 2*trans_len): + normalized_f = new_f + if(new_f == 0): + current_phase = 0. # Avoid weird sub-audio behavior + last_fade = fade_time + frame_count + envelope = intro[fade_time - trans_len:last_fade - trans_len] + fade_time = min(last_fade, 2*trans_len) - if(fade_time == 2*trans_len): - trans_done = True + if(fade_time == 2*trans_len): + trans_done = True - sine = np.sin(2 * np.pi * (current_phase + np.arange(frame_count)*normalized_f)) - delta = frame_count*normalized_f - delta -= np.floor(delta) + sine = np.sin(2 * np.pi * (current_phase + np.arange(frame_count)*normalized_f)) + delta = frame_count*normalized_f + delta -= np.floor(delta) - if(delta + current_phase > 1): - current_phase += delta - 1 - else: - current_phase += delta + if(delta + current_phase > 1): + current_phase += delta - 1 + else: + current_phase += delta - if(fade_time != 2*trans_len): - sine *= envelope + if(fade_time != 2*trans_len): + sine *= envelope - return (sine.astype(np.float32).tobytes(), pa.paContinue) + return (sine.astype(np.float32).tobytes(), pa.paContinue) paudio = pa.PyAudio() audio_strm = paudio.open(format=pa.paFloat32, - channels=1, - rate=44100, - output=True, - input=False, - stream_callback=audio_callback, - start=True) + channels=1, + rate=44100, + output=True, + input=False, + stream_callback=audio_callback, + start=True) print(paudio.get_default_output_device_info()) print(audio_strm.is_active()) + + def acquire_samples(sc_frequency, oscillo): - global new_f - global change_f - global trans_done - new_f = sc_frequency - change_f = True - while (change_f == True) or (trans_done == False): - time.sleep(0.05) - time.sleep(0.2) + global new_f + global change_f + global trans_done - oscillo.write("acquire:state run") - oscillo.write("data:source CH1") - input_ch = oscillo.query_binary_values("curve?",datatype="b",container=np.array).astype(np.float64) - oscillo.write("data:source CH2") - output_ch = oscillo.query_binary_values("curve?",datatype="b",container=np.array).astype(np.float64) + new_f = sc_frequency + change_f = True + while (change_f == True) or (trans_done == False): + time.sleep(0.01) + time.sleep(0.1) - return input_ch, output_ch + oscillo.write("acquire:state run") + oscillo.write("data:source CH1") + input_ch = oscillo.query_binary_values("curve?",datatype="b",container=np.array).astype(np.float64) + oscillo.write("data:source CH2") + output_ch = oscillo.query_binary_values("curve?",datatype="b",container=np.array).astype(np.float64) + + return input_ch, output_ch def manage_measures(f_list, oscillo): # These are NOT normalized frequencies - hscales = [0.25, 100e-3, 50e-3, 25e-3, 10e-3, 5e-3, 2.5e-3, 1e-3, 500e-6, 250e-6, 100e-6, 50e-6, 25e-6, 10e-6] - hscales_str = ["2.5e-1", "1.0e-1", "5.0e-2", "2.5e-2", "1.0e-2", "5.0e-3", "2.5e-3", "1.0e-3", "5.0e-4", "2.5e-4", "1.0e-4", "5.0e-5", "2.5e-5", "1.0e-5"] + hscales = [0.25, 100e-3, 50e-3, 25e-3, 10e-3, 5e-3, 2.5e-3, 1e-3, 500e-6, 250e-6, 100e-6, 50e-6, 25e-6, 10e-6] + hscales_str = ["2.5e-1", "1.0e-1", "5.0e-2", "2.5e-2", "1.0e-2", "5.0e-3", "2.5e-3", "1.0e-3", "5.0e-4", "2.5e-4", "1.0e-4", "5.0e-5", "2.5e-5", "1.0e-5"] - hscale_index = 0 - current_hscale = hscales[hscale_index] + hscale_index = 0 + current_hscale = hscales[hscale_index] - cal_A = [] - cal_B = [] - cal_done = False - H = [] + vscales = [0.25, 100e-3, 50e-3, 25e-3] + vscales_str = ["2.5e-1", "1.0e-1", "5.0e-2", "2.5e-2"] + vscale_index = 0 + current_vscale = vscales[vscale_index] - W = sc.signal.windows.flattop(2500) + cal_A = [] + cal_B = [] + cal_done = False - for f in f_list: - sc_frequency = np.round(2**20/44100 * f)/2**20 - num_periods = f * 10 * current_hscale - while(num_periods >= 5 * 2.5): - hscale_index += 1 - current_hscale = hscales[hscale_index] - num_periods = f * 10 * current_hscale - print("horizontal:main:scale " + hscales_str[hscale_index]) - oscillo.write("horizontal:main:scale " + hscales_str[hscale_index]) - cal_done = False + H = [] - print(f, " : ", current_hscale,"s/div, ", num_periods, " periods") - A, B = acquire_samples(sc_frequency, oscillo) - if not cal_done: - cal_A, cal_B = acquire_samples(0., oscillo) - cal_done = True - print(A) - print(B) - A, B = (A - cal_A)*W, (B - cal_B)*W - f_acq = 250./current_hscale - rel_f = f / f_acq + W = sc.signal.windows.flattop(2500) - # Obtain the Fourier transforms of A, B @ rel_f, with flattop windowing - V = np.exp(-2.0j * np.pi * np.arange(2500) * rel_f) - h = np.sum(B*V)/np.sum(A*V) - print("H(", f, ") = ", h) - H.append(h) - return H + for f in f_list: + sc_frequency = np.round(2**20/44100 * f)/2**20 + num_periods = f * 10 * current_hscale + update_hscale = False + while(num_periods >= 5 * 2.5): + hscale_index += 1 + current_hscale = hscales[hscale_index] + num_periods = f * 10 * current_hscale + update_hscale = True + + if update_hscale: + print("horizontal:main:scale " + hscales_str[hscale_index]) + oscillo.write("horizontal:main:scale " + hscales_str[hscale_index]) + cal_done = False + + print(f, " : ", current_hscale,"s/div, ", num_periods, " periods") + A, B = acquire_samples(sc_frequency, oscillo) + + is_sat, is_under = False, True + for x in B: + is_sat |= (abs(x) >= 127) + is_under &= ~(abs(x) >= 64) + + while((is_sat and vscale_index != 0) or (is_under and vscale_index != len(vscales)-1)): + if(is_sat): + print("We have saturation") + vscale_index-=1 + elif(is_under): + print("We are wasting bits") + vscale_index+=1 + current_vscale = vscales[vscale_index] + osci.write("ch2:scale " + vscales_str[vscale_index]) + cal_done = False + A, B = acquire_samples(sc_frequency, oscillo) + + is_sat, is_under = False, True + for x in B: + is_sat |= (abs(x) >= 120) + is_under &= ~(abs(x) >= 64) + + + if not cal_done: + cal_A, cal_B = acquire_samples(0., oscillo) + cal_done = True + print(A) + print(B) + A, B = (A - cal_A)*W, (B - cal_B)*W + f_acq = 250./current_hscale + rel_f = f / f_acq + + B *= current_vscale/vscales[0] + + # Obtain the Fourier transforms of A, B @ rel_f, with flattop windowing + V = np.exp(-2.0j * np.pi * np.arange(2500) * rel_f) + h = np.sum(B*V)/np.sum(A*V) + print("H(", f, ") = ", h) + H.append(h) + return H def find_oscillo(): - rm = pyvisa.ResourceManager() - R = rm.list_resources() - print(R) -# if R.empty(): -# print("No device found") -# exit(1) - return rm.open_resource(R[0]) + rm = pyvisa.ResourceManager() + R = rm.list_resources() + print(R) +# if R.empty(): +# print("No device found") +# exit(1) + return rm.open_resource(R[0]) osci = find_oscillo() @@ -176,17 +215,53 @@ osci.write("trigger:main:type EDGE") osci.write("acquire:mode sample") osci.write("acquire:stopafter sequence") osci.write("data:encdg RIBinary") -decade = [1.0, 1.2, 1.5, 1.8, 2.2, 2.7, 3.3, 3.9, 4.7, 5.6, 6.8, 8.2] -X = [68., 82] + list(np.array(decade)*([100.]*len(decade))) + list(np.array(decade) * ([1000.]*len(decade))) + [1e4, 1.2e4, 1.5e4, 1.8e4] + +def build_spoints(decade): + res = [] + power_of_ten = 10 + while(power_of_ten <= 100000): + for x in decade: + f = x * power_of_ten + if(60. <= f and f <= 20000.): + res.append(f) + power_of_ten *= 10 + return res + + +e12 = [1.0, 1.2, 1.5, 1.8, 2.2, 2.7, 3.3, 3.9, 4.7, 5.6, 6.8, 8.2] +e24 = [1.0, 1.1, 1.2, 1.3, 1.5, 1.6, 1.8, 2.0, 2.2, 2.4, 2.7, 3.0, 3.3, 3.6, 3.9, 4.3, 4.7, 5.1, 5.6, 6.2, 6.8, 7.5, 8.2, 9.1] +e48 = [1.00, 1.05, 1.10, 1.15, 1.21, 1.27, 1.33, 1.40, 1.47, 1.54, 1.62, 1.69, 1.78, 1.87, 1.96, 2.05, 2.15, 2.26, 2.37, 2.49, 2.61, 2.74, 2.87, 3.01, 3.16, 3.32, 3.48, 3.65, 3.83, 4.02, 4.22, 4.42, 4.64, 4.87, 5.11, 5.36, 5.62, 5.90, 6.19, 6.49, 6.81, 7.15, 7.50, 7.87, 8.25, 8.66, 9.09, 9.53] + +X = build_spoints(e24) + +print(X) + H = manage_measures(X, osci) Y = 20 * np.log10(np.abs(H)) +phase = np.angle(H, deg=True) +for i in range(1, len(phase)): + while(abs(phase[i] - phase[i - 1]) >= 180): + if(phase[i] >= phase[i-1]): + phase[i] -= 360 + else: + phase[i] += 360 + +print(X) print(H) +print("Corrected phase/magnitude :") +print(phase) +print(Y) + fig, axes = plt.subplots(nrows = 2, ncols=1, sharex = True) axes[0].semilogx(X,Y) axes[0].grid() -axes[1].semilogx(X, np.angle(H, deg=True)) +axes[1].semilogx(X, phase) axes[1].grid() +plt.show(block = False) + +plt.figure(2) +plt.plot(X, phase) plt.show()