Skip to content

Commit

Permalink
Merge pull request #8 from hybridmachine/FFT_Filters
Browse files Browse the repository at this point in the history
Fft filters
  • Loading branch information
hybridmachine authored Nov 30, 2019
2 parents 9045a64 + 0797156 commit dfef2c1
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 26 deletions.
3 changes: 3 additions & 0 deletions Signals And Transforms/Installer/Installer.wixproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,7 @@
<Error Condition="!Exists('..\packages\Microsoft.NetFramework.Analyzers.2.9.7\build\Microsoft.NetFramework.Analyzers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.NetFramework.Analyzers.2.9.7\build\Microsoft.NetFramework.Analyzers.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.CodeAnalysis.FxCopAnalyzers.2.9.7\build\Microsoft.CodeAnalysis.FxCopAnalyzers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeAnalysis.FxCopAnalyzers.2.9.7\build\Microsoft.CodeAnalysis.FxCopAnalyzers.props'))" />
</Target>
<PropertyGroup>
<PostBuildEvent>"c:\Program Files (x86)\Microsoft SDKs\ClickOnce\SignTool\signtool" sign /sha1 "4380105fab106823f712f185d0c3f9d6d9f6df55" /t http://timestamp.verisign.com/scripts/timstamp.dll /v $(TargetFileName)</PostBuildEvent>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion Signals And Transforms/Installer/Product.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />

<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<MediaTemplate />
<MediaTemplate EmbedCab="yes" />

<Feature Id="ProductFeature" Title="Product" Level="1">
<ComponentGroupRef Id="ProductComponents" />
Expand Down
18 changes: 18 additions & 0 deletions Signals And Transforms/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Signals And Transforms/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@
<data name="OPEN" xml:space="preserve">
<value>Open</value>
</data>
<data name="PLOT_FREQUENCY_HISTOGRAM_BOTTOM_AXIS" xml:space="preserve">
<value>Frequency</value>
</data>
<data name="PLOT_FREQUENCY_HISTOGRAM_LEFT_AXIS" xml:space="preserve">
<value>Amplitude</value>
</data>
<data name="PLOT_FREQUENCY_HISTOGRAM_TITLE" xml:space="preserve">
<value>Frequency Amplitudes</value>
</data>
Expand Down
1 change: 1 addition & 0 deletions Signals And Transforms/SignalsAndTransforms.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
<Compile Include="Models\Signal.cs" />
<Compile Include="Models\WorkBook.cs" />
<Compile Include="View Models\ConvolutionViewModel.cs" />
<Compile Include="View Models\FrequencyHistogramViewModel.cs" />
<Compile Include="View Models\MainWindowViewModel.cs" />
<Compile Include="View Models\SignalGeneratorViewModel.cs" />
<Compile Include="Views\ConvolutionView.xaml.cs">
Expand Down
10 changes: 3 additions & 7 deletions Signals And Transforms/View Models/ConvolutionViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private void LoadTestData()

public IList<DataPoint> ResultPlotPoints { get; private set; }

public IList<DataPoint> ResultFrequencyHistogram { get; private set; }
public FrequencyHistogramViewModel ResultFrequencyHistogram { get; private set; }


public void PlotData()
Expand Down Expand Up @@ -137,12 +137,8 @@ public void PlotData()

ComplexFastFourierTransform cmplxFFT = new ComplexFastFourierTransform();
FrequencyDomain frequencyDomain = cmplxFFT.Transform(convolutionResult, workbookSourceSignal.SamplingHZ);
ResultFrequencyHistogram = new List<DataPoint>(frequencyDomain.FrequencyAmplitudes.Count);
foreach (var freq in frequencyDomain.FrequencyAmplitudes)
{
ResultFrequencyHistogram.Add(new DataPoint(freq.Key, freq.Value));
}

ResultFrequencyHistogram = new FrequencyHistogramViewModel(frequencyDomain);

NotifyPropertyChanged(nameof(SignalPlotPoints));
NotifyPropertyChanged(nameof(ConvolutionPlotPoints));
NotifyPropertyChanged(nameof(ResultPlotPoints));
Expand Down
43 changes: 43 additions & 0 deletions Signals And Transforms/View Models/FrequencyHistogramViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using SignalProcessor;
using System;
using OxyPlot;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OxyPlot.Axes;
using OxyPlot.Series;

