OpenCores
URL https://opencores.org/ocsvn/turbocodes/turbocodes/trunk

Subversion Repositories turbocodes

[/] [turbocodes/] [trunk/] [src/] [myhdl/] [noiser.py] - Blame information for rev 7

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 7 dbrochart
######################################################################
2
####                                                              ####
3
####  noiser.py                                                   ####
4
####                                                              ####
5
####  This file is part of the turbo decoder IP core project      ####
6
####  http://www.opencores.org/projects/turbocodes/               ####
7
####                                                              ####
8
####  Author(s):                                                  ####
9
####      - David Brochart(dbrochart@opencores.org)               ####
10
####                                                              ####
11
####  All additional information is available in the README.txt   ####
12
####  file.                                                       ####
13
####                                                              ####
14
######################################################################
15
####                                                              ####
16
#### Copyright (C) 2005 Authors                                   ####
17
####                                                              ####
18
#### This source file may be used and distributed without         ####
19
#### restriction provided that this copyright statement is not    ####
20
#### removed from the file and that any derivative work contains  ####
21
#### the original copyright notice and the associated disclaimer. ####
22
####                                                              ####
23
#### This source file is free software; you can redistribute it   ####
24
#### and/or modify it under the terms of the GNU Lesser General   ####
25
#### Public License as published by the Free Software Foundation; ####
26
#### either version 2.1 of the License, or (at your option) any   ####
27
#### later version.                                               ####
28
####                                                              ####
29
#### This source is distributed in the hope that it will be       ####
30
#### useful, but WITHOUT ANY WARRANTY; without even the implied   ####
31
#### warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ####
32
#### PURPOSE. See the GNU Lesser General Public License for more  ####
33
#### details.                                                     ####
34
####                                                              ####
35
#### You should have received a copy of the GNU Lesser General    ####
36
#### Public License along with this source; if not, download it   ####
37
#### from http://www.opencores.org/lgpl.shtml                     ####
38
####                                                              ####
39
######################################################################
40
 
41
 
42
 
43
from random import gauss
44
from myhdl import Signal, posedge, negedge, always
45
 
46
def noiser(clk, rst, a, b, y1, y2, y1Int, y2Int, aNoisy, bNoisy, y1Noisy, y2Noisy, y1IntNoisy, y2IntNoisy, n = 4 , mu = 2**(4 - 1), sigma = 2**(4 - 2) + 2**(4 - 3)):
47
    """ Signal noiser (Gauss distribution).
48
 
49
    n           -- number of bits for the coding of the noisy signals (= for the sampling of the received data)
50
    mu          -- mean value for the distribution
51
    sigma       -- standard deviation for the distribution (0 means no noise)
52
    clk, rst    -- in  : clock and negative reset
53
    a, b, y1, y2, y1Int, y2Int  -- in  : original coder signals, coded with 1 bit
54
    aNoisy, bNoisy, y1Noisy, y2Noisy, y1IntNoisy, y2IntNoisy    -- out : noisy signals, coded with n bits and delayed by 1 clock cycle
55
 
56
    """
57
    #mu = 2**(n - 1) #8
58
    #sigma = 2**(n - 2) + 2**(n - 3) #6
59
#    cnt = Signal(int(0))
60
    @always(clk.posedge, rst.negedge)
61
    def noiserLogic():
62
        if rst.val == 0:
63
            aNoisy.next  = 0
64
            bNoisy.next  = 0
65
            y1Noisy.next = 0
66
            y2Noisy.next = 0
67
#            cnt.next = 0
68
        else:
69
#            if cnt.val < 10:
70
#                cnt.next = cnt.next + 1
71
#                aNoisy.next = ((a.val * 2) - 1) * 7
72
#                bNoisy.next = ((b.val * 2) - 1) * 7
73
#                y1Noisy.next = ((y1.val * 2) - 1) * 7
74
#                y2Noisy.next = ((y2.val * 2) - 1) * 7
75
#                y1IntNoisy.next = ((y1Int.val * 2) - 1) * 7
76
#                y2IntNoisy.next = ((y2Int.val * 2) - 1) * 7
77
#            else:
78
#                cnt.next = 0
79
#                aNoisy.next = 7
80
#                bNoisy.next = 7
81
#                y1Noisy.next = 7
82
#                y2Noisy.next = 7
83
#                y1IntNoisy.next = 7
84
#                y2IntNoisy.next = 7
85
            if a.val == 0:
86
                aNoisy.next  = int(round(gauss(-mu + 1, sigma)))
87
            else:
88
                aNoisy.next  = int(round(gauss(mu - 1, sigma)))
89
            if b.val == 0:
90
                bNoisy.next  = int(round(gauss(-mu + 1, sigma)))
91
            else:
92
                bNoisy.next  = int(round(gauss(mu - 1, sigma)))
93
            if y1.val == 0:
94
                y1Noisy.next = int(round(gauss(-mu + 1, sigma)))
95
            else:
96
                y1Noisy.next = int(round(gauss(mu - 1, sigma)))
97
            if y2.val == 0:
98
                y2Noisy.next = int(round(gauss(-mu + 1, sigma)))
99
            else:
100
                y2Noisy.next = int(round(gauss(mu - 1, sigma)))
101
            if y1Int.val == 0:
102
                y1IntNoisy.next = int(round(gauss(-mu + 1, sigma)))
103
            else:
104
                y1IntNoisy.next = int(round(gauss(mu - 1, sigma)))
105
            if y2Int.val == 0:
106
                y2IntNoisy.next = int(round(gauss(-mu + 1, sigma)))
107
            else:
108
                y2IntNoisy.next = int(round(gauss(mu - 1, sigma)))
109
    return noiserLogic

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.