%HELSINKI UNIVERSITY OF TEHNOLOGY
%Communications Laboratory
%Seppo Saastamoinen 5.2.2005

%S-72.060 SIGNALS AND SYSTEMS
%Laboratory work 3: STUDYING OF PULSES AND RANDOM SIGNALS
%Makro: distortion.m

clear all; close all; %Clear all variables and figures.

Fs = 100000; %Sample frequency
t = (0:1/Fs:1-1/Fs); %Duration of the signal is 1 s.
N = max(size(t)); %Number of samples.

%Input signal:
xt = ?; %GIVE HERE THE FORMULA FROM YOUR PRELIMIARY WORK!

%Distorted output signal
yt = xt+0.1*(xt.*xt);

%Amplitude spectrums in one sided frequency domain, values also in dBV´s.
Xf = abs(fft(xt))*2/N; Yf = abs(fft(yt))*2/N;
XfdBV = 20*log10(Xf); YfdBV = 20*log10(Yf);

%Here frequency domain is done:
f0 = Fs/N; %Frequency step
f = 0:f0:Fs-f0; %Frequency vector (domain)

%Plotting section.

subplot(2,3,1); plot(t,xt); axis([0 .01 -8 8]);
xlabel('Time/s'); ylabel('Input voltage/V');
grid on; zoom on;

%Please change some of the follwing parameters to be right at the moment work is done!
title({'Sum of cosine waves and non-linear system','Assistant: N.N.','Student numbers and names and date'});

subplot(2,3,2); plot(f,Xf); axis([-100 5000 0 5]);
xlabel('Frequency/Hz'); ylabel('Input voltage/V/Hz');
grid on; zoom on;

subplot(2,3,3); plot(f,XfdBV); axis([-100 5000 -60 12]);
xlabel('Frequency/Hz'); ylabel('Input voltage/dBV/Hz');
grid on; zoom on;

subplot(2,3,4); plot(t,yt); axis([0 .01 -8 8]);
xlabel('Time/s'); ylabel('Output voltage/V');
grid on; zoom on;

subplot(2,3,5); plot(f,Yf); axis([-100 5000 0 5]);
xlabel('Frequency/Hz'); ylabel('Output voltage/V/Hz');
grid on; zoom on;

subplot(2,3,6); plot(f,YfdBV); axis([-100 5000 -60 12]);
xlabel('Frequency/Hz'); ylabel('Output voltage/dBV/Hz');
grid on; zoom on;

shg;
