An optical semiconductor device comprising: a waveguide that has one or more first segments, one or more second segments and a plurality of third segments, the first segment having a first grating region and a first space region extending from the first grating region, the first grating region including a first sampled diffractive grating having a plurality of diffracting elements and the first space region not having a diffractive grating, wherein the first segment has a length L1 defined as the length of the first grating region plus the length of the first space region, the second segment having a second grating region and a second space region extending from the second grating region, the second grating region including a second sampled diffractive grating having a plurality of diffracting elements and the second space region not having a diffractive grating, wherein the second segment has a length L2 defined as the length of the second grating region plus the length of the second space region, the length L2 of the second segment being different from that of the first segment, the third segment having a third grating region and a third space region extending from the third grating region, the third grating region including a third sampled diffractive grating having a plurality of diffracting elements and the third space region not having a diffractive grating, wherein the third segment has a length L3 defined as the length of the third grating region plus the length of the third space region; and a refractive index control portion (11a to 11d) configured to control a refractive index of the first, second and third segments (31 to 33); characterised in that the length of the third segment is L3 = L1 + (L2 - L1) X K1 in which 0.3 ≤ K1 ≤ 0.7. a waveguide that has one or more first segments, one or more second segments and a plurality of third segments, the first segment having a first grating region and a first space region extending from the first grating region, the first grating region including a first sampled diffractive grating having a plurality of diffracting elements and the first space region not having a diffractive grating, wherein the first segment has a length L1 defined as the length of the first grating region plus the length of the first space region, the second segment having a second grating region and a second space region extending from the second grating region, the second grating region including a second sampled diffractive grating having a plurality of diffracting elements and the second space region not having a diffractive grating, wherein the second segment has a length L2 defined as the length of the second grating region plus the length of the second space region, the length L2 of the second segment being different from that of the first segment, the third segment having a third grating region and a third space region extending from the third grating region, the third grating region including a third sampled diffractive grating having a plurality of diffracting elements and the third space region not having a diffractive grating, wherein the third segment has a length L3 defined as the length of the third grating region plus the length of the third space region; and a refractive index control portion (11a to 11d) configured to control a refractive index of the first, second and third segments (31 to 33); characterised in that the length of the third segment is L3 = L1 + (L2 - L1) X K1 in which 0.3 ≤ K1 ≤ 0.7.