필터 지우기
필터 지우기

help me write the code

조회 수: 3 (최근 30일)
lloyd mukunza
lloyd mukunza 2013년 10월 2일
답변: Nyein 2023년 10월 4일
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
Grace  Rotich
Grace Rotich 2022년 11월 8일
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 2022년 11월 8일
@Grace Rotich Why are you telling @lloyd mukunza this? It looks like your homework problem, not a reply to Lloyd.

댓글을 달려면 로그인하십시오.

답변 (4개)

Jos (10584)
Jos (10584) 2013년 10월 2일
No ;-)

Image Analyst
Image Analyst 2013년 10월 2일

Udai Wasmi
Udai Wasmi 2019년 3월 2일
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 2023년 10월 4일
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!

Translated by