0% found this document useful (0 votes)
51 views1 page

Try 1

This code performs several signal processing tasks including: 1) Generating rectangular pulse signals and plotting their time and frequency domain representations. 2) Calculating the Fourier transform of signals using numerical integration. 3) Convolving two signals and plotting the result. 4) Estimating the probability density function of random variables from histogram data and comparing to theoretical distributions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views1 page

Try 1

This code performs several signal processing tasks including: 1) Generating rectangular pulse signals and plotting their time and frequency domain representations. 2) Calculating the Fourier transform of signals using numerical integration. 3) Convolving two signals and plotting the result. 4) Estimating the probability density function of random variables from histogram data and comparing to theoretical distributions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Code 1 w = 10;

subplot(2,1,2);
plot(w,xw)
xcw2(i)=
trapz(t,xct2.*exp(-
close all; sigma=var(x)

clc; t = -10:0.01:10; %axis([-5 5 -5 10]); j*w(i).*t)); N=100000;


clear all;
close all;
t0 = 3; title('Fourier end x=rand(1,N); Code 4
xct = rectpuls(t-t0,w); Transform'); clc;
xlabel('w'); subplot(2,2,4); step=0.1; close all;
l = 10; subplot(2,1,1); ylabel('X(w)'); plot(w,xcw2) Range=-3:step:3;
t = -10:0.01:10; clear all;
plot(t,xct) axis([-5 5 -5 10]);
axis([-10 10 -1 2]); title('Fourier h=histc(x,Range); N=10000;
xct = rectpuls(t,l); title('Rectangular Transform'); pdf=h./(step.*sum(h)); x=randn(1,N);
Pulse'); xlabel('w');
subplot(2,2,1);
plot(t,xct)
xlabel('t'); Code 2(c) ylabel('X(w)'); %figure(1) nu=mean(x);
ylabel('x(t)'); clc; %bar(Range,h,'histc'); sigma2=var(x);
axis([-6 6 -1 2]); %histc is used to make
title('Rectangular clear all;
w = -8*pi:0.01:8*pi; close all; a function that divides step=0.1;
Pulse'); for i=1:length(w) %Taking Conv data into bins of size
xlabel('t'); range=-3:step:3;
xcw(i)= l = 10; xct3 = conv(xct1,xct2, equal
ylabel('x(t)'); trapz(t,xct.*exp(- 'same')*0.01; %to step size and gives
t = -10:0.01:10; h=histc(x,range);
j*w(i).*t)); figure(2); numbr of x values in
w = -8*pi:0.01:8*pi; end subplot(2,2,1); that bin
%First square pulse f=((1./sqrt(2*pi*sigma2
xct1 = rectpuls(t,l); plot(t,xct3); ).*exp((-((range-
for i=1:length(w) subplot(2,1,2); title('Conv');
xcw(i)= subplot(2,2,1); nu).^2))./(2.*sigma2)))
plot(w,xcw) plot(t,xct1) xlabel('t'); figure(2) );
trapz(t,xct.*exp(- axis([-5 5 -5 10]); ylabel('x(t)'); subplot(2,1,1);
j*w(i).*t)); axis([-6 6 -1 2]);
title('Fourier title('Rectangular plot(Range,pdf,'*','mar subplot(2,1,1);
end Transform'); w = -8*pi:0.01:8*pi; kersize',10);
Pulse'); plot(range,f,'b','linew
xlabel('w'); xlabel('t'); for i=1:length(w) idth',2);
subplot(2,2,2); ylabel('X(w)'); xcw3(i)=
plot(w,xcw) ylabel('x(t)'); hold('on');
trapz(t,xct3.*exp(- b=1;
axis([-5 5 -5 10]); j*w(i).*t)); a=0;
title('Fourier w = -8*pi:0.01:8*pi; simulated_pdf=
for i=1:length(w) end h./(step.*sum(h));
Transform'); N=size(h);
xlabel('w'); xcw1(i)= plot
trapz(t,xct1.*exp(- subplot(2,2,2); (range,simulated_pdf,'*
ylabel('X(w)');
Code 2 (b) j*w(i).*t)); plot(w,xcw3) N=N(1,2); ','markersize',15);
subplot(2,2,3); end hold on;
clc; title('Fourier hold on;
plot(w,abs(xcw)) Transform'); syms X;
clear all; subplot(2,2,2); grid on;
axis([-5 5 0 10]); xlabel('w'); f=rectangularPulse(a,b,
close all; plot(w,xcw1)
title('Magnitude ylabel('X(w)'); X);
Spectrum'); axis([-5 5 -5 10]); %axis([-3,3,0
w = 10; title('Fourier fplot(f); max(simulated_pdf)])
xlabel('w');
t = -10:0.01:10; Transform'); axis([-3 3 0 0.5]);
ylabel('|X(w)|'); cdff=zeros(1,N);
t0 = exp(j*10*t); xlabel('w');
xt = rectpuls(t,w).*t0; ylabel('X(w)'); multi = xcw1.*xcw2; cdff(1)=h(1)/sum(h); title('gaussian
subplot(2,2,4); subplot(2,2,4);
plot(w,angle(xcw)) distribution')
subplot(2,1,1); plot(w,multi) for i=2:N xlabel('range');
axis([-6 6 -4 4]); cdff(i)=cdff(i-
plot(t,xt) %Second square pulse ylabel('pdf');
title('Phase title('Fourier 1)+h(i)/sum(h);
axis([-6 6 -1 2]); xct2 = rectpuls(t,l); legend('theoratical','s
Spectrum'); Transform'); end
title('Rectangular imulation');
xlabel('w'); xlabel('w');
Pulse'); subplot(2,2,3);
ylabel('angle(X(w))'); ylabel('X(w)'); subplot(2,1,2)
xlabel('t'); plot(t,xct2) subplot(2,1,2);
ylabel('x(t)'); axis([-6 6 -1 2]); plot(Range,cdff,'*','ma
title('Rectangular rkersize',15) N=size(h);
w = -8*pi:0.01:8*pi; Pulse'); axis([-3 3 0 1.2]) N=N(1,2);
for i=1:length(w) xlabel('t');
Code 2(a) xw(i)= ylabel('x(t)'); hold on syms t z;

clc;
trapz(t,xt.*exp(-
j*w(i).*t));
Code 3 cdf=int(f,X,-3,X);
fplot(cdf);
p=(1./(sqrt(2*pi)))*int
w = -8*pi:0.01:8*pi; clc; ((exp(-(t*t/2))),t,-
clear all; end for i=1:length(w) 3,z);
close all; clear all; u=mean(x) fplot(p,'linewidth',2);

hold ('on'); xq = round(x*(2^(q- Delta = 2./(L-1); a=rand(1,N)>0.5; % Calculate the number


1))/A)*(A/(2^(q-1))); % Step size of the of valid code words N
simulatedcdf(1)=(h(1)/( quantization levels s=2*a-1; and the code rate RC
sum(h))); % Compute the SQNR = N = 2^k;
for i=2:N quantization error and zeros(length(L),1); % snr_dB=1:1:10; RC = k/n
the SQNR To store the Signal to n=1/sqrt(2).*randn(1,N)
simulatedcdf(i)=simulat e = x - xq; Quantization Noise ; % Generate all possible
edcdf(i-1) + sqnr(q) = Ratio (SQNR) for each combinations of k
h(i)/(sum(h)); 10*log10(var(x)/var(e)) quantization level for i = information bits
end; ; 1:length(snr_dB) information_bits =
end % Non-Uniform dec2bin(0:N-1)-'0'
plot(range,simulatedcdf Quantization y=10^(snr_dB(i)/20).*s+
,'*','markersize',10) % Plot the SQNR versus for i=1:length(L) n; % Apply the generator
axis([-3 3 0 quantization levels q = zeros(size(x)); a_dec=real(y)>0; matrix G to each
max(simulatedcdf)]) plot(1:Q, sqnr, 'o-') % Compute combination to get the
title('cdf of gaussian xlabel('Quantization quantization levels nErr(i)=size(find(a- corresponding n code
distribution') Levels') V = [-(L(i)-1)/2 : a_dec),2); bits
xlabel ('range'); ylabel('Signal-to- 1 : (L(i)-1)/2] * end code_words =
ylabel('cdf'); Quantization-Noise Delta(i); simBer = nErr/N; mod(information_bits*G,
legend('theoretical','s Ratio (dB)') % Quantize the theoryBer = 2);
imulated') title('Uniform signal 0.5*erfc(sqrt(10.^(snr_
Quantization SQNR vs. for j=1:N dB/10))); % Display the complete
Quantization Levels') [val, index] = code set C
min(abs(x(j)-V)); figure disp('Complete code set
q(j) = semilogy (snr_dB, C:');
Code 5 V(index); theoryBer, 'b-', disp(code_words);
%Write a matlab program Code 6 end
% Compute the SQNR
'LineWidth', 1.5);
hold on
to compute the Signal % Program to Compute noise = x - q; semilogy (snr_dB,
to quantization Noise SNR of Non-Uniform
ratio of Uniform Quantization and Plot
signal_power =
sum(x.^2)/N;
simBer, 'x',
'MarkerSize', 8); Code 8(b)
Quantization. Plot SNQR the SNR vs. noise_power = grid on clear all;
versus Quantization Quantization Levels sum(noise.^2)/N; legend('theory', clc;
levels SQNR(i) = 'simulation'); close all;
clear all; 10*log10(signal_power/n xlabel('snr_db -->');
% Set the parameters close all; oise_power); ylabel('bit error rate- G = [1 1 0 0 1 0 1;
N = 1000; % number of clc; end ->'); 0 1 1 1 1 0 0;
samples title('bit error 1 1 1 0 0 1 1];
fs = 1000; % sampling % Signal Parameters % Plot the SNR vs. probability curve for
frequency (Hz) N = 10000; Quantization Levels bpsk modulation'); G (3, :) = mod (G (3,
f = 10; % signal % Number of samples in figure; :) +G (1, :) , 2) ;
frequency (Hz) the signal plot(b, SQNR, 'b-o', G (2, :) = mod (G (2,
A = 1; % signal f = 1; 'LineWidth', 2); :) +G (3, :), 2) ;
amplitude % Signal frequency xlabel('Number of G (1, :) = mod (G (1,
Q = 10; % maximum Fs = 1000; Bits');
Code 8(a) :) +G (2, :) , 2) ;
quantization level % Sampling frequency ylabel('Signal to clc;
t = (0:N-1)/Fs; Quantization Noise clear all; G
% Generate the signal % Time vector Ratio (dB)'); close all;
t = (0:N-1)'/fs; % time x = sin(2*pi*f*t); grid on;
vector % Signal % Define the generator
x = A*sin(2*pi*f*t); % matrix G
sinusoidal signal % Quantization G = [1 1 0 0 1 0 1;
Parameters 0 1 1 1 1 0 0;
% Compute the SQNR for L = 2:20; Code 7 1 1 1 0 0 1 1];
each quantization level % Number of clc;
sqnr = zeros(Q, 1); quantization levels to clear all; % Calculate the number
for q = 1:Q try close all; of information bits k
% Quantize the b = log2(L); and code bits n
signal % Number of bits to N = 10^6; [k, n] = size(G);
represent each level

You might also like