walsh变换matlab仿真word.docx
- 文档编号:28292921
- 上传时间:2023-07-10
- 格式:DOCX
- 页数:11
- 大小:55.83KB
walsh变换matlab仿真word.docx
《walsh变换matlab仿真word.docx》由会员分享,可在线阅读,更多相关《walsh变换matlab仿真word.docx(11页珍藏版)》请在冰豆网上搜索。
walsh变换matlab仿真word
Openwalshhadamarddemo.mintheEditor
RunintheCommandWindow
DiscreteWalsh-HadamardTransform
Contents
∙Introduction
∙Walsh(orHadamard)Functions
∙DiscreteWalsh-HadamardTransform
∙Walsh-TransformApplications
∙References
Introduction
TheWalsh-Hadamardtransform(WHT)isasuboptimal,non-sinusoidal,orthogonaltransformationthatdecomposesasignalintoasetoforthogonal,rectangularwaveformscalledWalshfunctions.ThetransformationhasnomultipliersandisrealbecausetheamplitudeofWalsh(orHadamard)functionshasonlytwovalues,+1or-1.
WHTsareusedinmanydifferentapplications,suchaspowerspectrumanalysis,filtering,processingspeechandmedicalsignals,multiplexingandcodingincommunications,characterizingnon-linearsignals,solvingnon-lineardifferentialequations,andlogicaldesignandanalysis.
ThisdemoprovidesanoverviewoftheWalsh-Hadamardtransformandsomeofitspropertiesbyshowcasingtwoapplications,communicationsusingspreadspectrumandprocessingofECGsignals.
Walsh(orHadamard)Functions
Walshfunctionsarerectangularorsquarewaveformswithvaluesof-1or+1.AnimportantcharacteristicofWalshfunctionsissequencywhichisdeterminedfromthenumberofzero-crossingsperunittimeinterval.EveryWalshfunctionhasauniquesequencyvalue.
Walshfunctionscanbegeneratedinmanyways(see[1]).HereweusethehadamardfunctioninMATLAB®togenerateWalshfunctions.LengtheightWalshfunctionsaregeneratedasfollows.
N=8;%LengthofWalsh(Hadamard)functions
hadamardMatrix=hadamard(N)
hadamardMatrix=
11111111
1-11-11-11-1
11-1-111-1-1
1-1-111-1-11
1111-1-1-1-1
1-11-1-11-11
11-1-1-1-111
1-1-11-111-1
Therows(orcolumns)ofthesymmetrichadamardMatrixcontaintheWalshfunctions.TheWalshfunctionsinthematrixarenotarrangedinincreasingorderoftheirsequenciesornumberofzero-crossings(i.e.'sequencyorder')butarearrangedin'Hadamardorder'.TheWalshmatrix,whichcontainstheWalshfunctionsalongtherowsorcolumnsintheincreasingorderoftheirsequenciesisobtainedbychangingtheindexofthehadamardMatrixasfollows.
HadIdx=0:
N-1;%Hadamardindex
M=log2(N)+1;%Numberofbitstorepresenttheindex
Eachcolumnofthesequencyindex(inbinaryformat)isgivenbythemodulo-2additionofcolumnsofthebit-reversedHadamardindex(inbinaryformat).
binHadIdx=fliplr(dec2bin(HadIdx,M))-'0';%Bitreversingofthebinaryindex
binSeqIdx=zeros(N,M-1);%Pre-allocatememory
fork=M:
-1:
2
%Binarysequencyindex
binSeqIdx(:
k)=xor(binHadIdx(:
k),binHadIdx(:
k-1));
end
SeqIdx=binSeqIdx*pow2((M-1:
-1:
0)');%Binarytointegersequencyindex
walshMatrix=hadamardMatrix(SeqIdx+1,:
)%1-basedindexing
walshMatrix=
11111111
1111-1-1-1-1
11-1-1-1-111
11-1-111-1-1
1-1-111-1-11
1-1-11-111-1
1-11-1-11-11
1-11-11-11-1
DiscreteWalsh-HadamardTransform
TheforwardandinverseWalshtransformpairforasignalx(t)oflengthNare
Fastalgorithms,similartotheCooley-Tukeyalgorithm,havebeendevelopedtoimplementtheWalsh-HadamardtransformwithcomplexityO(NlogN)(see[1]and[2]).SincetheWalshmatrixissymmetric,boththeforwardandinversetransformationsareidenticaloperationsexceptforthescalingfactorof1/N.ThefunctionsfwhtandifwhtimplementtheforwardandtheinverseWHTrespectively.
Example1PerformWHTontheWalshmatrix.Theexpectedresultisanidentitymatrixbecausetherows(orcolumns)ofthesymmetricWalshmatrixcontaintheWalshfunctions.
y1=fwht(walshMatrix)%FastWalsh-Hadamardtransform
y1=
10000000
01000000
00100000
00010000
00001000
00000100
00000010
00000001
Example2ConstructadiscontinuoussignalbyscalingandaddingarbitrarycolumnsoftheHadamardmatrix.ThissignalisformedusingweightedWalshfunctions,sotheWHTshouldreturnnon-zerovaluesequaltotheweightsattherespectivesequencyindices.WhileevaluatingtheWHT,theorderingisspecifiedas'hadamard',becauseaHadamardmatrix(insteadoftheWalshmatrix)isusedtoobtaintheWalshfunctions.
N=8;
H=hadamard(N);%Hadamardmatrix
%ConstructasignalbyaddingafewweightedWalshfunctions
x=8.*H(1,:
)+12.*H(3,:
)+18.*H(5,:
)+10.*H(8,:
);
y=fwht(x,N,'hadamard')
y=
80120180010
WHTisareversibletransformandtheoriginalsignalcanberecoveredperfectlyusingtheinversetransform.Thenormbetweentheoriginalsignalandthesignalobtainedfrominversetransformationequalszero,indicatingperfectreconstruction.
xHat=ifwht(y,N,'hadamard');
norm(x-xHat)
ans=
0
TheWalsh-Hadamardtransforminvolvesexpansionusingasetofrectangularwaveforms,soitisusefulinapplicationsinvolvingdiscontinuoussignalsthatcanbereadilyexpressedintermsofWalshfunctions.BelowaretwoapplicationsofWalsh-Hadamardtransforms.
Walsh-TransformApplications
ECGsignalprocessingOften,itisnecessarytorecordelectro-cardiogram(ECG)signalsofpatientsatdifferentinstantsoftime.Thisresultsinalargeamountofdata,whichneedstobestoredforanalysis,comparison,etc.atalatertime.Walsh-HadamardtransformissuitableforcompressionofECGsignalsbecauseitoffersadvantagessuchasfastcomputationofWalsh-Hadamardcoefficients,lessrequiredstoragespacesinceitsufficestostoreonlythosesequencycoefficientswithlargemagnitudes,andfastsignalreconstruction.
AnECGsignalanditscorrespondingWalsh-Hadamardtransformisevaluatedandshownbelow.
x1=ecg(512);%Singleecgwave
x=repmat(x1,1,8);
x=x+0.1.*randn(1,length(x));%Noisyecgsignal
y=fwht(x);%FastWalsh-Hadamardtransform
figure('Color','white');
subplot(2,1,1);
plot(x);
xlabel('Sampleindex');
ylabel('Amplitude');
title('ECGSignal');
subplot(2,1,2);
plot(abs(y))
xlabel('Sequencyindex');
ylabel('Magnitude');
title('WHTCoefficients');
Ascanbeseenintheaboveplot,mostofthesignalenergyisconcentratedatlowersequencyvalues.Forinvestigationpurposes,onlythefirst1024coefficientsarestoredandusedtoreconstructtheoriginalsignal.Truncatingthehighersequencycoefficientsalsohelpswithnoisesuppression.Theoriginalandthereproducedsignalsareshownbelow.
y(1025:
length(x))=0;%Zeroingoutthehighercoefficients
xHat=ifwht(y);%SignalreconstructionusinginverseWHT
figure('Color','white');
plot(x);
holdon
plot(xHat,'r');
xlabel('Sampleindex');
ylabel('ECGsignalamplitude');
legend('OriginalSignal','ReconstructedSignal');
Thereproducedsignalisveryclosetotheoriginalsignal.
Toreconstructtheoriginalsignal,westoredonlythefirst1024coefficientsandtheECGsignallength.Thisrepresentsacompressionratioofapproximately4:
1.
req=[length(x)y(1:
1024)];
whosxreq
NameSizeBytesClassAttributes
req1x10258200double
x1x409632768double
CommunicationusingSpreadSpectrumSpreadspectrum-basedcommunicationtechnologies,likeCDMA,useWalshcodes(derivedfromWalshfunctions)tospreadmessagesignalsandWHTtransformstodespreadthem.SinceWalshcodesareorthogonal,anyWalsh-encodedsignalappearsasrandomnoisetoaterminalunlessthatterminalusesthesamecodeforencoding.Belowwedemonstratetheprocessofspreading,determiningWalshcodesusedforspreading,anddespreadingtorecoverthemessagesignal.
TwoCDMAterminalsspreadtheirrespectivemessagesignalsusingtwodifferentWalshcodes(alsoknownasHadamardcodes)oflength64.ThespreadmessagesignalsarecorruptedbyaadditivewhiteGaussiannoiseofvariance0.1.
Atthereceiver(basestation),signalprocessingisnon-coherentandthereceivedsequenceoflengthNneedstobecorrelatedwith2^NWalshcodewordstoextracttheWalshcodesusedbytherespectivetransmitters.ThiscanbeeffectivelydonebytransformingthereceivedsignalstosequencydomainusingthefastWalsh-Hadamardtransform.Usingthesequencylocationatawhichapeakoccurs,thecorrespondingWalsh-Hadamardcode(ortheWalshfunction)usedcanbedetermined.TheplotbelowshowsthatWalsh-Hadamardcodeswithsequency(withordering='hadamard')60and10wereusedinthefirstandthesecondtransmitter,respectively.
loadmess_rcvd_signals.mat
N=length(rcvdSig1);
y1=fwht(rcvdSig1,N,'hadamard');
y2=fwht(rcvdSig2,N,'hadamard');
figure('Color','white');
plot(0:
63,y1,0:
63,y2,'r');
xlabel('Sequencyindex');
ylabel('WHToftheReceivedSignals');
title('Walsh-HadamardCodeExtraction');
legend('WHTofTx-1signal','WHTofTx-2signal');
Despreading(ordecoding)toextractthemessagesignalcanbecarriedoutinastraightforwardmannerbymultiplyingthereceivedsignalsbytherespectiveWalsh-hadamardcodesgeneratedusingthehadamardfunction.(NotethattheindexinginMATLAB®startsfrom1,henceWalsh-Hadamardcodeswithsequency60and10areobtainedfrombyselectingthecolumns(orrows)61and11intheHadamardmatrix.)
N=64;
hadamardMatrix=hadamard(N);
codeTx1=hadamardMatrix(:
61);%Codeusedbytransmitter1
codeTx2=hadamardMatrix(:
11);%Codeusedbytransmitter2
Thedecodingoperationtorecovertheoriginalmessagesignalis
xHat1=codeTx1.*rcvdSig1;%Decodedsignalatreceiver1
xHat2=codeTx2.*rcvdSig2;%Decodedsignalatreceiver2
Therecoveredmessagesignalsatthereceiversideareshownbelowandsuperimposedwiththeoriginalsignalsforcomparison.
subplot(2,1,1);
plot(x1);
holdon
plot(xHat1,'r');
legend('OriginalMessage','ReconstructedMessage','Location','Best');
xlabel('Sampleindex');
ylab
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- walsh 变换 matlab 仿真 word