MATLAB Answers

0

can anybody tell me the code how to find sum of series for a complex function?

Asked by vinod kumar govindu on 9 Feb 2017
Latest activity Commented on by vinod kumar govindu on 10 Feb 2017
I had IRx1,QRx1,IRx2,QRx2 vectors
IRx1=[-3.4,2.47,..........27.3]
QRx1=[2.3.............54.5]
the length of IRx1,QRx1,IRx2 and QRx2 are 128.length for all vectors is same that is 128.
x(n)=IRx1+i*QRx1 (complex signal)
y(n)=IRx2+i*QRx2 (complex signal)
i want to find auto correlation for X and cross correlation for X and y. by using below formulaes
ACF(k)=∑(n=0 to 128)〖x(n).*x(n-k) 〗
CCF(k)=∑(n=0 to 128〖x(n).*y(n)〗
Here i attached images of equations also. I tried so many times i am getting errors.
Help me to find ACF and CCF of given complex signals?

  2 Comments

Please post the code, you have tried, and a copy of the complete error message. It is much easier to suggest an improvement than to write the code from scratch.
For ACF "n-k" gets negative for n=0 . How do you try to solve this problem?
Dear simon,
here i posted my code my aim is to find out the auto correlation and cross correlation of the given signals x,y,z.
Auto correlation can be done by compare signal x with itself with some delay. cross correlation can be done by compare twp different signals x,y. I attached a picture contains ACF and CCF equations. In that there is mistake in CCF. It is CCF only not CCF(k). ACF(k) is a auto correlation of x(n) with delayed signal x(n-k). I used symsum function for summation but i am getting error. Given below i posted the error which i got while using symsum funtion.
??? Attempted to access IRx1(0); index must be a positive integer or logical.
Error in ==> G12 at 26 ACF1(i,n)=bug+((IRx1(n)+j.*QRx1(n)).*(IRx1(n-i)-j.*QRx1(n-i)));
I dont know it is correct function for the summation of complex signals.
The procedure is to multiply the x(n) with it self by giving delay x(n-k) and add all those to get ACF.
Help me to solve this coding.
clc;
close all;
clear all;
IRx1=[2.50582817101952,2.41713141145528,1.86841439304153,0.605047602894921,-0.703566724847468,-1.53347690224738,-2.68534618710372,-3.37564979764617,-3.60976457774389,-3.31964450712546,-2.66522613876526,-1.77623560339244,-0.492474329662971,0.160290587013230,0.507220033329129,0.312331782163865,0.113076760989049,-0.510845957116963,-1.02537238124377,-1.54315957923986,-1.92651006745793,-2.07761357141181,-1.96179000520892,-1.61605886905197,-0.998502032475426,-0.606791167516796,-0.408862392930745,-0.721810897897046,-1.03865928287495,-1.67596511911259,-2.17900191449449,-3.22455973533726,-4.20122236827395,-4.88936414084140,-4.98588492090064,-4.64611986699242,-3.89295986195026,-2.85016108345810,-1.51000979182552,-0.114053165824088,1.08073054478529,1.85120398545085,2.05071399629919,1.55713172662244,0.577854501379098,-0.781845566782136,-2.28138320255862,-3.59143240245656,-4.48240785969556,-4.80042560007416,-4.49335459690561,-3.61773210916393,-2.28811421907310,-0.616269087330731,1.34646211479523,2.58576397249433,3.18726452764764,3.55099127809478,3.39245771843159,2.67982568751591,1.28811220734259,0.290545697789977,-1.11083900436137,-2.24846907912449,-3.41008937840863,-4.08132603131973,-4.19202057140981,-3.75598274404288,-2.86511558343952,-1.33166071513922,-0.0888600143436430,1.04383587114973,1.90146530084647,2.36534314627888,2.37807964444616,1.94943719786547,1.15254387997119,0.111265653064370,-1.01930534408229,-2.44869015588492,-3.23965758371861,-3.36628409964266,-3.50424270023697,-3.29456430470408,-2.80531710517118,-2.14315533001624,-1.47170964682503,-0.795233104046106,-0.346629678415243,0.243676163193890,0.0561703047489547,-0.740610277561049,-1.27386267061423,-2.08480520623948,-2.43267440079923,-2.76937121834168,-2.99337398387634,-3.08558943524334,-3.04783986140056,-3.07230565610149,-2.94490942924285,-2.64367433237923,-2.33302680338966,-1.83789598292898,-1.97823772406445,-1.93937035972245,-2.20625565463774,-2.23887113241593,-2.58437228749598,-3.52733915198916,-4.07019344900751,-4.31937286306846,-4.82277220060252,-5.11817728167131,-5.13481364324164,-4.84209660869776,-4.24673283123647,-3.54290123157843,-2.67022083716594,-1.34112096240404,-0.847195923908771,-0.136621642288736,-0.113124944412861,-0.346362291440859,-0.812589735653853,-1.43525740508435,-2.31980008066570,-2.47632619329387];
IRx2=[1.01460425716151,0.789387892284636,0.465419065393918,-0.270674605261502,-0.324209579543460,-0.786127887110611,-1.31672413476201,-1.68974069580242,-1.68683326153294,-1.91463828346887,-1.99070592373177,-1.86159099936316,-1.51752077197991,-0.954746832721099,-0.209994594029173,0.811346972019044,1.61404780608856,1.96001533542083,2.49485352039829,2.76882719749157,2.73797080108476,2.39139122359568,1.75505098733065,0.892009683076733,0.0815037131794636,-1.01857047035352,-2.02213961753928,-2.93877580921443,-3.23294982923665,-2.99973300999368,-2.91528946965527,-2.01533398528999,-0.768915862561078,0.673940528188069,2.12014743798596,3.07912747337142,4.14769021857149,4.55429333026318,4.33404517081416,3.48728067593388,2.11504461592450,0.408386612077747,-1.37865630550980,-2.93271295825688,-4.10799835209611,-4.78408173369122,-4.46062915666738,-3.45118437406266,-1.90549976700760,-0.0589501797260740,1.80599108593936,3.40640695154048,4.54526003105368,5.18679223295696,5.33036875356390,4.48934454418814,3.04699266357109,1.54593614053326,0.135501358878592,-1.09302611399635,-1.85681416548019,-2.15661323317940,-2.32274156157063,-1.88578807031514,-1.04852785251823,0.0680470909691132,1.28358265681183,2.42637788797044,3.35703514167297,3.64767743571924,3.98742663931683,4.00581733933059,3.73109093230059,3.21309282961231,2.51322792193615,1.69750401007136,0.833207984444164,-0.0116689660343153,-0.768138496031731,-1.55330142621117,-1.97458482357104,-2.15477811425155,-1.87735825878768,-1.21139358892745,-0.236527845717644,0.916737394288882,2.02731175399555,3.11127236571521,3.76594186553903,4.15152292241076,3.65721802838211,2.68922312868832,1.35424397679989,-0.422175665866012,-1.47203008503273,-2.72588745633588,-3.60988696547965,-3.97459918433722,-3.75578630206334,-2.70609884338261,-2.18677889085995,-0.724861849873928,0.705065802834293,1.64916146563410,2.43886933811804,2.42744868507788,1.80584985609909,0.908696622442396,-0.705707238128764,-2.27270189339574,-3.37234227805187,-4.20160175589701,-4.17172206185601,-3.55339005011385,-2.42912689725117,-1.31805658267917,0.239514364570606,1.47991933586132,2.36459637723685,2.56164473359209,2.55384087296497,1.60993379649284,0.629564432592203,-0.645304518556036,-1.97479167479100,-3.10148212130029,-3.80003159784154,-3.94619491777448];
IRx3=[-0.993128890005284,-1.76594777520882,-2.31949979637286,-2.21870218475863,-2.45080409040613,-2.28219201343847,-1.02229193980455,0.453921919149053,1.90050025467925,2.59193207732919,2.69060034703535,2.15307465169026,1.05521829466591,-0.413379640224464,-2.00515321844758,-3.31946860669385,-4.41984467230870,-5.23501910734096,-5.16606973083684,-4.46543527319935,-3.25160209193610,-1.72671153217760,-0.140190359696800,1.25484213325138,2.02459808250948,2.62069605149156,2.60946644908517,2.09571076461969,1.01910162812756,-0.269202255127129,-1.23809167199613,-2.47193225700054,-3.38135220256387,-3.83434288531237,-3.68937515950887,-3.39741304134523,-2.42972386681567,-1.50374882556885,-0.508048999212305,0.404545935881431,1.10330611589675,1.49838880640620,1.55228571196290,1.34281769078276,0.842640828669976,-0.0527018153170412,-0.713595602532179,-1.26283024770965,-1.61665181987407,-1.72898418633932,-1.59713183999718,-1.26040333662297,-0.752932366670609,-0.0577665529710810,0.374250486357905,0.941611680965764,1.08213296963860,1.27444212679685,1.21015441855056,0.785605530968928,-0.180891381312223,-0.928904425156226,-1.73454047225642,-2.77036791374945,-3.73068718741744,-4.34861858499960,-4.53295554566547,-4.26883529651507,-3.61886401478481,-2.36423308245108,-1.43888043407460,-0.627189322960582,-0.0783446858768140,0.105958148447062,-0.111671539130095,-0.698782517051578,-1.55953435306677,-2.55178800751300,-3.51170697380857,-3.96060456182168,-4.42738941481774,-4.26437253555307,-4.15000793763006,-3.71955395095441,-3.03386608743514,-2.19598516647012,-1.39928527264283,-0.563069421120779,-0.0488066084850562,0.0229426002962217,-0.166071205981264,-0.696044288513010,-1.47745602544096,-2.36416001821257,-3.14726579723785,-4.02850927072230,-4.71723059101617,-5.10569764618782,-5.12914144917017,-4.99809288524002,-3.92091606240318,-3.00656913581731,-1.91111082249582,-0.565619991349472,0.283627761416091,0.947356788212610,0.948578976391194,0.906033103627324,0.165663577711276,-0.528126599095243,-1.75073591909251,-2.76186496190158,-4.01400972532222,-4.97621829735726,-5.52200879346877,-5.24556962852168,-4.80996281212845,-4.17173805622293,-3.24903463733582,-2.23274479585379,-0.979573531993498,0.423167172481398,1.16521650753348,1.49978408672960,1.36002336661019,0.741577094736565,-0.289522665579945,-1.60088092364450];
QRx1=[-0.144718579660555,0.995946652625673,2.05637645961698,2.61196347518716,3.25632649951836,3.08746302178533,2.45005524983264,1.52879189873049,0.0795600257263762,-0.903503642646553,-1.66384374630175,-2.07219543395580,-1.73663051946867,-1.22493813342171,-0.511968187169972,0.111113406512994,0.796516202647878,0.977755843153328,1.25462033881561,1.24592323194847,0.996209115120566,0.609489969080677,0.223354235342819,-0.0248956407188340,-0.232342453639286,0.174464228212001,0.807619460912736,1.49311646218381,2.21645131610826,2.67054620724355,3.06251300887572,3.09478595401401,2.63306697209545,1.73954071310858,0.532969121848919,-0.652371421489012,-1.45428721135333,-2.28225224335881,-2.60690673920328,-2.34235411873884,-1.51408904246930,-0.255026384528728,1.21922118882082,3.02115178742696,4.10050381643365,4.96903735582075,4.81132933804762,4.04180574992444,2.79181617599615,1.27442184206188,-0.255083903745787,-1.54528645820358,-2.42200036300971,-2.78267604719178,-2.42252639176325,-1.52142442818247,-0.307372780120042,1.16373862378014,2.59566895376017,3.82281007709030,4.68018360704009,5.05114433673019,4.82593849729210,4.20732887404119,3.07060487849618,1.62519161882054,0.0818617642666102,-1.34270890438126,-2.45728108780638,-3.18997435899711,-3.26264000733367,-2.85030338447939,-2.03755274312990,-0.961712703315067,0.208817912882685,1.29975076000225,2.15604845685741,2.66356786203298,2.76429227850948,2.60505351129691,1.84689048244303,0.820028928366605,-0.0623265017645658,-0.862750087599546,-1.46018221335862,-1.77273253255276,-1.73167622697005,-1.53061294715227,-1.07761129848942,-0.782769139847865,0.0264483256493230,0.436887172479494,0.789414211727582,0.727446167963397,0.756415264991138,0.618513152633964,0.393549801823466,0.131886491958235,-0.114912262481089,-0.545127730055126,-0.510377281509120,-0.512557411426055,-0.391659486423605,-0.0710516328225203,0.00509349801989560,0.426987287620363,0.627750665719879,0.943494833829077,1.35343204458950,1.54615610141597,1.51295396896865,1.31529822675633,0.856736949102081,0.198390357042307,-0.569333696382446,-1.32418460730406,-1.92388745351658,-2.45670604169471,-2.70052375902505,-2.08229123921291,-1.73603019307446,-1.13987994071623,-0.474015604873290,0.162399114708555,0.674102061951758,0.524785424561854,0.214556638570243,-0.0938660949699451];
QRx2=[1.25748821083559,1.59232820540285,1.89211923520759,1.88099181061371,1.75907167934012,1.82428183523391,1.78041254700247,1.56472843457122,1.04088165066503,0.646556290077192,0.128310603656031,-0.450501773794132,-1.00480904530030,-1.45912613104007,-1.72868619330447,-1.91466170173093,-1.52145406181707,-0.744755343783896,0.0164457823216737,0.920124206140120,1.87280368258172,2.76798592075878,3.49740829873187,3.96346095177321,3.92634814268997,3.79047264113801,3.25131401251054,2.19516080475489,1.11866898714991,-0.0868644803222537,-1.15381581692583,-2.08217190852378,-2.65256309571722,-2.74086608851374,-2.13703911177943,-1.86213629706259,-0.179665202068858,1.42353419433705,3.09919520661605,4.59655516335476,5.67777383988329,6.15849489368285,5.94162047977465,5.41655735638638,3.89777136864294,1.75659884543326,-0.147314506470493,-1.80654394943821,-2.97361612236474,-3.47952694704350,-3.26168307461630,-2.37373106741707,-0.986656040212108,0.680993458251602,2.66897460606418,4.14915838268406,5.28633393172347,5.56585128716944,5.32155618820885,4.58001729846046,3.68475979062889,2.18321673024426,0.727376002538077,-0.939867972535359,-2.14028958454835,-2.91210522072983,-3.20882166062459,-3.05352877769973,-2.52510818506159,-1.70592670614687,-0.851669664801974,0.0405071413518816,0.874314119614612,1.57491349902664,2.08961027424417,2.38518328361133,2.44437288087680,2.26371843129368,1.85394131721738,1.59842253507776,0.711185513135204,0.0404410173761393,-1.01883306281697,-1.89543095968338,-2.45170009387046,-2.58418936090662,-2.22354516228131,-1.40250297386122,-0.142751951346500,1.59542559405902,2.93768034088717,4.05373057297677,4.77627132908852,4.82664828257853,4.11455681138587,3.49068770809641,2.43703556765478,1.13299280408855,-0.192807969927715,-1.40172126792556,-1.95224338365755,-2.12390938625579,-1.65547574874616,-0.458219572865563,1.07830126344190,2.51125426751961,4.13485781495850,4.96487384457950,5.32729501591053,5.29550758377778,4.46931759931741,3.02864828865319,1.65029660558493,0.362393361769723,-0.594496557791115,-0.988543113338450,-0.925025563983850,-0.334419146424679,0.716880119341661,1.79250194692824,3.22379242483073,4.31309335618836,5.20263838196125,5.57918860188955,5.35976324760898,4.57171837761737,3.35665430473978,1.92253002265421];
QRx3=[1.61469434821989,1.28110087283433,0.593981423858839,-0.0746609794962341,-0.891803824646148,-2.19303462998841,-2.62044173173250,-2.33773458592233,-1.14868797987302,0.187752799404550,1.72921097658605,3.20949521901254,4.35189005875512,4.96422758117794,4.93938714967720,4.08414134060692,3.03450684126624,1.89291039683914,0.263892352374029,-1.21185894615126,-2.29786178930600,-2.82730994360425,-2.73002447245140,-2.04185996536298,-0.978459491542767,0.463296101102056,1.96310381648816,3.47769048065473,4.28572284988762,4.48069796806336,4.52430480758476,3.96142604376931,2.96223292698943,1.69588086517021,0.269549938642862,-0.470169450225313,-1.59577743807407,-2.08965359044770,-2.20036578610210,-1.94267300943902,-1.38745944463219,-0.647424702259412,0.142727660186499,0.457263258501747,1.02854810107158,1.53119350556719,1.43704558729807,1.09870604559311,0.589409191167250,0.00703713408324849,-0.542958205090700,-0.965174046229494,-1.21383179950569,-1.26407039195322,-1.25897405515521,-0.681320371584185,0.0334979706460327,0.911813186967266,1.84129800199022,2.67248382949417,3.19578726489379,3.23645876594367,3.35429118367439,3.44781140646502,2.88762169576680,2.01590005115277,1.00015989096743,0.0286399105764878,-0.722354919489267,-1.13763940346719,-1.04553560746135,-0.566614389385489,0.215915010612429,1.16617500935677,2.11970048353193,2.91199894737582,3.40662737197769,3.51802519672367,3.22535601020925,2.36107413812950,1.58191148418807,0.582199081336153,-0.245139894736487,-0.973514153843321,-1.48447989900030,-1.69133925164542,-1.56892560973338,-1.08445968606643,-0.360974609164748,0.496588571825767,1.40302979009760,2.17079631650935,2.67736691587632,3.13836637897697,2.38054122224518,1.97100715599610,1.24885416031121,0.307919228543620,-0.722710835794146,-1.50341250319490,-2.01468520812255,-2.68666490478536,-2.97425216528387,-2.89646892777086,-2.52379881302396,-1.49901796224810,-0.506869568406280,0.907651361053495,1.75345622216872,2.55545782056647,2.90248642844106,2.86882256178575,2.29975359926686,1.31819570586921,0.0578257551530834,-1.35655604583865,-2.53551533399583,-3.45158622002622,-4.07401651828128,-4.52543821838908,-4.36880666597097,-3.47644873119799,-2.46651478664132,-1.22740964353534,0.0764465476581728,1.26339866951640,2.15988323096008,2.61759542869763];
%IRx and QRx are inphase and quadrature phase signals
x=IRx1+j*QRx1;%IRx1 is inphase signal and QRx1 is quadrature phase
y=IRx2+j*QRx2;
z=IRx3+j*QRx3;
for i=1:128
j=sqrt(-1);
syms IRx1 QRx1
ACF1(i)=symsum((IRx1(n)+j.*QRx1(n)).*(IRx1(n-i)-j.*QRx1(n-i)),n,0,128);
end

Sign in to comment.

2 Answers

Answer by John BG
on 9 Feb 2017
Edited by John BG
on 9 Feb 2017
 Accepted Answer

Hi Vinod Kumar Govindu
having faced similar problem, I found out the following points may be of interest to you
1. that the standard MATLAB function conv has a limitation: it resets the time reference, not really knowing when the convolution starts and stops, let me explain:
i1=randi([-10 10],1,10);
q1=randi([-10 10],1,10);
i2=randi([-10 10],1,10);
q2=randi([-10 10],1,10);
plot(abs(conv(x,y)));grid on
.
as you can see, the resulting convolution always starts n=1 regardless of when do x and y really start. The correlation should tell when both signals start having something in common.
To improve this, the literature reference
Digital Signal Processing Using MATLAB
3rd edition
by Vinay K Ingle, John G Proakis
in page 44 a convolution function is developed taking into account the start and stop indices of x and y:
function [y,ny] = conv_m(x,nx,h,nh)
% Modified convolution routine for signal processing
% --------------------------------------------------
% [y,ny] = conv_m(x,nx,h,nh)
% y = convolution result
% ny = support of y
% x = first signal on support nx
% nx = support of x
% h = second signal on support nh
% nh = support of h
%
nyb = nx(1)+nh(1); nye = nx(length(x)) + nh(length(h));
ny = [nyb:nye];
y = conv(x,h);
2.
The same literature reference suggests another alternative convolution, with the Toeplitz calculation of the equivalent matrix that one just has to multiply to x to obtain y, instead of running all the progressive sums shifting y one reference vector value at a time:
function [y,H]=conv_tp(h,x)
% Linear Convolution using Toeplitz Matrix
% ----------------------------------------
% [y,H] = conv_tp(h,x)
% y = output sequence in column vector form
% H = Toeplitz matrix corresponding to sequence h so that y = Hx
% h = Impulse response sequence in column vector form
% x = input sequence in column vector form
%
Nx = length(x); Nh = length(h);
hc=[h; zeros(Nx-1, 1)];
hr=[h(1),zeros(1,Nx-1)];
H=toeplitz(hc,hr);
y=H*x;
further reading regarding the toeplitz function
3.
Perhaps you would like to consider using function corrcoef that shifts x and places in each line of the output matrix RHO the result of each sum of your expression CCF, corrcoef also outputs how sell correlated are x and y for each value of k, in the shape of another matrix
[rho,pval]=corrcoef(x,y)
the closer a value of pval is to 1, the more alike are x(n) and y(n-k). p(i,j)=1 means identical.
.
4.
Since you want to convolve 2 complex signals, perhaps you would like to decompose the operation the following way:
conv(i1+1j*q1,i2+1j*q2)=
conv(i1,i2)-conv(q1,q2)+(conv(i1,q2)+conv(i2,q1))j
or you would consider working with modulus and phase, and then just check how correlated are modules and phases:
modx=abs(x);ax=angle(x);mody=abs(y);ay=angle(y);
conv(modx,mody)
conv(ax,ay)
.
so, Vinod
if you find this answer useful would you please be so kind to mark my answer as Accepted Answer?
To any other reader, please if you find this answer of any help solving your question,
please click on the thumbs-up vote link,
thanks in advance
John BG

  0 Comments

Sign in to comment.


Answer by Thibaut Jacqmin on 9 Feb 2017

What you want to compute looks like convolutions. I think there is a mistake in the CCF expression which does not depend on k. What you want to compute is probably the sum over n of x(n)*y(n-k). You can find more info on the conv function here (have a look at the "More about" section) :
x = complex(IRx1,QRx1);
y = complex(IRx2,QRx2);
ACF = conv(x, x);
CCF = conv(x, y);

  0 Comments

Sign in to comment.