Basic Measurement

12
ME 7292 Control System Labs Spring 2014 Week 3 Sampling, Aliasing and Data Acquisition Kirti Deo Mishra mishra.98 January 30, 2014

description

Sampling, Aliasing and more.

Transcript of Basic Measurement

ME7292ControlSystemLabsSpring2014Week3Sampling,AliasingandDataAcquisitionKirtiDeoMishramishra.98January30,2014Contents1 Objective 22 Equipments 23 ExperimentProcedure 23.1 Assignment1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23.2 Assignment2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 ResultsandAnalysis 34.1 Assignment1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34.2 Assignment2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 Conclusion 96 Appendix 9ListofFigures1 SimulinkScreenshot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 ControldeskScreenshot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 OriginalVsSampledDataSignal(BothMonitors)-20mssampling. . . . . . . . . . 44 Comparisonplots-20ms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 Comparisonplots(20ms)-20Hzvs30Hz. . . . . . . . . . . . . . . . . . . . . . . . 56 OriginalVsSampledDataSignal(BothMonitors)-1mssampling . . . . . . . . . . 67 Comparisonplots-1ms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 Comparisonplots(1ms)-20Hzvs30Hz . . . . . . . . . . . . . . . . . . . . . . . . 79 DataAcquisitionMethods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 811 Objective1. ToinvestigatethealiasingeectandverifytheNyquistSamplingTheorem.2. TounderstanddSPACEsoftwareandhardwareenvironment.3. TounderstandthedataacquisitionusingdSPACE.2 EquipmentsEquipmentsusedfortheexperimentmainlywere1. DigitalComputer2. dSpaceDS1104Floating-PointControllerBorad3. OneBNCcables3 ExperimentProcedureOverall, experimentationconsistedof makingof simulinkmodel, convertingthe model intoanequivalent Ccode whichcouldbe loadedonthe controller boardandreal time control of thesimulinkmodel throughcontrol desk(GUIforDSpaceboard)software. Thissectiontalksabouttheexperimentalprocedureadoptedforassignmentsandthenextsectiontalksaboutresultsandanalysis.3.1 Assignment11. AsimulinkmodelwascreatedwhichwasconvertedtoanequivalentC-codebybuildingthemodelinSimulink. Themodelwasrebuildwithdierentsamplingfrequencylateron(1ms).Figure1: SimulinkScreenshot22. Anewinterfacewascreatedinthecontroldeskenvironment.Figure2: ControldeskScreenshot3. Frequencywasvariedfrm1Hzto49Hz(for20mssamplingcase)andthewholeprocesswasrepeatedfor1mssampling.4. DatawassavedandprocessedinMATLAB.3.2 Assignment21. PreviousmodelinsimulinkwasalteredandconvertedtoC-code.2. Frequency and amplitude was changed from the control desk interface and data was recordedbyusingthreedierentmethods-Simple,AutosaveandStream-to-disk.3. DatawassenttoMATLABandprocessed.4 ResultsandAnalysis4.1 Assignment11. Followingaretheplots showingthesampleddatafromboththemonitors alongwiththetheoriginal simulinksignal.Clearlyfromtheabovecurvewecanseetheeectof aliasing.Lower frequencies are properly represented whereas the higher frequencies pretend to be lowerfrequency. Something to notice is the behaviour for the frequency of 20-30 Hz. Although theirresolution is not great but if we closely look at them well nd that actually 30 Hz is immitatingthe20Hzcurve.3(a)1Hz (b)5Hz(c)20Hz (d)30Hz(e)45Hz (f)49HzFigure3: OriginalVsSampledDataSignal(BothMonitors)-20mssampling2. Wecanclearlyseefromthecurvesshownbelowthat49Hzcurveisexactlysameas1Hzcurve(in terms of frequence). Same goes for the 45 Hz curve(which is very close to 5 Hz curveintermsoffrequency). Aliasinginthecaseof30Hzistoughtoseeasthesampleddataisnotverymeaningful anddoestgiveaclearpicture. Thesendingsareprettyintuitiveand4goalongwiththeNyquistsamplingtheoremwhichsaysthatall frequencyaboveNyquestfrequencywill replicatethelowerfrequencies. Sinceoursamplingperiodforthiscaseis20ms,thusthesamplingfrequencyis50Hz.fNyquist=fsampling2Thusthenyquistfrequencyforthissystemis25Hz. Soallfrequenciesabovethiswillshowaliasingasshownbytheresultsbelow.(a)1Hzvs49Hz (b)5Hzvs45HzFigure4: Comparisonplots-20msFigure5: Comparisonplots(20ms)-20Hzvs30Hz3. Forthecasewhenthesamplingtimeis1ms(andthusthesamplingfrequencyis1000Hz),thenyquistfrequencyis500Hzandthuswedontseeanyaliasingasallthefrequenciesarebelow50Hz.5(a)1Hz (b)5Hz(c)20Hz (d)30Hz(e)45Hz (f)49HzFigure6: OriginalVsSampledDataSignal(BothMonitors)-1mssampling4. Following is shown the comparison plots between the lower and the higher frequencies. Clearlythere is no aliasing as the higherfrequency is not immitating the lower frequency. Reasoninghasbeenmadeinthepreviouspartbyshowingthatthenyquistfrequencyisveryhighascomparedtothefrequencyofthesignal.6(a)1Hzvs49Hz (b)5Hzvs45HzFigure7: Comparisonplots-1msFigure8: Comparisonplots(1ms)-20Hzvs30Hz4.2 Assignment2Belowareshowntheplots for thesinewaveacquiredbythreemethods of dataacquisition. Asfarasadvantagesanddisadvantagesarecocerned, thesimplemethodgivesusmorecontrol overtheprocess of edaytaacquisition. Wecanstoptheanimationat will andcapturethedataforanydesiredtimeperiod. Buttheprocessisnotautomated, asinif wewanttotakeconsecutivedatarecordingswehavetodoitmanuallyagainandagain. Thisdisadvantagecanbeovercomebytheautosavemethodwhere(iftheautonameoptionischecked)wecancansavethe.mat lesconsecutivelywithoutmanuallydoinganything. Thethirdoptionisgoodforsavingdatatoanypermanentmediabuthasadisadvantagethatithastobecovertedto.mat lebeforeitcanbeused.7Figure9: DataAcquisitionMethods85 ConclusionThis labmainlyhelpedtounderstandthe concept of aliasingandeect of samplingfrequecyonit. Apart fromthe eect of alliasing,various methods of dataacquisitionwas studiedandapplied. Advantages anddisadvantages associatedwiththemwas understoodandrmbaseindataacquisitionwasformed.6 Appendix%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ME 7292 Control System Labs% Data Acquisition and Aliasing% Week 3% Kirti Deo Mshra (# 98)%% This file processes the data acquired fromn dSPACE platform by% various methods and illustrates alliasing concepts%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%clcclose allclear all% Assignment 1% Case 1 Sampling is 20 ms% Alised vs originalfreqarray = [1 5 20 30 45 49]; % Array of frequenciestimearray = linspace(0,5,25100); % Array of time for simulink signaltimelimit = [5 1.5 0.5 0.2 0.15 0.5]; % Array of Time limits for better clarityfor i=1:length(freqarray)filename = [num2str(4) ' ' num2str(freqarray(i)) '.mat'];load (filename);% Creating sine signal and shifting it to meet the controller signalsimsine = 5*sin(2*pi*freqarray(i).*timearray + asin((dscapture.Y(1,2).Data(1))/5));figure('color', [1 1 1])plot(dscapture.X.Data, dscapture.Y(1,2).Data,...dscapture.X.Data,dscapture.Y(1,1).Data,...timearray, simsine, 'linewidth', 1.5)grid onxlabel('time(s)')xlim([0 , timelimit(i)])title(['Aliasing effect Original vs Alised signal(', num2str(freqarray(i)), ' Hz)'])legend('Monitor 1','Monitor 2(delayed)','Simulink Signal')end% Lower vs Higher frequencyfreqarray = [1 49 5 45 20 30]; % Array of frequenciestimelimit = [5 0 1.5 0 0.5];9for i = 1:2:length(freqarray)filename = [num2str(4) ' ' num2str(freqarray(i)) '.mat'];load (filename);figure('color', [1 1 1])plot(dscapture.X.Data, dscapture.Y(1,2).Data, 'r', 'linewidth', 1.5)hold onfilename = [num2str(4) ' ' num2str(freqarray(i+1)) '.mat'];load (filename);plot(dscapture.X.Data, dscapture.Y(1,2).Data,'b', 'linewidth', 1.5)grid onxlabel('Time(s)')legend([num2str(freqarray(i)) 'Hz'],[num2str(freqarray(i+1)) 'Hz'])title(['Frequency Comparison ' num2str(freqarray(i)) 'Hz vs' num2str(freqarray(i+1)) 'Hz'])xlim([0 , timelimit(i)])end% Case 2 Sampling is 1 msclcclear allclose all% Alised vs originalfreqarray = [1 5 20 30 45 49]; % Array of frequenciestimearray = linspace(0,5,50010); % Array of time for simulink signaltimelimit = [5 1.5 0.5 0.2 0.15 0.1]; % Array of Time limits for better clarityfor i=1:length(freqarray)filename = [num2str(4) 'a' num2str(freqarray(i)) '.mat'];load (filename);simsine = 5*sin(2*pi*freqarray(i).*timearray + asin((dscapture.Y(1,2).Data(1))/5));% Creating sine signal and shifting it to meet the controller signalfigure('color', [1 1 1])plot(dscapture.X.Data, dscapture.Y(1,2).Data,...dscapture.X.Data,dscapture.Y(1,1).Data,...timearray, simsine, 'linewidth', 1.5)grid onxlabel('time(s)')xlim([0 , timelimit(i)])title(['Aliasing effect Original vs Alised signal(', num2str(freqarray(i)), ' Hz)'])legend('Monitor 1','Monitor 2(delayed)','Simulink Signal')end% Lower vs Higher frequencyfreqarray = [1 49 5 45 20 30]; % Array of frequenciestimelimit = [1 0 0.5 0 0.2]; % Array to limit aaxis of the plotsfor i = 1:2:length(freqarray)10filename = [num2str(4) 'a' num2str(freqarray(i)) '.mat'];load (filename);figure('color', [1 1 1])plot(dscapture.X.Data, dscapture.Y(1,2).Data, 'r', 'linewidth', 1.5)hold onfilename = [num2str(4) 'a' num2str(freqarray(i+1)) '.mat'];load (filename);plot(dscapture.X.Data, dscapture.Y(1,2).Data,'b', 'linewidth', 1.5)grid onxlabel('Time(s)')legend([num2str(freqarray(i)) 'Hz'],[num2str(freqarray(i+1)) 'Hz'])title(['Frequency Comparison ' num2str(freqarray(i)) 'Hz vs' num2str(freqarray(i+1)) 'Hz'])xlim([0 , timelimit(i)])end% Assignment 2clcclear allclose allload ex21.mat % Simple Savefigure('color', [1 1 1])plot(ex21.X.Data, ex21.Y(1,1).Data,...ex21.X.Data, ex21.Y(1,2).Data, 'linewidth', 1.5)xlabel('Time(s)')xlim([0 0.035])grid onlegend('Delayed', 'Original')title('Simple Save Method')load ex22.mat % Autosavefigure('color', [1 1 1])plot(ex22.X.Data, ex22.Y(1,1).Data,...ex22.X.Data, ex22.Y(1,2).Data, 'linewidth', 1.5)xlabel('Time(s)')xlim([0 0.035])grid onlegend('Delayed', 'Original')title('Autosave Method')load ex23.mat % Stream to Diskfigure('color', [1 1 1])plot(ex23.X.Data, ex23.Y(1,1).Data,...ex23.X.Data, ex23.Y(1,2).Data, 'linewidth', 1.5)xlabel('Time(s)')xlim([0 0.035])grid onlegend('Delayed', 'Original')title('Stream To Disk Method')***********************11