📄 spectrademoapp.vb
字号:
' *******************************************************************************'' SpectraDemoApp.vb'' This file is an example application for the MATLAB Builder for .NET product.'' Copyright 2001-2005 The MathWorks, Inc.'' *******************************************************************************Imports SystemImports MathWorks.MATLAB.NET.UtilityImports MathWorks.MATLAB.NET.ArraysImports SpectraDemoCompNamespace MathWorks.Demo.SpectraDemoApp' <summary>' This application computes and plots the power spectral density of an input signal. ' </summary>Class SpectraDemoApp#Region " MAIN " ' <summary> ' The main entry point for the application. ' </summary> Shared Sub Main(ByVal args() As String) Try Const interval As Double = 0.01 ' The sampling interval Const numSamples As Integer = 1001 ' The number of samples ' Construct input data as sin(2*PI*15*t) + (sin(2*PI*40*t) plus a ' random signal. Duration= 10; Sampling interval= 0.01 Dim data As MWNumericArray = New MWNumericArray(MWArrayComplexity.Real, MWNumericType.Double, numSamples) Dim random As Random = New Random ' Initialize data Dim t As Double Dim idx As Integer For idx = 1 To numSamples t = (idx - 1) * interval data(idx) = New MWNumericArray(Math.Sin(2.0 * Math.PI * 15.0 * t) + Math.Sin(2.0 * Math.PI * 40.0 * t) + random.NextDouble()) Next idx ' Create a new signal analyzer object Dim signalAnalyzer As SignalAnalyzer = New SignalAnalyzer ' Compute the fft and power spectral density for the data array Dim argsOut() As MWArray = signalAnalyzer.computefft(3, data, MWArray.op_Implicit(interval)) ' Print the first twenty elements of each result array Dim numElements As Integer = 20 Dim resultArray As MWNumericArray = New MWNumericArray(MWArrayComplexity.Complex, MWNumericType.Double, numElements) For idx = 1 To numElements resultArray(idx) = (CType(argsOut(0), MWNumericArray))(idx) Next idx Console.WriteLine("FFT:{0}{1}{2}", Chr(10), resultArray, Chr(10)) For idx = 1 To numElements resultArray(idx) = (CType(argsOut(1), MWNumericArray))(idx) Next idx Console.WriteLine("Frequency:{0}{1}{2}", Chr(10), resultArray, Chr(10)) For idx = 1 To numElements resultArray(idx) = (CType(argsOut(2), MWNumericArray))(idx) Next idx Console.WriteLine("Power Spectral Density:{0}{1}{2}", Chr(10), resultArray, Chr(10)) ' Create a new plotter object Dim plotter As Plotter = New Plotter ' Plot the fft and power spectral density for the data array plotter.plotfft(argsOut(0), argsOut(1), argsOut(2)) Console.ReadLine() ' Wait for user to exit application Catch exception As Exception Console.WriteLine("Error: {0}", exception) End Try End Sub#End Region End ClassEnd Namespace
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -