Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

1- Sampling frequency and correct signal plotting

%% Sampling frequency and correct signal plotting


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
L = 800; % length of x axes
Fs = 1e3 ; %sampling frequency ,
Ts = 1/Fs;
t = (0:L-1)*Ts; % vector for x axes used when you plot the signal
f = 350; % frequecny og the plotted signal
y = .5*cos(2*pi*f*t);
figure(1);
plot(t,y) % plot only the signal on t,y axes
title("Fs = " + string(Fs))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
L = 800;
Fs = 1.5e3 ;
Ts = 1/Fs;
t = (0:L-1)*Ts;
f = 350;
y = .5*cos(2*pi*f*t);
figure(2);
plot(t,y) % plot only the signal on t,y axes
title("Fs = " + string(Fs))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
L = 800;
Fs = 4e3 ;
Ts = 1/Fs;
t = (0:L-1)*Ts;
f = 350;
y = .5*cos(2*pi*f*t);
figure(3);
plot(t(300:450),y(300:450))
title("Fs = " + string(Fs))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%55
L = 800;
Fs = 8e3 ;
Ts = 1/Fs;
t = (0:L-1)*Ts;
f = 350;
y = .5*cos(2*pi*f*t);
figure(4);
plot(t,y) % plot only the signal on t,y axes
title("Fs = " + string(Fs))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
L = 800;
Fs = 16e3 ;
Ts = 1/Fs;
t = (0:L-1)*Ts;
f = 350;
y = .5*cos(2*pi*f*t);
figure(5);
plot(t,y) % plot only the signal on t,y axes
title("Fs = " + string(Fs))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5
L = 800; % length of x axes
Fs = 24e3 ; %sampling frequency ,
Ts = 1/Fs;
t = (0:L-1)*Ts; % vector for t axes. it also used when you plot the signal
f = 350; % frequecny og the plotted signal
y = .5*cos(2*pi*f*t);
figure(6);
plot(t,y) % plot only the signal on t,y axes
title("Fs = " + string(Fs))
%%

in the plotted figures we must have Fs > 2* (signal frequency). But for "relatively" lower sampling frequencies, although these
frequencies are higher than the minimum required frequencies to not have to alias, it can't be visualized correctly, because
the plot command fills the space between sample points.
1- AM modulation example
Ac = Amplitude of the carrier signal

Am = Amplitude of the message signal

fc = frequency of the carrier signal

fm = frequency of the message signal

Yc = Carrier signal

Ym = Message signal

MATLAB CODE
We need to know the amplitude and frequency of the carrier signal and message signal.
So we will ask to user for the Frequency and Amplitude of the carrier signal and message
signal. The frequency of the message signal cannot be greater than the frequency of the
carrier signal. So, if the user entered a frequency of message signal that is greater than the
carrier signal then we will show that invalid. How long the frequency of the message signal
is not less than the frequency of the carrier signal we should reject that. We need a fixed
period for those signals.

T = input('Time Period: ');

We need to find the time domain values. We will find it from the fraction below.

t = 0:0.001:T;

Now, derive the message signal as below.

Ym = Am.*sin(2*pi*fm*t);

Make a subplot as 3 by 1 size. Place the message signal (upcoming) to first subplot. Set
the title.

subplot(3, 1, 1);
plot(t, Ym);
title('Message Signal');

Now, derive the carrier signal as below.

Yc = Ac.*sin(2*pi*fc*t);

Place the carrier signal (upcoming) to second subplot. Set the title.

subplot(3, 1, 2);
plot(t, Yc);
title('Carrier Signal');

Now, Derive the modulated signal.

Z = (Ac + Ym).*Yc;

Place the modulated signal (upcoming) to third subplot. Set the title.

subplot(3, 1, 3);
plot(t, Z, 'r');
title('Modulated Signal');

3. Filter Design
Filter design methods differ primarily in how performance is specified. For “loosely specified” requirements, as in the
first case above, a Butterworth IIR filter is often sufficient.

To design a fifth-order 30 Hz lowpass Butterworth filter and apply it to the data in vector x,

[b,a] = butter(5 , 30/50);

y = filter(b,a,x);

The second input argument to butter specifies the cutoff frequency, normalized to half the sampling frequency (the
Nyquist frequency). Frequency Normalization in the Signal Processing Toolbox All of the filter design functions operate
with normalized frequencies, so they do not require the system sampling rate as an extra input argument. This toolbox
uses the convention that unit frequency is the Nyquist frequency, defined as half the sampling frequency. The
normalized frequency, therefore, is always in the interval 0 ≤ f ≤ 1. For a system with a 1000 Hz sampling frequency, 300
Hz is 300/500 = 0.6. To convert normalized frequency to angular frequency around the unit circle, multiply by π. To
convert normalized frequency back to hertz, multiply by half the sample frequency

You might also like