I have the following exercise from the university:
The bit sequence [1 1 0 1 1 1 0 0] with data rate DR = 50 bps is given. This bit sequence modulates the amplitude of a carrier signal with frequency FC = 1000 Hz. During the transmission, white noise with deviation sigma = 0.5 is added to the modulated signal. The signal is demodulated in the receiver and filtered with a low-pass filter with cut-off frequency FG = FC. Plot the demodulated and filtered reception signal and compare it with the transmission signal. No built-in functions are allowed, except the discussed in the lecture!
So far I am able to generate the noise using the following code:
t = linspace(0,0.1,1001);
sigma = 0.5;
avg = 0;
noise = sigma * randn(size(t))+avg;
plot(t,noise)
I did something like that in the previous exercise but with some differences. I had squarewave, to which I have added a noise, then I filtered the result with a low-pass filter (not the build-in function) and compared the default squarewave with the one, to which I have added the noise and filtered it (the result). The code for that is below.
pkg load signal;
t = linspace(0,0.1,1001);
y = square(2*pi*50*t)*0.5 + 0.5;
mw = 0;
sigma = 0.5;
rauschen = sigma*randn(size(t))+mw;
yr = y + rauschen;
Y = fft(y);
Yr = fft(yr);
f = linspace(0,1/t(2),length(t));
plot(f,abs(Y),f,abs(Yr))
fg = 400;
Yru = Yr;
Yru(find(f>fg || f<1/t(2)-fg)) = 0;
find(f==fg)
ans = 41
Yru(41:end-41)=0;
plot(f,abs(Yru))
yru = ifft(Yru);
plot(t,real(yru));
The picture below shows the result of the previous exercise.
My main problem is that I am not able to generate the required carrierwave/signal..
Thanks to this article I think that I've figured it out. Here's the code and the result is shown on the picture below.
pkg load signal;
bits = [ 1 1 0 1 1 1 0 0 ];
bitrate = 50;
n = 1000;
T = length(bits)/bitrate;
N = n*length(bits);
dt = T/N;
t = 0:dt:T;
x = zeros(1,length(t));
lastbit = 1;
for i=1:length(bits)
if bits(i)==1
x((i-1)*n+1:i*n) = -lastbit;
lastbit = -lastbit;
else x((i-1)*n+1:i*n) = lastbit;
end
end
x = (x + 1)*0.5;
plot(t, x, 'Linewidth', 3);
figure;
sigma = 0.5;
rauschen = sigma * randn(size(t));
plot(t,rauschen)
figure;
xr = x + rauschen;
plot(t,xr)
figure;
Xr = fft(xr);
f = linspace(0,1/t(2),length(t));
fc = n;
Xru = Xr;
Xru(find(f==fc)) = 0;
plot(f,abs(Xru));
figure;
ans = find(f==fc);
ans
Xru(ans:end-ans)=0;
plot(f,abs(Xru));
figure;
xru = ifft(Xru);
plot(t,real(xru));
hold
plot(t,x)
#axis([0 t(end) -0.5 1.5])