HTBasic Help
×
Menu
Index

Example: Frequency Response

 
10     ! *********************************************************************
20     ! Example: Frequency Response
30     !
40     ! This program generates a theoretical frequency response
50     ! display (response in dB vs. frequency in Hz) for two channels.
60     !
70     ! ************************************************************
80     !
90     REAL Freq(1:31),Channel_1(1:31),Channel_2(1:31)
100   !
110   ! Define test frequencies.
120   !
130   DATA 20,25,32,40,50,63,80,100,125,160
140   DATA 200,250,320,400,500,630,800,1000,1250,1600
150   DATA 2000,2500,3200,4000,5000,6300,8000,e,12500,16000,20000
160   READ Freq(*)
170   !
180   ! Take voltage measurements for both channels, convert to dB.
190   !
200   FOR I=1 TO 31
210     Channel_1(I)=20*LGT(FNMeasure(Freq(I),1))
220     Channel_2(I)=20*LGT(FNMeasure(Freq(I),2))
230   NEXT I
240   !
250   ! Create and set up the graph
260   !
270   ASSIGN @Graph TO WIDGET "XY GRAPH";SET ("SHARED X":1,"VISIBLE":0,"TITLE":" Example: Frequency Response","WIDTH":400,"HEIGHT":300)
280   CONTROL @Graph;SET ("SYSTEM MENU":"Quit")
290   ON EVENT @Graph,"SYSTEM MENU" GOTO Finis
300   !
310   ! Set X axis attributes
320   !
330   CONTROL @Graph;SET ("CURRENT AXIS":"X","AUTOSCALE":1,"LOGARITHMIC":1,"AXIS LABEL":"Frequency (Hz)")
340   !
350   ! Set Y axis attributes
360   !
370   CONTROL @Graph;SET ("CURRENT AXIS":"Y","AUTOSCALE":1,"AXIS LABEL":"Response (dB)")
380   !
390   ! Enter the data into the graph
400   !
410   CONTROL @Graph;SET ("X DATA":Freq(*))
420   CONTROL @Graph;SET ("CURRENT TRACE":1,"Y DATA":Channel_1(*),"TRACE LABEL":"Channel 1")
430   CONTROL @Graph;SET ("CURRENT TRACE":2,"Y DATA":Channel_2(*),"TRACE LABEL":"Channel 2")
440   !
450   ! Display the graph
460   !
470   CONTROL @Graph;SET ("VISIBLE":1)
480   LOOP
490     WAIT FOR EVENT
500   END LOOP
510 Finis: END
520   !
530   ! This function simulates some data for the use of this program
540   !
550   DEF FNMeasure(Freq,Chan)
560   !
570   ! Simulate measured data for second order lowpass filters
580   !
590     F=Freq*(.8+Chan/5)
600     RETURN 1/(1-F/(3000-Chan*400)+(F/3000)^2)
610   FNEND