diff --git a/QAM/c.py b/QAM/c.py new file mode 100644 index 0000000..edd633e --- /dev/null +++ b/QAM/c.py @@ -0,0 +1,68 @@ +import numpy as np +import matplotlib.pyplot as plt +from matplotlib.animation import FuncAnimation + +# --- Demande à l'utilisateur --- +user_input = input("GIF ? (o/n) : ").strip().lower() +GENERATE_GIF = user_input == 'o' + +# --- Fichiers --- +ref_file = "constellation_ref.dat" # constellation de référence +rx_file = "constellation.dat" # symboles corrigés par la PLL + +# Charger les données +ref_constel = np.loadtxt(ref_file) # colonnes I Q +rx_data = np.loadtxt(rx_file) # colonnes I Q + +# Paramètres +window_size = 50 # nombre de symboles à afficher dans la fenêtre +speed_factor = 5 # pour accélérer l'animation +N_frames = len(rx_data) + +# Figure +fig, ax = plt.subplots(figsize=(6,6)) +ax.set_title("Rolling Constellation avec PLL") +ax.set_xlabel("I") +ax.set_ylabel("Q") +ax.grid(True) + +# Constellation de référence +ax.scatter(ref_constel[:,0], ref_constel[:,1], c='red', marker='x', label='Référence') + +# Points PLL +scat = ax.scatter([], [], c='blue', s=20, label='Points récents') +last_point = ax.scatter([], [], c='green', s=50, label='Dernier symbole') + +ax.set_xlim(np.min(ref_constel[:,0])-0.5, np.max(ref_constel[:,0])+0.5) +ax.set_ylim(np.min(ref_constel[:,1])-0.5, np.max(ref_constel[:,1])+0.5) +ax.legend() + +# Initialisation +def init(): + scat.set_offsets(np.empty((0,2))) + last_point.set_offsets(np.empty((0,2))) + return scat, last_point + +# Mise à jour +def update(frame): + idx = min(frame*speed_factor, N_frames) + start_idx = max(0, idx - window_size) + data_window = rx_data[start_idx:idx] + + scat.set_offsets(data_window) + if len(data_window) > 0: + last_point.set_offsets(data_window[-1:]) + return scat, last_point + +# Création de l'animation +ani = FuncAnimation(fig, update, frames=int(N_frames/speed_factor)+1, + init_func=init, blit=True, interval=20) + +# --- Sauvegarde GIF conditionnelle --- +if GENERATE_GIF: + ani.save("pll_constellation.gif", writer='pillow', fps=30) + print("GIF généré : pll_constellation.gif") + +# Affichage à l'écran +plt.show() + diff --git a/QAM/constellation.dat b/QAM/constellation.dat index 76f0605..bb6ac2e 100644 --- a/QAM/constellation.dat +++ b/QAM/constellation.dat @@ -1,416 +1,416 @@ --0.48961254 -0.44544459 --0.46513110 1.40428312 --0.29307347 1.38893240 - 1.31089689 -0.55680171 --0.38632169 1.36097312 --0.33123545 1.38726262 --1.26549075 1.37974405 --1.49852105 -1.19958987 --0.31017669 1.30222164 - 1.50729893 1.24105325 --0.43017215 0.48948646 --0.54096932 -0.28558853 --0.26310886 1.41585924 --0.43457847 0.44417363 --0.19980151 1.35561085 --0.44785998 -0.33107245 --1.14331753 1.50994919 - 0.14820610 -1.42291697 --1.10811359 1.44551804 --1.57079461 -1.11961078 --0.38427593 0.43042485 --0.81528420 -1.22676725 --0.44084375 0.55211323 --1.12415715 1.46959617 --0.22904642 1.34965939 --0.50438838 -0.39136139 --0.20762621 1.38489848 - 0.33614255 -0.59435058 --0.42253847 0.49986333 --1.60347736 -0.95239233 --0.03566900 1.37591841 --0.51774331 -0.40091728 --0.44026540 0.59544844 - 1.61978249 0.94637465 --0.92149464 1.71093438 --1.56102417 -0.94051892 --0.01285030 1.38478328 --1.19627264 0.83013282 --0.06307302 1.47052202 --0.58523530 -0.26077664 --0.98115028 1.59689715 --1.66141576 -0.88628493 --0.00852613 1.43712353 --0.94510653 1.68296522 - 0.02796472 1.45841907 - 0.04359314 -1.43960140 - 0.02915805 1.41430273 - 0.59530686 0.23857004 - 0.01512380 1.39441413 - 0.87304003 1.07342230 - 0.03850944 1.47994568 --0.74819139 -1.08237048 --0.80309466 1.82889157 --1.69114176 -0.75838051 --0.22871349 0.55763008 --0.28017727 0.51990165 - 0.05134513 1.43745319 - 0.70298158 -1.76376530 - 0.06299865 1.44501145 - 1.04763519 -0.94454689 --0.14211486 0.57473317 --1.05659494 0.90567818 - 0.21562582 1.42864813 - 1.43794919 -0.18192650 --0.17191186 0.72065825 - 1.06943225 -1.00399960 --0.62563602 1.77948004 --1.75877350 -0.58976746 - 0.15742790 1.38156984 --1.36716105 0.18569423 --0.10959253 0.56159108 --1.38029979 0.27498475 --0.16662433 0.63815496 --0.69299949 -0.22078711 - 0.24097931 1.43158061 --0.56183026 -0.17886504 --0.20186054 0.69913865 --0.62490100 -0.14390235 --0.20291470 0.59305976 - 0.51209376 -1.90033204 --0.45613235 1.87052028 --0.33525878 -1.36406488 --0.52204801 1.87033049 --1.80395817 -0.49649028 --0.56417371 -0.09817205 - 0.33527724 1.34641187 - 0.25267449 1.38825080 - 0.89090250 -1.07383883 - 0.29405742 1.35820577 - 0.34849465 1.37038226 --0.31128450 1.84170483 --1.79739912 -0.39840073 - 0.33475505 1.42320930 - 1.73584529 0.41520891 --0.11884979 0.65144257 --0.58057834 -0.09703036 - 0.41486733 1.25197673 --0.08610506 0.61807043 - 0.48157488 1.34603546 --0.51959424 -0.10279402 --0.22181939 1.85567303 --0.43696196 -1.32625724 --0.22859344 1.91431107 --1.86197344 -0.21673157 --0.07335711 0.70160975 --1.19148834 -0.78920537 --0.13331574 0.62574148 --0.12591132 1.90861215 - 0.55253930 1.36648515 --0.61017418 -0.07900305 - 0.56494240 1.25763125 - 0.03588819 -0.60607038 --0.16605597 0.61282039 --1.83991758 -0.05832141 - 0.44707974 1.32300615 --0.58169728 -0.00595536 - 0.04035602 0.60491026 - 1.82488117 0.13148933 --0.09894890 1.85431403 --1.94432949 -0.01478929 - 0.65139963 1.21039977 --0.73792715 1.19409828 - 0.61274010 1.20774353 --0.55048746 0.06897033 --0.00216719 1.94731226 --1.90572088 -0.00961994 - 0.63257907 1.28332411 --0.03658697 1.88600425 - 0.72958333 1.30050643 --0.69441386 -1.20574763 - 0.59432528 1.18046372 - 0.57212587 0.03035341 - 0.72664451 1.15150859 - 1.33739250 0.53193906 - 0.65798374 1.22337579 --1.27476518 -0.49007002 - 0.05715084 1.91518006 --1.92376764 0.20568610 - 0.03337894 0.52213641 - 0.09766169 0.76246638 - 0.72672206 1.20756452 --0.24726369 -1.82461637 - 0.84049477 1.19627841 - 0.45402707 -1.32737360 - 0.10396333 0.67426301 --0.46558946 1.36599073 - 0.75612467 1.20061076 - 1.20224816 -0.82351951 - 0.09945559 0.64980823 - 0.40092147 -1.39275741 - 0.28095155 1.95902585 --1.89902051 0.38443177 - 0.81312652 1.06565550 --1.10523485 0.81614169 - 0.17539027 0.60607147 --1.08341524 0.85037101 - 0.11703295 0.56780442 --0.62514703 0.08280138 - 0.93688915 1.13972258 --0.62616770 0.08694894 - 0.07656169 0.60466805 --0.58304627 0.12275201 - 0.14060574 0.65332465 --0.46504121 -1.86336679 - 0.47300263 1.79896550 --0.91510621 -1.05313216 - 0.47114393 1.85433307 --1.77301753 0.46009286 --0.54507731 0.16083904 - 0.88330875 0.97594803 - 0.84930908 0.97970934 - 0.26180808 -1.39899938 - 0.92125691 0.88504166 - 1.04997851 1.00795302 - 0.52998259 1.81511825 --1.71489073 0.52823691 - 0.98904512 1.04053873 - 1.82532442 -0.57436133 - 0.13520730 0.50528308 --0.61914934 0.21982490 - 1.01503204 1.05277598 - 0.21159036 0.57605876 - 0.91660475 0.94049546 --0.61541016 0.29095564 - 0.62609787 1.74017153 --1.08752399 -0.99132647 - 0.76525865 1.72200222 --1.76420782 0.71663228 - 0.22353957 0.49553689 --1.36548697 -0.13614393 - 0.30057974 0.60480370 - 0.72688319 1.69890859 - 1.02144075 0.87191682 --0.53104473 0.20727986 - 1.12890578 0.89874637 --0.34307893 -0.59073421 - 0.21189859 0.47810079 --1.67898034 0.75335891 - 1.11877996 0.92515156 --0.53524443 0.19639758 - 0.40246637 0.55394168 - 1.71671976 -0.84851742 - 0.85241157 1.67085885 --1.65999861 0.88996632 - 1.14343675 0.77619951 - 0.01973882 1.50709965 - 1.23496270 0.84604907 --0.58865986 0.31450775 - 0.90706106 1.63673024 --1.64951586 0.99700496 - 1.23705620 0.79200846 - 0.90811187 1.69230330 - 1.21871516 0.77786107 --1.21417902 -0.82676679 - 1.21843545 0.79754650 - 0.46830390 -0.39568361 - 1.23591198 0.75994717 - 1.30664386 -0.15646879 - 1.20837214 0.66956495 --1.33597135 0.20770639 - 1.07684938 1.58402836 --1.63631303 0.97690329 - 0.42837377 0.46174780 - 0.33755803 0.49496571 - 1.28309836 0.72649413 --1.02856457 -1.51936209 - 1.27789182 0.74562945 --0.22354338 -1.43585457 - 0.40585314 0.61327824 - 0.18263466 1.44556002 - 1.29947395 0.65836781 - 0.67059393 -1.27143638 - 0.30976849 0.50595737 --0.35133388 -1.38306488 - 1.09424882 1.46139023 --1.54993037 1.18919991 - 1.26990578 0.58664272 --0.64627153 1.28576337 - 0.40915803 0.43278891 --0.60210501 1.29808665 - 0.31782993 0.51648304 --0.53174512 0.34997737 - 1.27252369 0.54738946 --0.50931719 0.38587497 - 0.37844860 0.43542442 --0.57010280 0.32272275 - 0.41449300 0.52494515 --1.27703904 -1.43171480 - 1.31351682 1.41133254 --1.33669046 -0.53197769 - 1.20667648 1.34711079 --1.36551992 1.34228552 --0.53606785 0.42397625 - 1.42643488 0.52754677 - 1.25063823 0.46187229 --0.38606726 -1.35182299 - 1.35171097 0.53935539 - 1.35062855 0.42160177 - 1.36233237 1.34029509 --1.31043230 1.34643901 - 1.38244016 0.39373355 - 1.25066238 -1.44855873 - 0.43200556 0.46788979 --0.42134427 0.47098778 - 1.36281212 0.46815575 - 0.44083823 0.36229051 - 1.38305322 0.32810010 --0.45110773 0.46380056 - 1.43603839 1.20120537 --1.32190338 -0.37624311 - 1.49449818 1.20125391 --1.20567682 1.55232534 - 0.58422493 0.41427894 --1.20715782 0.48988342 - 0.34866497 0.39151998 - 1.49886828 1.20337418 - 1.44048084 0.19095526 --0.39314298 0.50199366 - 1.37274013 0.21145366 --0.51646556 -0.34849968 - 0.46286982 0.32106549 --1.11795301 1.55817381 - 1.43635472 0.12670014 --0.45229655 0.46130994 - 0.51300846 0.36804529 - 1.09069505 -1.46299574 - 1.56406300 1.04566660 --0.99216278 1.57795669 - 1.48352041 0.22764812 - 0.67153229 1.22104534 - 1.38989645 0.16687950 --0.26628596 0.55482193 - 1.55176085 1.05592934 --1.00805648 1.59717399 - 1.39738347 0.13954744 - 1.64093666 1.09085350 - 1.33149219 0.07607907 --1.49718163 -0.19222213 - 1.46484721 0.11587303 - 0.30323162 -0.52722447 - 1.44154326 -0.04261822 - 1.15996483 -0.78417104 - 1.46808337 0.06327806 --1.13150524 0.70882611 - 1.73417711 0.92971637 --0.88679017 1.65283145 - 0.65323782 0.27004474 - 0.62156850 0.23908697 - 1.43120236 -0.01977933 --1.69704199 -0.81548161 - 1.50195468 -0.11010930 --0.89704982 -1.11511745 - 0.51339586 0.28540725 - 0.86939319 1.07216313 - 1.41848331 -0.03882423 --0.12057756 -1.45947991 - 0.69599133 0.22852746 --0.91695338 -1.05331735 - 1.78578231 0.74835257 --0.74016968 1.81822295 - 1.40289027 -0.11172712 - 0.07084859 1.43723720 - 0.58119839 0.21524718 - 0.04198519 1.49789145 - 0.57210920 0.22097615 --0.22366343 0.58627521 - 1.42455620 -0.12982301 --0.13362457 0.68263829 - 0.54696227 0.24686813 --0.24118480 0.58089469 - 0.56356655 0.30392984 --1.77517966 -0.69108184 - 1.83172461 0.61442927 --1.42019865 0.19993192 - 1.84241886 0.55973948 --0.54492246 1.84798540 --0.22529925 0.58683552 - 1.42416898 -0.22866871 - 1.44660767 -0.19126394 --1.06656064 -1.02613643 - 1.33374832 -0.27671784 - 1.35663736 -0.31437592 - 1.81277928 0.50904140 --0.42071499 1.94048571 - 1.34430120 -0.30054542 - 0.49215095 -1.80490515 - 0.55692097 0.14763690 --0.09100418 0.57967127 - 1.31097206 -0.32851058 - 0.60454127 0.10088269 - 1.38250158 -0.31253244 --0.03627446 0.57912606 - 1.85238460 0.35877373 --1.35123008 0.43176677 - 1.94955103 0.36646367 --0.35021803 1.81764768 - 0.64238008 0.17451633 --0.82792393 1.19165344 - 0.61155272 0.17222952 - 1.81529035 0.32912303 - 1.34665515 -0.39850446 --0.07146229 0.59176372 - 1.31666474 -0.42121180 --0.66679149 -0.07441151 - 0.65795799 0.16475121 --0.23277688 1.87718572 - 1.28531280 -0.57869031 --0.03715614 0.63080589 - 0.63786408 0.09445329 - 0.20978234 -1.91444420 - 1.89066545 0.19889781 --0.14577078 1.89789268 - 1.30375767 -0.50887943 - 1.20271768 0.69208730 - 1.33826305 -0.56560928 --0.06780183 0.63430771 - 1.93393669 0.05628379 --0.13854581 1.90279530 - 1.28577881 -0.54780021 - 1.89384896 0.06695432 - 1.33780890 -0.55354551 --1.25558620 0.66576944 - 1.33159009 -0.48283724 - 0.04017382 -0.64200065 - 1.23844040 -0.59677820 - 0.68829395 -1.26704094 - 1.29130299 -0.59222046 --0.67535838 1.20820049 - 1.93869890 -0.05791543 - 0.12713845 1.87484374 - 0.77657913 0.02040247 - 0.63160102 0.00660691 - 1.24244624 -0.67370943 --1.84109063 0.08797837 - 1.28182793 -0.69719047 --1.31319236 -0.52642967 - 0.63488504 -0.07598658 - 1.32781009 0.62256655 - 1.22594177 -0.71521729 --0.76582438 -1.24994760 - 0.63268726 -0.15553386 --1.32682719 -0.53291695 - 2.01777801 -0.13027800 - 0.14464114 1.90637156 - 1.12406593 -0.75712395 - 0.78498751 1.21465878 - 0.62142786 -0.04518144 - 0.77876616 1.15380949 - 0.61338544 -0.00774816 - 0.06401641 0.66848491 - 1.15548903 -0.83882198 - 0.12182780 0.68004504 - 0.54187921 -0.06399507 - 0.02153134 0.60988530 - 0.75335082 -0.07216479 --1.85238231 0.19396941 +-0.56017590 -0.42377949 +-0.45289523 1.51059437 +-0.07257432 1.43147803 + 1.27307169 -0.67005556 +-0.37967337 1.36566367 +-0.29333356 1.41363109 +-1.33315292 1.27215770 +-1.51359683 -1.23385338 +-0.37871841 1.17408296 + 1.43152849 1.43869158 +-0.52929376 0.42820425 +-0.57760543 -0.22573077 +-0.51247161 1.38475262 +-0.56765549 0.25187418 +-0.40404161 1.24995427 +-0.29429508 -0.34257885 +-1.49313732 1.15713334 + 0.39917364 -1.40846552 +-1.40466440 0.98792150 +-1.26379686 -1.51538156 +-0.47168254 0.20463768 +-0.71913005 -1.39946099 +-0.66378306 0.47166596 +-1.41483771 1.10231336 +-0.47819178 1.21832484 +-0.41889470 -0.50041356 +-0.38220082 1.32946665 + 0.37365887 -0.65804940 +-0.55966082 0.42508728 +-1.56075333 -0.94008134 + 0.06556035 1.33341442 +-0.48586063 -0.50163934 +-0.59018298 0.67782695 + 1.63890714 0.85050310 +-0.74794030 1.86791146 +-1.53179861 -0.77946016 + 0.26267466 1.32416755 +-1.05874201 1.08375705 + 0.27163575 1.52834151 +-0.65700148 -0.05629840 +-0.71673708 1.70588451 +-1.80369749 -0.46584331 + 0.37697228 1.42065476 +-0.59118366 1.88920409 + 0.47444261 1.44714133 +-0.30520153 -1.44651498 + 0.46287024 1.33856888 + 0.65884728 -0.03828696 + 0.52198669 1.26375960 + 1.22373302 0.55124560 + 0.75684246 1.37869460 +-1.01144015 -0.62726620 + 0.39573635 2.10090584 +-1.74711783 0.39637249 + 0.20810145 0.52232697 + 0.11032738 0.52879796 + 1.19169298 0.86674812 +-1.20811534 -1.46826148 + 1.36576595 0.60485822 +-0.58189221 -1.27964494 + 0.53520067 0.15282713 + 0.62664866 1.20916062 + 1.48665772 -0.14829934 +-0.17634645 -1.48935341 + 0.90249062 0.07726799 +-1.15109529 -1.02455858 + 1.84095788 0.33174592 +-0.18825800 1.78643369 + 1.28502734 -0.43995878 + 0.53709956 1.21817420 + 0.47170821 -0.18777161 + 0.85638798 1.11088085 + 0.67259516 -0.19240908 + 0.21664177 0.83241591 + 1.01154714 -1.11406080 + 0.22823492 0.47798745 + 0.69566311 -0.50666926 + 0.50076049 0.42491448 + 0.46338263 -0.41564102 +-1.13263193 1.72903008 + 0.84254588 -1.77578692 + 0.21039663 1.37774295 + 0.66780608 -1.89088328 + 1.78100201 0.45041323 + 0.49048315 -0.06506837 +-0.72402635 -1.13962679 +-0.69060936 -1.23539842 +-0.26574100 1.34331078 +-0.92346177 -0.99729534 +-1.10763676 -0.87876502 +-1.07208503 -1.48331711 + 1.49218375 -0.94083056 +-1.34711300 -0.73263351 +-1.28453400 1.01606001 +-0.54648352 -0.44319570 + 0.28789875 -0.44141882 +-1.18637059 -0.00658476 +-0.55798335 -0.25370211 +-1.44175973 0.18565129 + 0.19450483 -0.33744811 +-1.76900569 -0.46837781 + 1.34859325 -0.25273164 +-1.94031017 -0.34050293 + 0.24492776 -1.82645969 +-0.80240115 -0.08842996 + 0.81095501 -1.20193596 +-0.62357056 -0.22046612 +-1.93791955 0.03117123 +-1.39726353 0.69037467 + 0.08561544 -0.58690030 +-1.16231739 0.65212151 + 0.57216330 -0.01413764 +-0.61095165 -0.29411086 +-0.20225603 -1.75302469 +-1.30808974 0.46108705 +-0.12668999 -0.49715315 +-0.51116863 0.28148695 + 0.39034466 1.69425745 +-1.69460921 0.61361246 +-1.00158092 -1.74380533 +-0.53882345 1.21031644 +-1.40286516 -0.01805414 +-0.45321707 1.18787123 +-0.42312486 -0.19827109 +-1.39259474 1.45977775 +-1.42960869 -1.27853019 +-0.32844977 1.41772026 +-1.19368114 1.44698550 +-0.07148486 1.59823702 + 0.00583920 -1.36130800 +-0.17387102 1.18247255 + 0.36149591 0.34828894 + 0.16013382 1.28415764 + 1.00532357 1.08115165 +-0.02437700 1.35588353 +-0.93426497 -0.90363392 +-0.84139839 1.75802080 +-1.92880367 -0.48600801 +-0.13462601 0.34591997 +-0.20498363 0.93770054 + 0.21611454 1.38725347 + 0.29412786 -1.74133562 + 0.49402091 1.45065818 + 0.79149310 -1.14064010 +-0.08770833 0.74695431 +-0.84896522 1.21788576 + 0.34699052 1.38588152 + 1.42468197 -0.52352703 +-0.06694096 0.68912431 + 0.71260219 -1.32015171 +-0.29333970 2.07329541 +-1.99618602 -0.07031522 + 0.45826194 1.15059507 +-1.25350933 0.40544865 + 0.07901791 0.63425212 +-1.21555860 0.52866835 +-0.03657218 0.50445859 +-0.60531062 -0.18525472 + 0.51932143 1.47273191 +-0.58929165 -0.24446090 +-0.28542989 0.51302196 +-0.50223486 -0.21168413 +-0.33564206 0.63529564 + 0.94113942 -1.71151356 +-0.93871449 1.54527150 + 0.23902395 -1.34761376 +-1.28448356 1.44736671 +-1.22318413 -1.23729914 +-0.34232917 -0.33539074 +-0.48506217 1.07517417 +-0.58052853 0.97328586 + 1.42127449 -0.20290376 +-0.39183048 1.02040707 +-0.62271429 1.38445406 +-1.62286110 0.95478903 +-0.84406291 -1.41831634 +-0.81241922 1.22121696 + 0.99585270 1.66151016 +-0.34719291 0.14397792 +-0.43043009 -0.54141487 +-0.71860297 1.35331665 +-0.42362767 0.40682290 +-0.48062435 1.07337661 +-0.64403933 -0.39540518 +-1.20682145 1.31163237 + 0.32591546 -1.51717009 +-0.98439464 1.59340558 +-1.53521313 -1.14231798 +-0.21636614 0.36104222 +-0.47469942 -1.22628876 +-0.38567915 0.63071372 +-1.16027806 1.34729282 +-0.36292738 1.18961391 +-0.31024868 -0.37370633 +-0.40896982 1.42555646 + 0.42532007 -0.63357428 +-0.28621189 0.23492612 +-1.11048711 -1.36687965 +-0.66577896 1.35115783 +-0.21392503 -0.44591791 +-0.36815110 0.69364382 + 1.25746845 1.47626140 +-1.38495585 1.21915608 +-1.28222518 -1.35424120 +-0.41617254 1.27269826 +-1.59166136 0.38260726 +-0.55125726 1.51568086 +-0.47191104 -0.53912710 +-1.34156199 1.25223692 +-1.45934771 -1.32788097 +-0.45508492 1.47780453 +-1.49660089 1.25879692 +-0.44647022 1.42251821 + 0.56771393 -1.43889399 +-0.50112406 1.42937090 + 0.56365752 0.23875599 +-0.47217163 1.42547044 + 0.42377887 1.10105676 +-0.35201711 1.29170494 +-0.48147733 -1.17660087 +-1.40565060 1.34040859 +-1.08560707 -1.58828830 +-0.31986211 0.56945010 +-0.43085927 0.34607761 +-0.70529887 1.39000564 + 1.41445828 -1.02573242 +-0.77812882 1.36684061 + 1.47265361 -0.32168109 +-0.71642896 0.51355019 +-1.49788849 0.26034835 +-0.51234117 1.42731577 + 1.37227722 0.52784304 +-0.46348516 0.29575992 + 1.25522763 -0.73185551 +-1.16132345 1.27627382 +-1.55075597 -1.31398777 +-0.26939794 1.35043607 +-1.41855142 -0.40948380 +-0.25321126 0.48887229 +-1.40730351 -0.37248443 +-0.51232706 0.29926432 +-0.38071407 -0.53674173 +-0.29717868 1.31192675 +-0.44552879 -0.47655817 +-0.31306008 0.38938133 +-0.31976359 -0.65691897 +-0.50726473 0.51589728 + 1.18179590 -1.54875881 +-1.14409922 1.60587726 + 0.33217726 -1.43610604 +-1.11026376 1.26957954 +-1.55899666 -1.15478202 +-0.47506953 -0.59884739 +-0.46988919 1.60307689 +-0.38942873 1.15795644 + 1.34802114 -0.37184219 +-0.62581664 1.38743223 +-0.37790013 1.36513432 +-1.36587105 1.36411209 +-1.29325614 -1.32688108 +-0.41926822 1.40926419 + 1.46536157 1.27287583 +-0.54732285 0.35032616 +-0.44167438 -0.45147896 +-0.70616366 1.30925240 +-0.31623913 0.36939187 +-0.42240683 1.36890939 +-0.39180475 -0.54508873 +-1.29625917 1.30114096 + 0.55951250 -1.19822698 +-1.33033920 1.42169087 +-1.53949061 -1.37310638 +-0.51607031 0.65959938 +-0.21420794 -1.13166431 +-0.40112584 0.10434650 +-1.36412554 1.40217694 +-0.18253252 1.50630130 +-0.47349134 -0.43860083 +-0.24281265 1.33394399 + 0.35117264 -0.50147215 +-0.28598853 0.36919386 +-1.43019023 -1.32049701 +-0.23483888 1.47475181 +-0.27749189 -0.63165706 +-0.46284559 0.42590708 + 1.08632881 1.34309674 +-1.30618130 1.32386728 +-1.35816894 -1.21375094 +-0.64705037 1.48984964 +-1.32633608 0.32874390 +-0.48659272 1.29113157 +-0.52882669 -0.30018355 +-1.45751092 1.14215938 +-1.25142097 -1.39860931 +-0.53341743 1.28465005 +-1.65027378 1.26276577 +-0.36803717 1.16532974 + 0.75207139 -1.46823707 +-0.55737628 1.44321603 + 0.40489024 0.40666496 +-0.20105953 1.48343408 + 0.42229726 1.31399171 +-0.50654098 1.46207753 +-0.23545608 -1.20839381 +-1.45503652 1.46627362 +-1.29302777 -1.31616454 +-0.46427478 0.67428475 +-0.38984232 0.61084960 +-0.45743592 1.38300930 + 1.35002789 -1.28346580 +-0.42253789 1.58876255 + 1.40458190 -0.38428716 +-0.46181943 0.25745516 +-1.29395053 0.31923242 +-0.60644398 1.29051309 + 1.45927536 0.48986704 +-0.56056645 0.68185625 + 1.32389738 -0.36336689 +-1.51990206 1.28573183 +-1.34748636 -1.55220074 +-0.53389984 1.29101337 +-1.31833223 -0.66085964 +-0.42701096 0.42605912 +-1.42175914 -0.78379354 +-0.42512484 0.40394351 +-0.43459708 -0.44407656 +-0.49556879 1.36547008 +-0.72904742 -0.34840364 +-0.46323258 0.31698070 +-0.39594126 -0.48496526 +-0.60301744 0.30669229 + 1.38262772 -1.33212603 +-1.25217969 1.53478372 + 0.32152636 -1.42648234 +-1.15393035 1.59140203 +-1.59386343 -1.15565496 +-0.42095444 -0.46541980 +-0.35802540 1.43752805 +-0.49342695 1.44425771 + 1.47255177 -0.55260500 +-0.27110420 1.26148945 +-0.26427525 1.33989383 +-1.32137320 1.31184928 +-1.62598445 -1.35418536 +-0.43921955 1.25147916 + 1.14912632 1.43009627 +-0.39360822 0.30474643 +-0.41513517 -0.33001712 +-0.50409875 1.15837816 +-0.41303325 0.42035104 +-0.71139901 1.23226139 +-0.45349522 -0.28123507 +-1.50365788 1.11570311 + 0.56486287 -1.31309425 +-1.72565247 1.20407268 +-0.99701980 -1.48266831 +-0.65250340 0.30452062 +-0.38738202 -1.45457535 +-0.58724389 0.27915734 +-1.35821685 1.13913325 +-0.50297633 1.29692739 +-0.42880887 -0.33969887 +-0.36733876 1.28695074 + 0.43097612 -0.58386529 +-0.59728020 0.46009946 +-1.50840720 -1.12879048 + 0.05297976 1.41706535 +-0.56506788 -0.28765738 +-0.42032226 0.51389409 + 1.60625846 1.13329025 +-1.12366083 1.53999467 +-1.58077514 -1.07863608 +-0.29245205 1.34787663 +-1.21011805 0.60199587 +-0.37228587 1.46050541 +-0.42178039 -0.49219996 +-1.32843700 1.48267086 +-1.22760849 -1.48024074 +-0.57000356 1.25087236 +-1.44130397 1.22681830 +-0.73314352 1.30516039 + 0.44591569 -1.36824959 +-0.87774197 1.13965235 + 0.36097326 0.55198381 +-0.52916743 1.20899602 + 0.28575600 1.45408910 +-0.60699782 1.29769355 +-0.25475930 -1.32373641 +-1.31938568 1.50335056 +-1.51052347 -1.08866749 +-0.72070488 0.66505391 +-0.45659354 0.43681641 +-0.33937600 1.36998661 + 1.11243972 -1.37420978 +-0.39586394 1.46996408 + 1.26246348 -0.64423889 +-0.36021352 0.54494751 +-1.48609384 0.41588619 +-0.43868348 1.35742497 + 1.47085328 0.44995339 +-0.31316292 0.63040356 + 1.41070727 -0.34322719 +-1.78035823 1.29090603 +-1.12202816 -1.57423715 +-0.47710792 1.18149901 +-1.33930021 -0.65482861 +-0.52175006 0.32022806 +-1.24222595 -0.55549998 +-0.55208425 0.23946826 +-0.43635780 -0.58306419 +-0.41581288 1.38709588 +-0.58111001 -0.51072254 +-0.32392980 0.27489901 +-0.30789522 -0.50984649 +-0.68270996 0.63877289 + 1.32172043 -1.26227214 diff --git a/QAM/out b/QAM/out index a288096..1a46528 100755 Binary files a/QAM/out and b/QAM/out differ diff --git a/QAM/pll_constellation.gif b/QAM/pll_constellation.gif new file mode 100644 index 0000000..5313117 Binary files /dev/null and b/QAM/pll_constellation.gif differ diff --git a/QAM/pll_error.dat b/QAM/pll_error.dat new file mode 100644 index 0000000..b1002f1 --- /dev/null +++ b/QAM/pll_error.dat @@ -0,0 +1,416 @@ +0 -1.45145122 +1 -1.69906690 +2 -4.47129748 +3 -5.96330133 +4 -6.20274205 +5 -7.13778791 +6 -6.55095757 +7 -7.31721234 +8 -7.08483494 +9 -6.74317554 +10 -5.34416146 +11 -9.48171937 +12 -8.72074064 +13 -4.47730085 +14 -4.42917130 +15 -3.49487851 +16 -2.08100979 +17 -2.55150948 +18 -0.70290026 +19 0.18363787 +20 4.03597337 +21 2.11953487 +22 3.68191049 +23 4.70294370 +24 4.92539441 +25 5.52268401 +26 4.72237126 +27 1.57472911 +28 2.85667589 +29 0.08084627 +30 2.88460646 +31 2.84225779 +32 1.90955201 +33 3.40792005 +34 3.80169821 +35 5.12583620 +36 6.14431738 +37 5.66675682 +38 6.87978408 +39 -0.87481631 +40 -0.05368555 +41 -0.80306149 +42 -0.13019453 +43 -0.34419021 +44 -0.30070107 +45 0.88737764 +46 0.69805424 +47 8.30137602 +48 7.11938407 +49 7.81242046 +50 5.50869135 +51 7.68861587 +52 8.73351157 +53 9.34469514 +54 13.17554315 +55 18.65018280 +56 16.10333524 +57 16.37581363 +58 16.63317216 +59 14.78530104 +60 8.81006528 +61 6.84977226 +62 8.98860843 +63 10.83226215 +64 7.95317945 +65 7.10940122 +66 5.41714263 +67 3.04563046 +68 2.99832724 +69 2.05672074 +70 6.43537931 +71 2.78064022 +72 8.18759541 +73 13.57710530 +74 12.60169208 +75 15.77959050 +76 16.87109105 +77 15.41961906 +78 15.49255411 +79 12.84119520 +80 8.89749301 +81 10.56824668 +82 10.55730128 +83 9.59079221 +84 16.35080551 +85 13.31914194 +86 11.05072593 +87 9.55958089 +88 5.00713647 +89 3.96703103 +90 5.87492565 +91 3.47177735 +92 5.59215940 +93 6.97470545 +94 5.97329242 +95 3.93945986 +96 0.86904990 +97 -2.48934317 +98 0.14338149 +99 -2.16685565 +100 -2.25690594 +101 -0.24335560 +102 -1.33219419 +103 -2.79209131 +104 -9.31325358 +105 -5.52403828 +106 -9.49539136 +107 -5.35570659 +108 -6.10164228 +109 -12.11985791 +110 -13.08769484 +111 -4.00635737 +112 -6.96227952 +113 -4.04450905 +114 -3.64227377 +115 2.56272808 +116 5.77523192 +117 6.86031000 +118 6.62188994 +119 4.56981296 +120 5.75500291 +121 2.60708698 +122 3.32962730 +123 -0.09052149 +124 0.07621438 +125 -0.10467282 +126 -0.68057940 +127 -1.24368959 +128 -3.69074455 +129 -6.44113626 +130 -7.56310359 +131 -6.97913861 +132 -4.15347746 +133 -3.17845751 +134 -5.84090794 +135 -5.34665734 +136 -3.39462249 +137 -3.64969938 +138 -7.47118161 +139 -7.86066917 +140 -5.35381343 +141 -6.37115643 +142 -5.78377818 +143 -2.16272938 +144 -8.77711769 +145 -4.99046608 +146 -3.62371673 +147 -3.45696508 +148 -10.23777868 +149 -7.59832183 +150 -8.83779550 +151 -11.13261158 +152 -10.90480090 +153 -10.00272162 +154 -2.28176461 +155 -2.86432657 +156 -10.00081999 +157 -14.41239732 +158 -13.64677658 +159 -16.88559698 +160 -18.76857263 +161 -21.72090154 +162 -23.62523675 +163 -20.39444483 +164 -16.89736111 +165 -17.50123439 +166 -17.17925405 +167 -16.20401520 +168 -15.46453216 +169 -13.59623072 +170 -10.63738928 +171 -8.22311012 +172 -7.36538599 +173 -5.96911968 +174 -3.04249646 +175 -5.20874414 +176 -2.20705586 +177 0.42838079 +178 4.47557207 +179 5.38295859 +180 6.80423659 +181 6.61924941 +182 7.28338334 +183 4.40105110 +184 3.70794847 +185 2.33214633 +186 -0.25414357 +187 -1.79778196 +188 -4.31533593 +189 -4.62189817 +190 -6.90886381 +191 -7.37663740 +192 -7.31377994 +193 -6.01682373 +194 -6.21451273 +195 -8.00836831 +196 -6.63808044 +197 -5.29252000 +198 -3.67479401 +199 -0.01579635 +200 -3.24272244 +201 -2.33048453 +202 -1.63937137 +203 -1.36790471 +204 -1.45983305 +205 -0.58380344 +206 -0.37285257 +207 0.24099117 +208 0.48661638 +209 -0.13932687 +210 -0.47900574 +211 0.34809387 +212 0.03992012 +213 0.50297697 +214 0.53593848 +215 -3.64907920 +216 -3.58769334 +217 -3.99449156 +218 -4.49021829 +219 -5.08078443 +220 -4.69337199 +221 -2.62307952 +222 -5.50376317 +223 -4.21298382 +224 -2.58114827 +225 -0.92913671 +226 1.03499465 +227 1.96002656 +228 3.43768349 +229 4.69710877 +230 4.56051729 +231 4.67363721 +232 6.59793144 +233 3.96693152 +234 3.15127175 +235 2.00866377 +236 0.48054901 +237 -0.08175854 +238 -3.42615735 +239 -4.02519501 +240 -1.22835864 +241 0.49255752 +242 -0.69301956 +243 -0.42056019 +244 -1.65750588 +245 1.81069703 +246 1.51023294 +247 -0.09192436 +248 -1.95684559 +249 -2.96963711 +250 -3.64243340 +251 -5.13804724 +252 -3.79458214 +253 -4.11955420 +254 -4.01802989 +255 -3.39988071 +256 -2.29684548 +257 -2.87253060 +258 -2.87004370 +259 -2.74227682 +260 -3.10253800 +261 -3.84366334 +262 -1.53462091 +263 -1.50718489 +264 0.22339113 +265 -0.77223672 +266 -1.13854921 +267 0.45827230 +268 0.24445067 +269 1.27468792 +270 0.69046447 +271 -0.11451626 +272 -1.55685215 +273 -0.22709654 +274 5.20895985 +275 4.63052990 +276 2.11208493 +277 1.44270435 +278 -0.28080600 +279 -2.26110351 +280 -3.63402626 +281 -4.02880320 +282 -5.71386376 +283 -1.67717988 +284 -1.32732970 +285 -0.32506023 +286 -0.55533009 +287 -1.29451090 +288 -0.47877935 +289 0.19751679 +290 0.41626688 +291 -2.61897328 +292 -1.39248950 +293 -0.91815048 +294 -0.29724235 +295 0.92815575 +296 0.53076870 +297 1.91918980 +298 2.13336695 +299 1.86855532 +300 -0.37452090 +301 -0.41759410 +302 -0.44867232 +303 0.76005983 +304 0.50404262 +305 0.39574557 +306 -1.72202589 +307 -4.10068383 +308 -4.09485932 +309 -3.80289207 +310 -4.44764031 +311 -3.83613249 +312 -0.91946627 +313 -0.22982236 +314 0.82101275 +315 0.60214958 +316 -0.65258179 +317 -0.25001500 +318 0.44121658 +319 0.96245495 +320 1.45675107 +321 2.69145796 +322 2.37095582 +323 3.97637516 +324 3.85361441 +325 3.58577535 +326 3.50000828 +327 -0.43423912 +328 1.36523917 +329 2.18195567 +330 5.21570149 +331 4.97610029 +332 3.49323687 +333 2.10115109 +334 0.17235424 +335 -1.65693151 +336 -1.19993225 +337 -2.11430285 +338 -2.08670069 +339 -2.53396648 +340 -3.72798679 +341 -5.04291244 +342 -4.91874652 +343 -5.80267373 +344 -5.52241278 +345 -4.28532392 +346 -2.92635899 +347 -4.17278916 +348 -3.22602464 +349 -3.35881958 +350 -1.26911975 +351 -3.84201081 +352 -2.30996479 +353 -1.51851602 +354 0.19661667 +355 2.00483430 +356 5.35872769 +357 5.51796261 +358 8.62712861 +359 8.90680187 +360 8.76741407 +361 6.92001797 +362 5.93110615 +363 3.88445548 +364 4.88271185 +365 2.96859712 +366 5.65956130 +367 1.90664653 +368 0.61185042 +369 -1.36498789 +370 -3.07352133 +371 -5.02975949 +372 -6.06279919 +373 -7.38376800 +374 -7.93086081 +375 -6.88736975 +376 -7.29285632 +377 -6.12726282 +378 -4.89349560 +379 -3.99839930 +380 -1.99635080 +381 -2.17305647 +382 1.25292461 +383 3.15141476 +384 3.73890886 +385 4.68866735 +386 5.46853657 +387 6.38095697 +388 5.18027131 +389 3.03735287 +390 3.12669418 +391 3.02499566 +392 1.86693090 +393 0.49700351 +394 -0.31489838 +395 -2.04849665 +396 -4.23446144 +397 -3.67551828 +398 -3.76101457 +399 -4.01155962 +400 -7.40896510 +401 -6.34552867 +402 -4.55391017 +403 -2.77388463 +404 -2.18594372 +405 -0.88289000 +406 1.42591973 +407 2.18216875 +408 5.82453862 +409 6.82758168 +410 5.95849746 +411 4.78360579 +412 5.21365704 +413 7.31742854 +414 7.11921723 +415 6.83090473 diff --git a/QAM/qam.c b/QAM/qam.c index 9d7b971..e61c466 100644 --- a/QAM/qam.c +++ b/QAM/qam.c @@ -314,6 +314,56 @@ void po(qam_system* qam, double complex* s_with_preamble, double complex* preamb } } +// Costas loop +void pll(qam_system* qam, double complex* s_with_preamble, double complex* r_corr, int L, int total_samples, int nb_symbols, double Kp, double Ki, double alpha, FILE* fp_error) { + double phase_est = 0.0; + double integrator = 0.0; + double filtered_error = 0.0; + + int start_data_idx = L * qam->N; + int N = qam->N; + + for (int k = 0; k < nb_symbols; k++) { + double complex r_k = 0; + for (int n = 0; n < N; n++) { + int idx = start_data_idx + k * N + n; + double t = (double)idx / qam->Fs; + r_k += s_with_preamble[idx] * cexp(-2.0 * I * M_PI * qam->Fc * t) / A; + } + double complex r_symbol = r_k / N; + + r_symbol *= cexp(-I * phase_est); + + double min_dist = INFINITY; + double complex closest = 0; + for (int idx = 0; idx < qam->M; idx++) { + double dist = cabs(r_symbol - qam->constellation[idx]); + if (dist < min_dist) { + min_dist = dist; + closest = qam->constellation[idx]; + } + } + + double error = carg(r_symbol * conj(closest)); + + filtered_error = (1.0 - alpha) * filtered_error + alpha * error; + + integrator += Ki * filtered_error; + phase_est += Kp * filtered_error + integrator; + + if (fp_error) { + fprintf(fp_error, "%d % .8f\n", k, 100 * filtered_error); + fflush(fp_error); + } + + for (int n = 0; n < N; n++) { + int idx = start_data_idx + k * N + n; + r_corr[idx] = s_with_preamble[idx] * cexp(-I * phase_est); + } + } +} + + int main () { // Initialisation du system qam qam_system qam; @@ -354,7 +404,7 @@ int main () { double complex* s_with_preamble = concat_preamble_signal(preamble_mod, L, s_mod, nb_symbols, qam.N); // Ajout du bruit - add_noise(s_with_preamble, total_samples, 10); + add_noise(s_with_preamble, total_samples, 24); FILE *fp_ref = fopen("constellation_ref.dat", "w"); fill_constellation_data(&qam, fp_ref); @@ -364,7 +414,7 @@ int main () { add_dephasage(s_with_preamble, M_PI / 6.0 , total_samples); // AJout de decalage de fréquence - add_freq(&qam, s_with_preamble, 10, total_samples); + add_freq(&qam, s_with_preamble, 50, total_samples); // Estimation / correction du CFO cfo(s_with_preamble, qam.N, L, qam.Fs, total_samples, qam.Fc); @@ -373,10 +423,21 @@ int main () { // Correction phase po(&qam, s_with_preamble, preamble, L, total_samples); + // PLL + double complex* s_corrected = malloc(sizeof(double complex) * total_samples); + double Kp = 0.5; + double Ki = 0.01; + double alpha = 0.1; + FILE *fp_pll_error = fopen("pll_error.dat", "w"); + pll(&qam, s_with_preamble, s_corrected, L, total_samples, nb_symbols, Kp, Ki, alpha, fp_pll_error); + fclose(fp_pll_error); + + + // Démodulation FILE *fp_constel = fopen("constellation.dat", "w"); uint8_t* output_bits = (uint8_t*)malloc(nb_bits * sizeof(uint8_t)); - demodulate(&qam, s_with_preamble + L * qam.N, nb_symbols, output_bits, fp_constel); + demodulate(&qam, s_corrected + L * qam.N, nb_symbols, output_bits, fp_constel); fclose(fp_constel); // Reconstruction du texte