Example #1
0
    def test_specgram_band_pass(self):
        time_points = 10000
        sampling_frequency = 100.0
        data = numpy.zeros((time_points,1))
        for time_index in range(time_points):
            data[time_index,0] = numpy.sin(2.0 * numpy.pi * 5.0 * (time_index / sampling_frequency))
            data[time_index,0] += numpy.sin(2.0 * numpy.pi * 15.0 * (time_index / sampling_frequency))
            data[time_index,0] += numpy.sin(2.0 * numpy.pi * 25.0 * (time_index / sampling_frequency))
            data[time_index,0] += numpy.sin(2.0 * numpy.pi * 35.0 * (time_index / sampling_frequency))
            data[time_index,0] += numpy.sin(2.0 * numpy.pi * 45.0 * (time_index / sampling_frequency))

        pass_band=(20.,30.)

        #Generate a time series build out of the data
        from pySPACE.resources.data_types.time_series import TimeSeries
        test_data = TimeSeries(input_array = data,
                               channel_names = ["test_channel_1"],
                               sampling_frequency = sampling_frequency,
                               start_time = 0,
                               end_time = float(time_points) / sampling_frequency)

        lpf_node = filtering.FFTBandPassFilterNode(pass_band=pass_band)
        filtered_time_series = lpf_node.execute(test_data)

        lpf_node_fir = filtering.FIRFilterNode(pass_band=pass_band)
        filtered_time_series_fir = lpf_node_fir.execute(test_data)

        lpf_node_fir2 = filtering.FIRFilterNode(pass_band=pass_band,window='hann')
        filtered_time_series_fir2 = lpf_node_fir2.execute(test_data)

        lpf_node_iir = filtering.IIRFilterNode(pass_band=pass_band,stop_band_rifle=90)
        filtered_time_series_iir = lpf_node_iir.execute(test_data)
Example #2
0
    def test_specgram_low_pass(self):
        time_points = 10000
        sampling_frequency = 100.0
        data = numpy.zeros((time_points, 1))
        for time_index in range(time_points):
            data[time_index, 0] = numpy.sin(2.0 * numpy.pi * 5.0 *
                                            (time_index / sampling_frequency))
            data[time_index, 0] += numpy.sin(2.0 * numpy.pi * 15.0 *
                                             (time_index / sampling_frequency))
            data[time_index, 0] += numpy.sin(2.0 * numpy.pi * 25.0 *
                                             (time_index / sampling_frequency))
            data[time_index, 0] += numpy.sin(2.0 * numpy.pi * 35.0 *
                                             (time_index / sampling_frequency))
            data[time_index, 0] += numpy.sin(2.0 * numpy.pi * 45.0 *
                                             (time_index / sampling_frequency))

        #Generate a time series build out of the data
        from pySPACE.resources.data_types.time_series import TimeSeries
        test_data = TimeSeries(input_array=data,
                               channel_names=["test_channel_1"],
                               sampling_frequency=sampling_frequency,
                               start_time=0,
                               end_time=float(time_points) /
                               sampling_frequency)

        lpf_node = filtering.SimpleLowPassFilterNode(cutoff_frequency=20.0)
        filtered_time_series = lpf_node.execute(test_data)

        lpf_node_fir = filtering.FIRFilterNode([20.0])
        filtered_time_series_fir = lpf_node_fir.execute(test_data)
Example #3
0
    def testTimeShifting(self):
        time_points = 10
        channels = 1
        import pySPACE.tests.utils.data.test_data_generation as tdg
        counter = tdg.Counter()
        test_data = test_ts_generator.generate_test_data(channels=channels,
                                                         time_points=time_points,
                                                         function=counter)

        filter_node = filtering.FIRFilterNode([10,20],time_shift="middle",taps=3)

        filter_node.initialize_data_dependencies(test_data)

        filter_node.filter_kernel = numpy.array([1,1,1])/3.

        filtered_data = filter_node.execute(test_data)

        # the result should be
        #[[ 0.33333333]
        # [ 1.        ]
        # [ 2.        ]
        # [ 3.        ]
        # [ 4.        ]
        # [ 5.        ]
        # [ 6.        ]
        # [ 8.        ]
        # [ 7.        ]
        # [ 5.66666667]]
        desired_result=numpy.array([1.0/3,1,2,3,4,5,6,7,8,17./3])
        desired_result.shape=(10,1)

        #print filtered_data
        #print desired_result
        self.assertTrue(numpy.allclose(filtered_data,desired_result))
Example #4
0
    def setUp(self):
        self.logger = logging.getLogger("TestLogger")

        self.pass_band = [10,20]

        self.filter_node = filtering.FIRFilterNode(self.pass_band)

        time_points = 1000
        channels = 10
        self.data = test_ts_generator.generate_test_data(channels,time_points,function=test_data_generation.Delta())
Example #5
0
 def create_filter(self,target_frequency,downsampling_factor,transition_region_width):
     
     skip = 0
     if self.skipping:
         skip = int(round(downsampling_factor-1))
             
     return filtering.FIRFilterNode([target_frequency], 
                                      comp_type=self.comp_type,
                                      width=transition_region_width,
                                      skip=skip,
                                      time_shift = self.time_shift)