Generate a 4-Hz, 1000-point sine wave with a sample interval of T=0.002, and use quantiziation to digitize it using a 4-,8-,12-, and 16-bit ADC...
27 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi, I'm having some issues debugging the for-loop involved with this problem and getting the output results I need. The problem is written below:
Generate a 4-Hz, 1000-point sine wave with a sample interval of T=0.002, and
use quantization to digitize it using a 4-,8-,12-, and 16-bit ADC. Then
subtract the original signal from the quantized signal to find the error
signal. The amplitude of the error signal should be equal to the quantization
level, q. Use the "max" and "min" functions in MATLAB to find this amplitude
and compare it with the theoretical value. Put this code in a for-loop and
repeat the evaluations for the four different bit levels requested.
Be sure to display the results to at least 4 decimal places to make an
accurate comparison.
I think for the most part I'm just not processing my for-loop correctly, and I'm not sure what I may need to modify in that for-loop to get it working correctly to provide me the outputs I'm looking for.
Should I try putting the disp(out) formatting outside of the for-loop too? Also, if I were to plot this sine wave - what command lines would I need to add to the m-file program to get the plot shown?
I'm assuming I would use the 'plot()' command somehow. But what if I wanted 4 different plots? One for each level of digitization I use in this problem (4, 8, 12, and 16) to represent the 4-bit, 8-bit, 12-bit, and 16-bit ADC digitization.
If anyone can provide me help with solving this problem, and send me solution feedback - I would greatly appreciate it. Thank you.
This is the code I have written so far:
T = 0.002; %sampling interval = 0.002
N = 1000; %Number of points = 1000
f = 4; %frequency = 4
b = 0; %bits = 0
t = (0:N-1)*T; %Vector used to generate a 1-cycle sine wave
Mx = 0; %I'm Initializing the maximum amplitude variable.
Mn = 0; %I'm Initializing the minimum amplitude variable.
for (b = 4: b<=16: b+4)
signal_in = sin(2*pi*frequency*t); %My input signal.
signal_out = quantization(signal_in, b); %Here, I am quantizing
%the output signal.
noisesignal = signal_out - signal_in; %This is my quantization error
%signal.
q_noise = var(noisesignal); %I'm calculating the variance
%of the quantization noise.
q = 1/(2^b - 1); %I'm calculating the quantization level.
theoretical = (q^2)/12; %I'm calculating the theoretical quantization
%error.
Mx = max(noisesignal); %I'm calculating the maximum amplitude
%of the quantization error signal.
Mn = min(noisesignal); %I'm calculating the minimum amplitude
%of the quantization error signal.
disp('Quantization Noise')
disp('Bits Empirical Theoretical')
out=sprintf('%2d %5e %5e', b, q_noise, theoretical);
%I'm Formatting my output
disp('Max Min')
out=sprintf('%2d %5e', Mx, Mn'); %I'm formatting my output for the max
%and min amplitudes of the quantization
%error signal.
disp(out)
end
0 comentarios
Respuestas (2)
Jim Riggs
el 1 de Feb. de 2018
The first thing I notice is that signal_in is computed from
signal_in = sin(2*pi*frequency*t)
but variable "frequency" is not defined. It is defined as "f" in your code. The code would not run with this error, so I assume that it has been fixed and this is not the problem.
To plot the signal, you must create a figure window:
figure;
plot(t,signal_in,'b') % blue line plot
hold;
plot(t,signal_out,'r'); % red line plot
plot(t,noise,'k'); % black line plot
grid;
legend ('Input', 'Quantized', 'Noise');
The other thing that looks suspicious to me is the "quantization" function. This does not look like a built-in function, so I assume it is a user function. The built in function "quant" requires the second input to be the quantization magnitude, so it would look like:
signal_out = quant(signal_in,q)
Does this help?
0 comentarios
Michael
el 1 de Feb. de 2018
3 comentarios
Jim Riggs
el 2 de Feb. de 2018
What I am saying is that you should verify that the function is giving the expected/desired output by plotting it along with the input signal. Does it look the way you expect it to look? Then you will know that it is working and being used correctly.
I recommend that you a) forget about the for loop until you can get a single case to work correctly. b) make the plots using the code I suggested above to verify the operation of your code.
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!