From b59775ed6aa28a713334155aee5f3309bf016cab Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 19 Jul 2023 21:46:10 +0700 Subject: [PATCH] retake --- Code.m | 8 ++++++++ frequencySpectrum.m | 48 +++++++++++++++++++++++++++++++++++++++++++++ unknownsignal.csv | 1 + 3 files changed, 57 insertions(+) create mode 100644 Code.m create mode 100644 frequencySpectrum.m create mode 100644 unknownsignal.csv diff --git a/Code.m b/Code.m new file mode 100644 index 0000000..64b5412 --- /dev/null +++ b/Code.m @@ -0,0 +1,8 @@ +signal = csvread('unknownsignal.csv'); +Fs = 650; %Hz + +frequencySpectrum(signal,Fs); + +figure; +title('Spectrogram of Unknown Signal') +spectrogram(signal,[],[],[],Fs,'yaxis'); \ No newline at end of file diff --git a/frequencySpectrum.m b/frequencySpectrum.m new file mode 100644 index 0000000..94617d5 --- /dev/null +++ b/frequencySpectrum.m @@ -0,0 +1,48 @@ +function power = frequencySpectrum(signal, fs) +%%%%%%%%%%%%%%%%%% +%function frequencySpectrum(signal, fs) +% +% Task: Display the power spectrum of a given signal +% +% Input: +% - signal: the input signal to process +% - fs: the sampling rate +% +% Output: +% - power: power spectrum of the signal +% +% +% Guillaume Gibert, guillaume.gibert@ecam.fr +% 25/04/2022 +%%%%%%%%%%%%%%%%%% + +n = length(signal); % number of samples + +y = fft(signal, n);% compute DFT of input signal +power = abs(y).^2/n; % power of the DFT + +[val, ind] = max(power); % find the mx value of DFT and its index + +% plots +figure; + +subplot(1,3,1) % time plot +t=0:1/fs:(n-1)/fs; % time range +plot(t, signal) +xticks(0:0.1*fs:n*fs); +xticklabels(0:0.1:n/fs); +xlabel('Time (s)'); +ylabel('Amplitude (a.u.)'); + +subplot(1,3,2) % linear frequency plot +f = (0:n-1)*(fs/n); % frequency range +plot(f,power, 'b*'); hold on; +plot(f,power, 'r'); +xlabel('Frequency (Hz)') +ylabel('Power (a.u.)') + +subplot(1,3,3) % log frequency plot +plot(f,10*log10(power/power(ind))); +xlabel('Frequency (Hz)') +ylabel('Power (dB)') + diff --git a/unknownsignal.csv b/unknownsignal.csv new file mode 100644 index 0000000..d1871db --- /dev/null +++ b/unknownsignal.csv @@ -0,0 +1 @@ +-0.000812667,0.003238888,0.016508771,0.040642663,0.03057009,0.042197716,0.040257548,0.028155009,0.0211113,0.017715434,0.015835723,-0.005508175,-0.022757424,-0.027021875,-0.03520212,-0.041105604,-0.045090823,-0.044211393,-0.037567801,-0.019896313,-0.014805021,-0.010984783,0.003081698,0.026799421,0.034625263,0.04060147,0.036276943,0.032896858,0.033995333,0.036290177,0.029560607,0.019229123,0.007773405,-0.015538026,-0.023803791,-0.033762401,-0.031236986,-0.038617402,-0.042543825,-0.033844405,-0.028167919,-0.027346761,-0.009097952,-0.008167878,0.006376908,0.013982166,0.02765383,0.02989277,0.03623783,0.035657114,0.041199676,0.030193379,0.018701319,0.012590977,-0.001551644,-0.015095001,-0.033588442,-0.023278759,-0.02966461,-0.047082409,-0.044828731,-0.034232122,-0.020345234,-0.024815409,0.001543966,0.003831724,0.020232981,0.026390372,0.043426785,0.041865878,0.047998245,0.044790205,0.035689426,0.033610445,0.013882174,0.005744368,-0.008015793,-0.017194813,-0.018738083,-0.033235947,-0.028794111,-0.041043739,-0.037253405,-0.021011048,-0.02592012,-0.017024487,-0.004088735,0.017685712,0.019733027,0.025888974,0.034567774,0.037726723,0.044425751,0.03294513,0.021482207,0.02308537,-0.000945221,0.003261519,-0.013148854,-0.028521171,-0.022758237,-0.032696836,-0.044387638,-0.029066697,-0.039199589,-0.02828079,-0.023190858,0.000867315,0.006289891,0.012103439,0.028428844,0.039937622,0.032127333,0.035019564,0.033968663,0.035861629,0.027830244,0.018486535,-0.007719719,-0.000114345,-0.023051576,-0.01929123,-0.027879744,-0.030142163,-0.036999556,-0.035840914,-0.019702728,-0.023814967,-0.018422128,-0.002780872,0.006149064,0.014852982,0.033233718,0.027202568,0.028726489,0.028941729,0.029620844,0.019532593,0.025716819,0.007644544,-0.001426042,-0.01724245,-0.022875565,-0.024197017,-0.026164057,-0.037476917,-0.040909373,-0.040741869,-0.014761702,-0.019995924,-0.011435818,0.00653097,0.013262489,0.020535649,0.041980665,0.043171238,0.035913392,0.033072947,0.020648353,0.016570599,0.013486562,0.005125806,-0.009985656,-0.016627756,-0.032516332,-0.042174903,-0.034420571,-0.028220182,-0.034839052,-0.031870031,-0.027039168,-0.016575737,0.006116434,0.012333465,0.016811694,0.02493945,0.035991756,0.029874749,0.034367983,0.037033503,0.030901999,0.023571272,0.003973171,-0.013268295,-0.005840869,-0.025776274,-0.028490496,-0.043123199,-0.037352522,-0.038488213,-0.032803249,-0.02618398,-0.005936867,-0.013247689,0.007202172,0.012102535,0.021431447,0.031335595,0.039849256,0.036055036,0.034574884,0.033471072,0.030159165,0.011657935,0.007368376,-0.014197753,-0.021823194,-0.029212825,-0.023236427,-0.040508745,-0.029485345,-0.031864097,-0.018720853,-0.02500824,-0.000723804,0.001517538,0.012547078,0.020393369,0.032501354,0.0331454,0.025508289,0.035261932,0.022624132,0.033768501,0.019384398,0.004884892,0.005693031,-0.003484076,-0.023308666,-0.024992736,-0.040948983,-0.024519032,-0.022492626,-0.028592505,-0.014153487,-0.017291554,-0.001388085,-0.000944914,0.017437656,0.026395925,0.035250294,0.023077193,0.031213788,0.02209527,0.028363247,0.012569166,0.011013851,0.008975089,-0.011160014,-0.012951405,-0.030961403,-0.030763302,-0.040480625,-0.037324727,-0.021493594,-0.022673205,-0.008606766,-0.006430845,-0.006680589,0.011848147,0.026748418,0.016614588,0.028338281,0.032912485,0.032800975,0.030603359,0.017592695,0.024065202,-0.004430179,0.003544906,-0.017303745,-0.027087158,-0.036394719,-0.020861682,-0.035912608,-0.031130736,-0.035194746,-0.027124775,-0.002340039,0.001143853,0.007160653,0.021895827,0.023523327,0.031617778,0.030821787,0.021687742,0.025128452,0.030415496,0.017569622,0.01440135,-0.007084377,-0.005961414,-0.019084627,-0.029530295,-0.020087522,-0.027446159,-0.030038884,-0.026767835,-0.015766925,-0.005802045,-0.004981526,-0.000387547,0.013166257,0.019341649,0.016295857,0.020564906,0.033664036,0.036098453,0.019112989,0.022790015,0.009806698,0.002246072,-0.004632752,-0.008440475,-0.024875071,-0.015120707,-0.022154326,-0.024347231,-0.020505847,-0.022911265,-0.020832697,-0.018905752,-0.010482462,0.006440874,0.012373052,0.011547971,0.033355933,0.02633494,0.034343403,0.017470719,0.017830689,0.013882097,-0.000493391,0.007041842,-0.010989623,-0.00742571,-0.027823695,-0.019009901,-0.027870744,-0.032155128,-0.033695156,-0.024177995,-0.019256038,0.002638699,-0.004367448,0.01378707,0.011724597,0.016574269,0.032972191,0.033464963,0.033101288,0.026284161,0.022565212,0.007634158,0.001510373,-0.012979526,-0.018957138,-0.026174743,-0.027630969,-0.014951472,-0.029174752,-0.017787754,-0.015811877,-0.02235518,-0.012714638,0.001510062,0.011253437,0.006445612,0.011537624,0.018633135,0.030295498,0.033797617,0.022493421,0.019946922,0.012720377,-0.000589019,0.010028395,-0.005459536,-0.016827869,-0.021009997,-0.021426701,-0.016366411,-0.015387749,-0.026198913,-0.011188313,-0.007846332,-0.013340096,0.008117047,0.000975525,0.023678117,0.021701419,0.029053032,0.019212379,0.016035516,0.026828068,0.007395981,0.0076898,0.005712412,-0.008255969,-0.013281531,-0.023406062,-0.025698137,-0.022744862,-0.017466554,-0.020586253,-0.013911745,-0.01523797,0.001197811,0.003592119,0.008751375,0.006703889,0.012340358,0.011030758,0.026770053,0.019268763,0.014785722,0.025319481,0.004750582,-0.002496144,-0.003934896,-0.011125386,-0.003135053,-0.015268925,-0.026316841,-0.028165232,-0.022446849,-0.018020766,-0.00530767,-0.015208576,-0.010292294,-0.001609335,0.014687953,0.020190745,0.009792215,0.027300833,0.010053094,0.012005408,0.011720426,0.013000269,0.011824081,0.012709625,0.002764646,-0.002139516,-0.003513259,-0.021582208,-0.024112123,-0.01863842,-0.026361957,-0.017339486,-0.005907616,-0.010125942,-0.000911008,0.003837098,0.010201784,0.011137299,0.014489822,0.025903461,0.020666721,0.007037701,0.012904853,0.008392138,0.006327448,-0.006187031,-0.008217985,-0.009106446,-0.021305794,-0.013769526,-0.023794341,-0.022471831,-0.007904523,-0.003803766,-0.002670669,-0.000589447,-0.008015331,0.005347641,0.009181624,0.01597409,0.02059815,0.010454621,0.006376976,0.022683085,0.015347056,0.006962186,0.005459004,0.003829496,-0.004481629,-0.019355689,-0.013792398,-0.005643428,-0.023579247,-0.012802036,-0.010643483,-0.006141476,-0.000535344,9.20E+09,-0.000817562,0.011400718,0.015090151,0.021109999,0.022532472,0.009805494,0.010500285,0.015861258,0.003744137,-0.005184099,-0.005213717,-0.010103474,-0.00084713,-0.00756084,-0.003178268,-0.017965528,-0.009977618,-0.003897023,-0.005110671,-0.007694324,-0.01088751,0.008861911,0.00510308,0.010153641,0.0138556,0.014577289,0.014288758,0.016580006,0.007901433,0.011855049,0.000248655,-0.001626111,-0.002792385,-0.008328697,-0.016549463,-0.010732838,-0.004698104,-0.017091481,-0.006972506,-0.007287868,-0.008536148,-0.007284111,-0.005682398,0.000989942,0.01081782,0.017115797,0.001622825,0.010223084,0.000259739,0.009386063,0.000564041,-0.002385168,-0.002897787,-0.00598241,-0.005726369,0.003423615,-0.012628384,-0.014141561,0.000411147,-0.006528388,-0.010802122,-0.008375943,0.00541639,0.001064153,-0.001291464,0.008718895,-0.002634712,0.01055342,0.012214905,0.0138534,0.010472335,0.014999118,0.005262716,0.013162855,-0.005917982,-0.007139583,-0.002717935,-0.010201668,0.000954307,0.002446496,-0.007650278,-0.015053745,-0.010350166,-0.003476093,0.002783569,0.006210022,-0.005569041,0.000624916,0.001651019,0.00439984,0.010701344,0.00482052,0.01468358,0.000128375,0.011410181,0.002092087,0.002638574,-0.009380251,-0.000501161,-0.005250804,-0.007726809,0.000257277,-0.003582858,-0.00800655,0.00302186,-0.007262183,0.002465995,-0.008793392,0.009409362,-0.00435911,-0.005190161,0.008595009,-0.002309009,-0.001815093,-0.004581098,9.11E+07,0.004872272,-0.006667158,0.001729052,0.006121835,-0.003275189,0.00054752,-0.000226829,-0.000119477,0.005512117,0.002273266,0.006863555,-0.001233273,0.001438275,-0.003199227,-0.008234372,0.007370168,0.001050347,-0.003032929,0.007432969,0.006690174,0.007826455,0.003340175,0.00553887,0.003229223,0.001607839,0.004550239,0.008537368,-0.007933537,0.003182556,-0.010292159,0.002055704,-0.002119661,-0.000976062,0.002062435,-0.00012837,0.007605009,0.006795447,-0.006871017,-0.00452655,-0.001625335,0.001427158,0.017592769,0.047653923,0.003368045,0.002521002,-0.01752427,-0.043216763,-0.041284289,-0.016917864,0.018745324,0.014745505,0.01016692,0.01829161,0.005426465,-0.012085623,-0.029311967,-0.035604768,-0.027229846,0.004942604,0.009984555,0.006512813,0.015387177,0.03637832,0.022484382,0.007724569,-0.018987828,-0.031330534,-0.021454047,0.00185214,0.013921164,0.020843153,0.023624171,-0.001588715,-0.001787767,-0.010159878,0.002318265,-0.008645518,-0.016258119,-0.002432571,0.001196085,-0.009210615,0.011052748,-0.006981801,-0.000465963,-0.0089554,-0.004208982,-0.018368208,-0.017224818,-0.02013574,0.000391728,-0.001656048,0.002876921,0.020974833,0.020507077,0.014441283,-0.010309063,0.014565023,0.00105591,-0.035840487,-0.032183447,-0.010562369,0.016309956,0.000958434,0.03803039,0.016569037,0.015619893,-0.007275498,-0.001830825,-0.019893127,-0.005290292,0.006610616,0.016953636,0.043496212,0.029496424,0.029350193,0.009077218,-0.006655657,-0.005993313,-0.025825939,-0.001812637,-0.009022613,0.011185427,0.044577209,0.019711923,0.007152316,-0.006916271,-0.00392177,-0.031832939,-0.036739353,-0.020420431,-0.002429663,0.028845467,0.023256294,0.012939947,0.023584201,-0.019135747,-0.002795173,-0.02133069,-0.030629464,0.006596637,0.010916709,0.003679478,0.037459907,0.005732169,0.003752108,-0.017055946,-0.000800766,-0.017269404,-0.025259443,-0.004021395,0.014282645,-0.001658054,0.006305429,0.008124944,0.017990914,0.011220842,0.005956475,-0.028766888,0.007469669,-0.015926866,0.013053268,0.013699763,0.020975877,0.011175484,0.008437444,0.02665514,-0.003376323,-0.019529612,-0.016599951,-0.02435656,-0.026219675,-0.000291325,-0.014756901,-0.007672308,0.000134371,0.009337036,-0.00389884,0.015253533,-0.011780155,-0.015580621,-0.026064288,-0.010523392,0.015052497,0.034386371,0.023664758,0.013262762,-0.005391324,0.016484863,-0.027788228,-0.04034074,-0.024362103,-0.019654806,-0.005452003,0.040043832,0.042530008,0.022824578,0.007972682,-0.02500734,-0.033651762,-0.027470668,-0.017798195,-0.011426196,0.014154392,0.014143536,0.01197981,0.026982546,0.023534113,-0.014374446,-0.033899767,-0.044066562,-0.03475663,0.005439924,0.01433779,0.016222258,0.018937704,0.021962026,-0.01022072,-0.01539469,-0.012435376,-0.012358436,-0.001349187,-0.006809267,-0.006807008,0.036378834,0.014307009,0.015284173,-0.016705639,-0.013094483,-0.024748458,-0.022057803,-0.016741356,0.015036916,-0.011094636,0.014297264,0.004987669,0.003011112,0.003840198,0.006884841,-0.007089716,-0.00755398,0.001443045,0.013295702,-0.00029825,0.016597515,-0.002040409,0.003343162,0.003026954,0.021953188,-0.01311234,0.002258259,-0.013035019,0.001343912,-0.022727826,0.015177995,0.008829832,0.018112308,0.017695097,0.022673135,0.004047533,-0.027426525,-0.015384344,-0.03561601,0.005046126,0.005071417,0.009241519,0.041078369,0.04384877,0.013349708,0.008402824,-0.031224701,-0.006406872,-0.00631246,-0.01736622,0.014904878,0.008809547,0.032069394,0.012860607,0.019622974,0.003695141,-0.007698237,-0.04836464,-0.031126001,-0.031843259,0.009099302,0.008384516,0.030620241,0.041673512,0.00635588,0.001734077,-0.03525444,-0.030787417,-0.03962597,-0.018993998,0.024726319,0.025514097,0.043440717,0.024015853,-0.009477344,-0.007148216,-0.005811694,-0.042479075,-0.021523459,-0.003248533,0.01220653,0.024429807,0.011962761,0.034222478,-0.016140931,0.00678244,-0.024840718,-0.030243284,-0.032000155,0.015268431,-0.003371123,0.009549388,-0.004864412,-0.0039649,0.023968281,0.006481455,-0.005125279,0.00446581,-0.006497815,0.001964908,-0.000929478,-0.014839943,0.000782785,0.022887291,0.00987421,0.016034481,-0.015299296,-0.00215063,-0.017504253,-0.026753169,0.004572277,0.001846038,0.005599133,0.014704012,0.030061536,0.033150881,0.009508151,-0.010576005,-0.010692466,-0.017783326,-0.032054039,-0.020427977,0.01672514,0.03502529,0.011817641,0.024516555,-0.000744528,-0.015904137,-0.025283375,-0.020222072,-0.031664918,0.014254443,0.02460817,0.034949133,0.042208608,0.02087434,-0.003464785,-0.032275694,-0.043624624,-0.027181731,-0.020100331,-0.016904059,0.035010093,0.026242654,0.040651106,-0.001119719,-0.010260345,-0.023183264,-0.046346241,-0.012854829,-0.020240101,0.019162332,0.005855671,0.039120222,0.021917442,0.000249939,-0.024156734,-0.027679171,-0.035719338,-0.002357626,-0.020263065,0.015037958,0.008432027,0.011257793,0.032679374,0.02057389,0.009553519,-0.007177153,-0.007974516,-0.021732649,-0.011364907,-0.015779798,-0.005892264,-0.004660644,0.000392991,0.026382444,-0.007124146,0.007001835,0.000592341,-0.023273503,-0.01449545,0.003987634,0.014064583,-0.004492643,-0.002886493,0.003095179,0.018892323,0.019884423,-0.005795088,-0.009230872,-0.015730985,-0.027543719,0.014218035,0.006471253,0.005285088,0.012246782,0.017297269,0.023178116,0.012996465,-0.024259702,-0.008412982,-0.010864919,-0.025167074,0.017969332,0.003167785,0.043079435,0.026626848,0.02333228,-0.014948627,-0.033896628,-0.013178469,-0.038805809,-0.013117764,0.013554771,0.013520865,0.021489821,0.00593622,-0.005845059,-0.01352189,-0.0157903,-0.028375624,-0.013002774,-0.007937552,0.03234995,0.037644092,0.037358459,0.011816751,-0.004253514,-0.032224509,-0.016255318,-0.032109556,-0.027289775,0.017453769,0.002339006,0.008803429,0.017251642,0.004266006,0.015307962,-0.014662888,-0.038277733,-0.037143109,-0.015997042,0.003064923,0.033858522,0.010558793,0.007006129,0.00351028,0.01269691,0.003391274,-0.030196359,0.001446954,-0.027899788,-0.013258057,-0.001141716,0.013036841,0.019664447,0.027756516,0.012561679,0.007137063,0.009377658,-0.021001178,-0.020098073,-0.004029303,-0.016404126,0.00155026,0.020322821,0.00340205,0.009217116,0.003098278,-0.000705645,-0.013466018,-0.016524314,0.003648797,-0.001711316,-0.017472539,0.008952711,0.01379237,0.019271056,-0.001931098,-0.00693165,-0.011262603,-0.035921195,-0.015975864,-0.025765912,-0.010292862,0.029203865,0.040002273,0.033825961,0.018918996,-0.0212652,-0.019170195,-0.028370901,-0.019411438,-0.002387018,-0.006709616,0.002417521,0.04691352,0.034916161,0.012246874,-0.000494151,-0.01058279,-0.025386297,-0.042551848,-0.0107309,0.027814267,0.007808368,0.032704791,0.025985544,0.012799637,-0.002262744,-0.023199882,-0.036983169,-0.012384787,0.004482914,0.029294393,0.041599386,0.017934838,0.01304818,0.012995103,-0.020647859,-0.040956371,-0.033581081,-0.026997107,0.012345863,0.018012869,0.038561461,0.010509571,0.018290398,0.016062287,-0.002017773,-0.019681492,-0.032983507,0.005082136,-0.000497286,0.01199402,0.019836603,0.018786446,0.013428142,0.012752877,-0.008181278,-0.000468224,-0.019741101,-0.015714779,-0.007576427,-0.007132051,-0.012849973,0.006939533,0.023128462,-0.002461986,0.012048341,0.001857381,-0.011912953,-0.019703715,-0.023349181,-0.012061615,0.009937519,0.027153242,-4.78E+10,0.017286129,-0.007355273,0.002533625,-0.023730283,-0.034137914,-0.032042492,-0.026474804,-0.00794619,0.02953542,0.011661064,0.013144868,0.035596163,0.006508148,-0.020034296,-0.029266597,-0.00692411,-0.010896779,-0.004068995,0.028135682,0.011705923,0.034353706,0.024170305,0.00880552,-0.014461837,-0.012824337,-0.026888694,0.006029819,-0.008936679,0.009921889,0.031005742,0.015660044,0.026350658,0.012087465,-0.023519079,-0.04568911,-0.033122532,-0.007851893,0.018808214,0.035591539,0.012725889,0.015410639,0.000503015,-0.012117113,-0.012224262,-0.026847951,0.000539656,-0.013551566,0.025813697,0.020053533,0.026415206,-0.000421421,0.009067681,-0.009852098,-0.02120623,-0.006210823,-0.00952438,-0.010937347,0.018293762,0.00164455,0.020178841,-0.007877896,0.020095263,-0.0163303,-0.025047968,-0.001184514,-0.022846791,-0.018268314,-0.017810051,-0.001632793,0.014592839,-0.003885343,0.014566264,0.021690347,-0.001541353,0.000401662,-0.005956247,-0.007543014,0.006134451,0.005905581,0.023061449,0.013329388,0.020452623,0.006560278,-0.013826855,0.004529317,-0.0188798,-0.031417956,-0.006280269,0.003953338,0.021313377,0.025049514,0.034694683,0.025587833,0.009749759,-2.53E+10,-0.004266706,-0.04066645,-0.011290869,-0.023028333,0.018940352,0.022835894,0.027100856,0.02372983,0.00199116,-0.000965148,-0.014664508,-0.042803059,-0.027248381