Chinmaye
Full Member level 3
Dear all,
I am trying to write a matlab code for first order and second order modulator. The SNR of first order modulator is greater than that of 2nd order modulator for OSR 20,80. But it works fine for OSR 40,160. Here is the code. Can someone point out what is wrong?
I am trying to write a matlab code for first order and second order modulator. The SNR of first order modulator is greater than that of 2nd order modulator for OSR 20,80. But it works fine for OSR 40,160. Here is the code. Can someone point out what is wrong?
Code:
First order sigma delta
clc;
clear all;
close all;
a=5;
Fs = 2048;
dt = 1/Fs;
t = 0:dt:1-dt;
x = 2*(sin(2*pi*50.5*t));
%x = 3*(1+ 0*t)
l = length(x);
u(1) = 0.1
figure;
subplot(211);
plot(x,'r');
for i = 1:l
if(u(i)> 0)
y(i) = 2;
else
y(i) = -2;
end
e(i) = x(i) - y(i);
u(i+1)= u(i) + e(i);
end
subplot(212);
stairs(y,'b')
x2 = y.*kaiser(length(y),13)'
figure
plot(x2)
X1 = db(abs(fft(x)));
Y1 = db(abs(fft(x2)));
X2 = fft(x2)
%figure
%plot(X1, 'r')
figure
plot(Y1, 'b')
signal_value = (sum(X2(48:54).*conj(X2(48:54))));
noise_bins = [X2(2:47)];
noise = (sum(noise_bins.*conj(noise_bins)));
snrfftwin = 10*log10(signal_value/noise)
Code:
Second order sigma delta
clc;
clear all;
close all;
a=5;
Fs = 2048;
dt = 1/Fs;
t = 0:dt:1-dt;
x = 2*(sin(2*pi*50.5*t));
%x = 1.2*(1+ 0*t)
l = length(x);
u(1) = 0
e2(1)=0
y(1) = -2
figure;
subplot(211);
plot(x,'r');
for i = 1:l-1
e1(i+1) = x(i) - y(i);
e2(i+1) = e2(i)+ e1(i+1);
e3(i+1) = e2(i+1) -y(i)
u(i+1)= u(i) + e3(i+1);
if(u(i+1)< 0)
y(i+1) = -2;
else
y(i+1) = 2;
end
end
subplot(212);
stairs(y,'b')
x2 = y.*kaiser(length(y),13)'
figure
plot(x2)
X1 = db(abs(fft(x)));
Y1 = db(abs(fft(x2)));
X2 = fft(x2)
figure
plot(X1, 'r')
figure
plot(Y1, 'b')
signal_value = (sum(X2(48:54).*conj(X2(48:54))));
noise_bins = [X2(2:47)];
noise = (sum(noise_bins.*conj(noise_bins)));
snrfftwin = 10*log10(signal_value/noise)