help me write the code

18 views (last 30 days)
lloyd mukunza
lloyd mukunza on 2 Oct 2013
Answered: Nyein on 4 Oct 2023
Given a sinusoidal waveform with frequency of 100Hz x(t)=4.5sin(2π×100t)), sampled at 8 kHz, Write a MATLAB program to quantize the x(t) using 4-bits to obtain and plot the quantized signal x_q, assuming that the signal range is from -5 to 5 volts Calculate the SNR due to quantization using the MATLAB program
  2 Comments
Grace  Rotich
Grace Rotich on 8 Nov 2022
The function below performs signal quantization decoding. Here X-min will be -5 and X-max will be +5. The function is named decodingquant and is added to the path of the software. It will be called in the main program. The bits will be 6 bits since we are using a 6 bit bipolar quantizer.
function deout = decodingquant(bits,Xmin,Xmax,I) le=2*bits; delta=(Xmax-Xmin)/le; deout=Xmin+I*delta; %the following function performs signal quantization decoding.
This is a code for a function named quantization that performs signal quantization:
function [I, out] = quantization(bits,Xmin,Xmax, value)
le=2*bits;
delta=(Xmax-Xmin)/le;
I=round((value-Xmin)/delta);
if I==le
I=I-1;
end
if I<0
I=0;
end
out=Xmin+I*delta;
The main program: This is where we will call our functions: quantization decodingquant We also initialize and write the code. This program quantizes the signal using 6-bits bipolar quantizer to obtain the to obtain the quantized signal x_q and plots the original and quantized signal.
clc clear close all Tm=1/50; %Time period of the signal fs=8000; %This is the samplig frequency T=1/fs; %The sampling time period t=0:T:2*Tm; %This the the two period-time array. signal=3.25*sin(2*pi*50*t)+1.25*cos(2*pi*100*t+pi/4); bits=6; %6 bit quantizer as asked in the question. l=length(signal); %After initializing everything, we carry out quantization Index=zeros; quadsignal=zeros; for x=1:l [Index(x), qout]=quantization(bits,-5,5,signal(x)); end % we call the function inprder to recover signal from quantized values. % also indicate the signal range:from -5 to 5. for x=1:l quadsignal(x)=decodingquant(bits,-5,5,Index(x)); end plot(t,signal,'b') hold on stairs(t,quadsignal,'r'); ylabel('Signal') % xlabel('time (s)') legend('Original ','Quantized ') %Inorder to plot original signal and quantised signal. hold off
(b) Plot the signal and quantized signal.
Image Analyst
Image Analyst on 8 Nov 2022
@Grace Rotich Why are you telling @lloyd mukunza this? It looks like your homework problem, not a reply to Lloyd.

Sign in to comment.

Answers (4)

Jos (10584)
Jos (10584) on 2 Oct 2013
No ;-)

Image Analyst
Image Analyst on 2 Oct 2013

Udai Wasmi
Udai Wasmi on 2 Mar 2019
Given a sinusoidal waveform with a frequency of 100 Hz ( ) ( ) sampled at
8kHz.
a- Write a MATLAB program to quantizer
( ) using 4 bits to obtain and plot the
quantized signal , assuming the signal range is between -5 and 5 volts;
b- Calculate the SNR due to quantization

Nyein
Nyein on 4 Oct 2023
frequency is 100 Hz , x(t) =4.5 sin(2pi*100t) sampled at 8000Hz, Write a Matlab program to quantized x(t) using 4 bits to obtain and plot the quantized singnal xq , assuming the signal range is between -5 and 5 volts.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!