CS代写 EEEE3089 Seminar Lecture examples Week 2

EEEE3089 Seminar Lecture examples Week 2
Bit depth of a signal and sampling
An Analogue signal is to be digitised so that the AC part of the signal is represented by at least 10 levels. The ADC input range is 0-3.3V. The signal is of the form . There are 5 seconds of data sampled at 400Hz.
let’s code the signal

Copyright By PowCoder代写 加微信 powcoder

t = linspace(0,5-0.0025,2000); %make the time information 2000 samples, dt = 1/400 = 0.0025
dt=t(2)-t(1);
f = linspace(5,8,2000); % we’re not told the frequency, so could use a single F, but i m
S1 = 1.55+25e-3.*cos(2.*pi.*f.*t); %build the signal
plot(t,S1);
xlabel(‘time (s)’);ylabel(‘amplitude (V)’);
title(‘Signal to digitise’)
axis([0 5 0 3.3]); % add axis to represent the full range of the ADC and the time extent of th
clear variables
cd ‘C:\Users\eezrjs\OneDrive – The University of Nottingham\EEE Teaching\H63EFM’

We know from the equation AC is represented by 25mV .* Cos function
We know peak to peak is +/- 25mV giving 50mV range. 10 levels means LSB must represent
The number of levels is therefore:
Levels = 660
bits = log(Levels)/log(2)
bits = 9.3663
We need to round up (use ceil(bits)) to ensure we meet the spec
bits = ceil(bits)
lev = (range) / 2^bits;
Digitise the signal by converting to levels and rounding at LSB size
range=3.3-0;
Levels = (range)/5e-3
D1 = round(S1./lev);
D1a = (D1/2^bits)*range;
plot(t,S1,t,D1a);
xlabel(‘time (s)’);ylabel(‘amplitude (V)’);
title(‘Signal and digitised version’);legend(‘S1′,’D1’)
axis([0 5 0 3.3]);

%Zoom in to check
axis([0 0.2 1.5 1.6]);

number_of_levels=50e-3/lev
number_of_levels = 15.5152
Trends examples
Let’s look at a coupe of signals and decide how we might remove a trend from them.
[signal,signal2,signal3,t] = SeminarExamples_make_signals;
plot(t,signal);
xlabel(‘time (s)’);ylabel(‘Amplitude (V)’);
title(‘Signal 1’);

How could we remove this linear trend line from the signal?
by inspection we can see there is a linear ramp on the signal. use the data tips we see at t=0, that the signal is at 1.5, and at t = 1.5s the value is 4.5. This implies we have a gradient of dy/dt of (4.5-1.5)/1.5 = 3/1.5 = 2;
plot(t,signal-2.*t); xlabel(‘time (s)’);ylabel(‘Amplitude (V)’); title(‘Signal 1 – 2*t’);

We still have a DC offset. This could be part of the signal (it’s not changing so it’s not a trend, so this could be removed. This depends on what you are doing with the signal afterwards – does your ADC have +/-V operation? is it going to be amplified where the DC will limit the size of gain you can apply?
what about this signal?
plot(t,signal2);
xlabel(‘time (s)’);ylabel(‘Amplitude (V)’);
title(‘Signal 2’);

plot(t,signal3);
xlabel(‘time (s)’);ylabel(‘Amplitude (V)’);
title(‘Signal 3’);

How could we remove non-linear or the in-band contaminant from the signal? This is related to the formatiave exercise Q1.
Frequency domain examples
Let look at the time trace and the FFT of signal 3 from above
zp=length(signal3);
fx = xtof(t);
f = (1/zp)*abs(fft(signal3,zp));
subplot(2,1,1);plot(t,signal3);xlabel(‘time (s)’);ylabel(‘Amplitude (V)’);
title(‘Signal 3′);
subplot(2,1,2);plot(fx,fftshift(f),’.-‘); xlabel(‘Frequency (Hz)’);ylabel(‘Amplitude (V)’);
title(‘Spectrum of Signal 3’);
axis([0 250 0 1.6 ])

here we see we have large DC (~1.5) as expected, the other features hard to see
subplot(2,1,1);plot(t,signal3);xlabel(‘time (s)’);ylabel(‘Amplitude (V)’);
title(‘Signal 3′);
subplot(2,1,2);plot(fx,fftshift(f),’.-‘); xlabel(‘Frequency (Hz)’);ylabel(‘Amplitude (V)’);
title(‘Spectrum of Signal 3’);
axis([0 250 0 0.15 ])

zoom in to see the small peak, the broad flat part and the noise
subplot(2,1,1);plot(t,signal3);xlabel(‘time (s)’);ylabel(‘Amplitude (V)’);
title(‘Signal 3′);
subplot(2,1,2);plot(fx,fftshift(f),’.-‘); xlabel(‘Frequency (Hz)’);ylabel(‘Amplitude (V)’);
title(‘Spectrum of Signal 3’);
axis([0 30 0 0.15 ])

zoom in more we see the peak is poorly sampled – hard to determine the frequency. from the time domain signal we can see if the FFT makes sense.
• the time domain signal has a DC offset
• it has a sinusoisal components throughout • a chirped signal in the centre
• random noise throughout.
What should be expect in the FFT
• DC will give a spike at 0Hz – present
• sinusoidal component will give a spike at the frequency – present, although currently hard to determine
the frequency exactly due to sampling.
• the centre chirp region, is effectively a chirp mulitplied by a rectangular window, so we should expect a
broad frequency response convovled with a sinc function, so we expect the edges to tail off – this is what we see.
Power of 2 and timing code
Lets time how long some code takes to run and see what happens if we have a non power of 2 signal length. What do we expect to see?

for k = 1:1000
f = (1/3000)*abs(fft(signal3,zp));
Elapsed time is 0.278017 seconds.
Elapsed time is 1.181258 seconds.
We see adding 1 more point 16384 vs 16385 increases the compute time by ~2.5 times
Zero padding to powers of 2 is therefore sensible. We should expect this as the FFT is highly optimised, if the FFT cannot be used, then the DFT is used and this is slower to compute.
If we re-run with only one compuation – timing is not as reliable. overheads and setup can greatly influence the time and so it appears there is less impact. This is not the case if you are repeating the calculations many times.
for k = 1:1000
f = (1/3000)*abs(fft(signal3,zp+1));

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com