namespace SignalsAndTransforms.View_Models
{
public class FrequencyHistogramViewModel : PlotModel
{
public FrequencyHistogramViewModel(FrequencyDomain frequencyDomain)
{
Title = Properties.Resources.PLOT_FREQUENCY_HISTOGRAM_TITLE;
Axes.Add(new LinearAxis { Position = AxisPosition.Left, Title = Properties.Resources.PLOT_FREQUENCY_HISTOGRAM_LEFT_AXIS });
Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Title = Properties.Resources.PLOT_FREQUENCY_HISTOGRAM_BOTTOM_AXIS });

if (frequencyDomain != null)
{
HistogramSeries chs = new HistogramSeries();
chs.Items.AddRange(GetFrequencyBins(frequencyDomain));
Series.Add(chs);
}
}

private IList<HistogramItem> GetFrequencyBins(FrequencyDomain frequencyDomain)
{
int binCount = (int)Math.Ceiling(frequencyDomain.SampleRateHz / 2);
List<HistogramItem> histogramItems = new List<HistogramItem>(binCount);

foreach (var amplitude in frequencyDomain.FrequencyAmplitudes)
{
HistogramItem item = new HistogramItem(amplitude.Key - 0.25, amplitude.Key + 0.25, amplitude.Value, 1);
histogramItems.Add(item);
}

return histogramItems;
}
}
}
13 changes: 5 additions & 8 deletions Signals And Transforms/View Models/SignalGeneratorViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private void LoadSignalsFromActiveWorkBook()
}

public IList<DataPoint> PlotPoints { get; private set; }
public IList<DataPoint> FrequencyHistogram { get; private set; }
public PlotModel FrequencyViewModel { get; private set; }

public String Title { get; private set; }

Expand All @@ -67,8 +67,7 @@ private void ActiveWorkBookChangedHandler(object sender, PropertyChangedEventArg
public void PlotSignals()
{
PlotPoints = new List<DataPoint>(512);
FrequencyHistogram = new List<DataPoint>(512);


Signal workbookSourceSignal = workBookManager.ActiveWorkBook().SumOfSources();
if (workbookSourceSignal == null)
{
Expand All @@ -84,13 +83,11 @@ public void PlotSignals()
ComplexFastFourierTransform cmplxFFT = new ComplexFastFourierTransform();
FrequencyDomain frequencyDomain = cmplxFFT.Transform(workbookSourceSignal.Samples, workbookSourceSignal.SamplingHZ);

foreach (var freq in frequencyDomain.FrequencyAmplitudes)
{
FrequencyHistogram.Add(new DataPoint(freq.Key, freq.Value));
}

FrequencyViewModel = new FrequencyHistogramViewModel(frequencyDomain);

NotifyPropertyChanged(nameof(PlotPoints));
NotifyPropertyChanged(nameof(FrequencyHistogram));
NotifyPropertyChanged(nameof(FrequencyViewModel));
}

private void NotifyPropertyChanged(string propertyName)
Expand Down
6 changes: 1 addition & 5 deletions Signals And Transforms/Views/ConvolutionView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@
MarkerType="Square"/>
</oxy:Plot.Series>
</oxy:Plot>
<oxy:Plot Grid.Column="0" Grid.Row="2" Grid.ColumnSpan="2" Margin="5" Title="{x:Static res:Resources.PLOT_FREQUENCY_HISTOGRAM_TITLE}">
<oxy:Plot.Series>
<oxy:LineSeries ItemsSource="{Binding ResultFrequencyHistogram}"/>
</oxy:Plot.Series>
</oxy:Plot>
<oxy:PlotView Grid.Column="0" Grid.Row="2" Grid.ColumnSpan="2" Margin="5" Model="{Binding ResultFrequencyHistogram}"/>
</Grid>
</UserControl>
6 changes: 1 addition & 5 deletions Signals And Transforms/Views/SignalGeneratorView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@
MarkerType="Square"/>
</oxy:Plot.Series>
</oxy:Plot>
<oxy:Plot Grid.Column="3" Grid.Row="0" Grid.RowSpan="4" Margin="5" Title="{x:Static res:Resources.PLOT_FREQUENCY_HISTOGRAM_TITLE}">
<oxy:Plot.Series>
<oxy:LineSeries ItemsSource="{Binding FrequencyHistogram}"/>
</oxy:Plot.Series>
</oxy:Plot>
<oxy:PlotView Grid.Column="3" Grid.Row="0" Grid.RowSpan="4" Margin="5" Model="{Binding FrequencyViewModel}"/>
</Grid>
</UserControl>

0 comments on commit dfef2c1

Please sign in to comment.