Homeworks on FFT Instr. and Meas. for Communication Systems- Gianfranco Miele. Name Surname

Similar documents
Signal and Systems. Matlab GUI based analysis. XpertSolver.com

% Edit the above text to modify the response to help Video_Player. % Last Modified by GUIDE v May :38:12

LAMPIRAN 1. Percobaan

1. Peralatan LAMPIRAN

% Edit the above text to modify the response to help Principal

GUI code for different sections is in following sections

LISTING PROGRAM. % Edit the above text to modify the response to help cover. % Last Modified by GUIDE v Jun :24:43

LISTING PROGRAM. % UIWAIT makes pertama wait for user response (see UIRESUME) % uiwait(handles.figure1);

Ear Recognition. By: Zeyangyi Wang

A NEW MACHINING COST CALCULATOR (MC 2 )

Supplementary Information

We are IntechOpen, the world s leading publisher of Open Access books Built by scientists, for scientists. International authors and editors

OMR Sheet Recognition

1.Matlab Image Encryption Code

Lithium-Ion Battery Data. Management

Lampiran 1. Script M-File Global Ridge

LAMPIRAN A PROGRAM PELATIHAN DAN PENGUJIAN

Akkad Bakad Bambai Bo

PROGRAMMING IN MATLAB

ECE Fall 05. Undergraduate Research: Digital Signal Processing & Quantization Effects

Finding a Minimum Covering Circle Based on Infinity Norms

MV 1:00 1:05 1:00 1:05

Contents INTERFACING MATLAB WITH EMBEDDED SYSTEMS

Solving Sudoku with MATLAB

% --- Executes on button press in btn_gsn. function btn_gsn_callback(hobject, eventdata, handles) GaussianSpeckleNoise close AiSoftware;

.., 7. References. [ 1] 1 mage Analysis and Mathematical Morphology:J.Serra. [2] Erosion, dilation and related operators,by Mariusz Jankowski

Airfoil Boundary Layer Separation Prediction

LAMPIRAN A LISTINGPROGRAM

LAMPIRAN LISTING PROGRAM

LISTING PROGRAM. if nargout [varargout{1:nargout}] = gui_mainfcn(gui_state, varargin{:}); else gui_mainfcn(gui_state, varargin{:}); end

Main Form visual Studio

Parallel-connected solar arrays

COMPLETELY AUTOMATED PUBLIC TURING TEST TO TELL COMPUTERS AND HUMANS APART

GUI Signal Analysis and Filtering Design

ALGORITHMS AND INTERFACE FOR OCEAN ACOUSTIC RAY-TRACING (Developed in MATLAB)

MATLAB. Creating Graphical User Interfaces Version 7. The Language of Technical Computing

Real-Time IIR Digital Filters

Accepted by... John H. Lienhard V

Implementation of a Motion Detection System

1 Lab 3, Simulation of crank-piston system

Design of Automated Digital Eye Palpation Exam for Intraocular Pressure Measurement

Interactive Programs

MEASURING INTERFACIAL TENSION WITH THE PENDANT DROP METHOD

TREBALL FINAL DE GRAU

LOK-Viewer : Graphical Interface Application for Geomagnetic Data in Observatory Geomagnetic Lombok

IMAGE STEGANOGRAPHY USING DISCRETE COSINE TRNASFORM ALGORITHM

Basic Simulation Lab with MATLAB

Tutorial of Origin 7.0. Chuang Tan, Zheyun Liu

Exercises Unit 4. Graphics User Interface

Chapter 6 User-Defined Functions. dr.dcd.h CS 101 /SJC 5th Edition 1

Introduction To MATLAB Interactive Graphics

Still More About Matlab GUI s (v. 1.3) Popup Menus. Popup Menu Exercise. Still More GUI Info - GE /29/2012. Copyright C. S. Tritt, Ph.D.

Intel Quark microcontroller D2000 How to communicate with MATLAB over UART

Sandia National Laboratories: Implementation of and Experimenting with a Clustering Tool

Plotting using Matlab. Vytautas Astromskas

Special Topics II: Graphical User Interfaces (GUIs)

Blind to Change. More on Graphical User Interfaces. Exploring change blindness

Music 270a: Matlab Tutorial 3

Part #10. AE0B17MTB Matlab. Miloslav Čapek Viktor Adler, Pavel Valtr, Filip Kozák

Chapter 6 Data Acquisition and Spectral Analysis System high-speed digitizer card for acquiring time-domain data. The digitizer is used in

muse Capstone Course: Wireless Sensor Networks

Signals and Systems Profs. Byron Yu and Pulkit Grover Fall Homework 1

Spring 2010 Instructor: Michele Merler.

Data needs to be prepped for loading into matlab.

MP3 Speech and Speaker Recognition with Nearest Neighbor. ECE417 Multimedia Signal Processing Fall 2017

Introduction to. The Help System. Variable and Memory Management. Matrices Generation. Interactive Calculations. Vectors and Matrices

The Language of Technical Computing. Computation. Visualization. Programming. Creating Graphical User Interfaces Version 1

Laboratory 1 Introduction to MATLAB for Signals and Systems

How to learn MATLAB? Some predefined variables

Computing Fundamentals Plotting

George Mason University Signals and Systems I Spring 2016

GENDER ESTIMATION BASED ON FACIAL IMAGE AZLIN BT YAJID UNIVERSITI TEKNOLOGI MALAYSIA

1. Register an account on: using your Oxford address

SBT 645 Introduction to Scientific Computing in Sports Science #5

Plotting - Practice session

Some Matlab functions for random signals

ECE251DN: Homework #3 Solutions

Lab P-1: Introduction to MATLAB. 3. Learn a little about advanced programming techniques for MATLAB, i.e., vectorization.

CS/NEUR125 Brains, Minds, and Machines. Due: Wednesday, March 8

Advanced Digital Signal Processing Adaptive Linear Prediction Filter (Using The RLS Algorithm)

ECE4703 B Term Laboratory Assignment 2 Floating Point Filters Using the TMS320C6713 DSK Project Code and Report Due at 3 pm 9-Nov-2017

Practical 4: The Integrate & Fire neuron

ME 142 Engineering Computation I. Graphing with Excel

APPM 2460 PLOTTING IN MATLAB

Introduction to Medical Image Analysis Exercise 11 - Line and Path Tracing

Stokes Modelling Workshop

EE 350. Continuous-Time Linear Systems. Recitation 1. 1

W1005 Intro to CS and Programming in MATLAB. Data Structures. Fall 2014 Instructor: Ilia Vovsha. hep://

ELEC4042 Signal Processing 2 MATLAB Review (prepared by A/Prof Ambikairajah)

Assignment 2 in Simulation of Telesystems Laboratory exercise: Introduction to Simulink and Communications Blockset

MAT 275 Laboratory 1 Introduction to MATLAB

EE 301 Signals & Systems I MATLAB Tutorial with Questions

UNIVERSITÀ DEGLI STUDI DI PADOVA

QUIZ: What is the output of this MATLAB code? >> A = [2,4,10,13;16,3,7,18; 8,4,9,25;3,12,15,17]; >> length(a) >> size(a) >> B = A(2:3, 1:3) >> B(5)

Desktop Command window

Small rectangles (and sometimes squares like this

Mini-Project System Simulation over AWGN Using BPSK Modulation

BUILDING A MATLAB GUI. Education Transfer Plan Seyyed Khandani, Ph.D. IISME 2014

Matlab Tutorial. Get familiar with MATLAB by using tutorials and demos found in MATLAB. You can click Start MATLAB Demos to start the help screen.

MATLAB SUMMARY FOR MATH2070/2970

Transcription:

Homeworks on FFT 90822- Instr. and Meas. for Communication Systems- Gianfranco Miele Name Surname October 15, 2014 1

Name Surname 90822 (Gianfranco Miele): Homeworks on FFT Contents Exercise 1 (Solution)............................................ 3 (a)...................................................... 3 (b)...................................................... 3 (c)...................................................... 4 (d)...................................................... 6 (e)...................................................... 8 (f)...................................................... 9 (g)...................................................... 10 Exercise 2 (Solution)............................................ 13 List of Figures 1 s 1 (t) and s 2 (t) versus time...................................... 3 2 S 1 (f)................................................. 4 3 S 2 (f)................................................. 5 4 S 1 (f) evaluated considering two different transform lengths................... 6 5 S 2 (f) evaluated considering two different transform lengths................... 6 6 S 1 (f) evaluated considering two different windows........................ 7 7 S 2 (f) evaluated considering two different windows........................ 8 8 S tot (f) evaluated considering two different transform lengths. A rectangular window has been applied................................................. 9 9 S tot (f) evaluated considering two different transform lengths. A Hamming window has been applied................................................. 10 10 S 1 (f)................................................. 11 11 S 2 (f)................................................. 11 12 S 1 (f) evaluated considering two different windows (rectangular and Hanning windows).... 13 13 S 2 (f) evaluated considering two different windows (rectangular and Hanning windows).... 13 14 S 1 (f) evaluated considering two different windows (rectangular and flat-top windows)..... 14 15 S 2 (f) evaluated considering two different windows (rectangular and flat-top windows)..... 14 16 GUI implementing the frequency shift of a sinusoidal signal.................... 19 List of Tables Page 2 of 19

Name Surname 90822 (Gianfranco Miele): Homeworks on FFT Exercise 1 Exercise 1 (Solution) (a) The listing below shows the correct MATLAB script. A1=75; %amplitude of s_1(t) f1=609.36; %frequency of s_1(t) A2=1; %amplitude of s_2(t) f2=937.5; %frequency of s_2(t) 5 fs=6000; %sampling rate Ts=1/fs; %sampling period t=[0:ts:63*ts]; %time vector x1=a1*sin(2*pi*f1*t); %s_1 x2=a2*sin(2*pi*f2*t); %s_2 10 plot(t,x1, b, LineWidth,6) %plot of s_1(t) vs time hold on plot(t,x2, r, LineWidth,6) %plot of s_2(t) vs time 15 xlabel( Time [s], FontSize,22) %x-axis label ylabel( Amplitude [V], FontSize,22) %y-axis label legend( s_1(t), s_2(t) ) %legend Figure 1: s 1 (t) and s 2 (t) versus time (b) The listing below shows the correct MATLAB script. Exercise 1 continued on next page... Page 3 of 19

Name Surname 90822 (Gianfranco Miele): Homeworks on FFT Exercise 1 (continued) X1= f f t (x1)/length(x1); %FFT of s_1(t) X2= f f t (x2)/length(x2); %FFT of s_2(t) df=fs/length(x1); %frequency resolution 5 f=[0:length(x1)/2]*df; %vector of frequency bins plot(f,abs(x1(1:length(f))), b, LineWidth,6) %plot of S_1(f) ylabel( Magnitude [V], FontSize,22) 10 plot(f,abs(x2(1:length(f))), r, LineWidth,6) %plot of S_2(f) 15 ylabel( Magnitude [V], FontSize,22) Figure 2: S 1 (f) Regarding Figure 2, analyzing the above reported plot it is possible to highlight that S 1 (f) has the highest peak at 562.5 Hz and its value is 24.71 V and these values don t match with the expected results. In fact from the calculations S 1 (f) have a line spectrum composed by a single tone at 609.36 Hz and its value is 37.5 V. As far as Figure 3 goes, the highest peak is at 937.5 Hz and its value is 0.5 V and these values agree with that obtained from the calculations. In the first case, the analysis is affected by spectral leakage and the amplitude error is referred to as scalloping loss. (c) The listing below shows the correct MATLAB script. Exercise 1 continued on next page... Page 4 of 19

Name Surname 90822 (Gianfranco Miele): Homeworks on FFT Exercise 1 (continued) Figure 3: S 2 (f) X3= f f t (x1,1024)/length(x1); %new FFT of s_1(t) considering %a transform length of 1024 %samples 5 X4= f f t (x2,1024)/length(x1); %new FFT of s_2(t) considering %a transform length of 1024 %samples df=fs/1024; %new frequency resolution f3=[0:1024/2]*df; %new vector of frequency bins 10 plot(f,abs(x1(1:length(f))), b, LineWidth,6) %plot of S_1(f) hold on plot(f3,abs(x3(1:length(f3))), g, LineWidth,6) %new plot of S_1(f) 15 ylabel( Magnitude [V], FontSize,22) legend( 64-points, 1024-points ) %legend plot(f3,abs(x4(1:length(f3))), k, LineWidth,6) %plot of S_2(f) 20 hold on plot(f,abs(x2(1:length(f))), r, LineWidth,6) %new plot of S_2(f) ylabel( Magnitude [V], FontSize,22) 25 legend( 1024-points, 64-points ) %legend Using a higher transform length, we have improved the frequency resolution of our analysis, allowing to obtain a better magnitude estimation. Exercise 1 continued on next page... Page 5 of 19

Name Surname 90822 (Gianfranco Miele): Homeworks on FFT Exercise 1 (continued) Figure 4: S 1 (f) evaluated considering two different transform lengths Figure 5: S 2 (f) evaluated considering two different transform lengths (d) The listing below shows the correct MATLAB script. w=hamming(length(x1)) ; %window definition y1=x1.*w; %windowing s_1(t) y2=x2.*w; %windowing s_2(t) 5 Y1= f f t (y1)/sum(w); %FFT of the windowed signal Exercise 1 continued on next page... Page 6 of 19

Name Surname 90822 (Gianfranco Miele): Homeworks on FFT Exercise 1 (continued) %s_1(t) Y2= f f t (y2)/sum(w); %FFT of the windowed signal %s_2(t) plot(f,abs(x1(1:length(f))), b, LineWidth,6) %plot of S_1(f) 10 hold on plot(f,abs(y1(1:length(f))), r, LineWidth,6) %plot of S_1_windowed(f) ylabel( Magnitude [V], FontSize,22) 15 legend( Rectangular, Hamming ) %legend plot(f,abs(x2(1:length(f))), b, LineWidth,6) %plot of S_2(f) hold on 20 plot(f,abs(y2(1:length(f))), r, LineWidth,6) %plot of S_2_windowed(f) ylabel( Magnitude [V], FontSize,22) legend( Rectangular, Hamming ) %legend 25 Figure 6: S 1 (f) evaluated considering two different windows Regarding Figure 6, analyzing the above reported plot it is possible to highlight that S 1 (f) the Hamming window allows to improve the magnitude estimation. In fact in this case we can found a highest peak at 562.5 Hz with an amplitude value equal to 30.9 V. As a consequence, the measure is affected by scallop loss but its value is lower than that experienced considering a rectangular window. The Hamming window permits to reduce the spectral leakage. As far as Figure 7 goes, the highest peak is at 937.5 Hz and its value is 0.5 V and these values agree with that obtained from the calculations. Exercise 1 continued on next page... Page 7 of 19

Name Surname 90822 (Gianfranco Miele): Homeworks on FFT Exercise 1 (continued) Figure 7: S 2 (f) evaluated considering two different windows (e) The listing below shows the correct MATLAB script. s1=x1+x2; %new signal s_tot(t) S1= f f t (s1)/length(s1); %FFT of s_tot(t) plot(f,20*log10(abs(s1(1:length(f)))), b, LineWidth,6) %plot of S_tot(f) 5 hold on S2= f f t (s1,1024)/length(s1); %new FFT of s_tot(t) %considering a %transform length of 10 %1024 samples plot(f3,20*log10(abs(s2(1:length(f3)))), r, LineWidth,6) %new plot of S_tot(f) ylabel( Magnitude [dbv], FontSize,22) legend( 64-points, 1024-points ) 15 S3= f f t (s1.*w)/sum(w); %FFT of the windowed %version of s_tot(t) plot(f,20*log10(abs(s3(1:length(f)))), b, LineWidth,6) %plot of the FFT of the 20 %windowed version of %s_tot(t) hold on S4= f f t (s1.*w,1024)/sum(w); %new FFT of the 25 %windowed version %of s_tot(t) %considering a Exercise 1 continued on next page... Page 8 of 19

Name Surname 90822 (Gianfranco Miele): Homeworks on FFT Exercise 1 (continued) %transform length of %1024 samples 30 plot(f3,20*log10(abs(s4(1:length(f3)))), r, LineWidth,6) %plot of the new FFT %of the windowed %version of s_tot(t) ylabel( Magnitude [dbv], FontSize,22) 35 legend( 64-points, 1024-points ) Figure 8: S tot (f) evaluated considering two different transform lengths. A rectangular window has been applied. In Figure 9 the weaker signal is more visible. As a consequence, the Hamming window allows to distinctly measure the weaker signal. (f) The listing below shows the correct MATLAB script. fs1=3000; %new sampling rate Ts1=1/fs1; %new sampling period t1=[0:ts1:63*ts1]; %new vector of time samples x1b=a1*sin(2*pi*f1*t1); %resampled signal s_1(t) 5 x2b=a2*sin(2*pi*f2*t1); %resampled signal s_1(t) X1b= f f t (x1b)/length(x1b); %FFT of s1_(t) X2b= f f t (x2b)/length(x2b); %FFT of s1_(t) df1=fs1/length(x1b); %new frequency resolution 10 f4=[0:length(x1b)/2]*df1; %new vector of frequency bins plot(f4,abs(x1b(1:length(f4))), b, LineWidth,6) %plot of S_1(f) Exercise 1 continued on next page... Page 9 of 19

Name Surname 90822 (Gianfranco Miele): Homeworks on FFT Exercise 1 (continued) Figure 9: S tot (f) evaluated considering two different transform lengths. applied. A Hamming window has been ylabel( Magnitude [V], FontSize,22) 15 plot(f4,abs(x2b(1:length(f4))), r, LineWidth,6) 20 ylabel( Magnitude [V], FontSize,22) %plot of S_2(f) Using a sampling rate equal to 3000 Hz it is possible to avoid spectral leakage and it is proved by the Figures 10 and 11. (g) The listing below shows the correct MATLAB script. w=hann(length(x1)) ; y1=x1.*w; y2=x2.*w; %Hanning window %windowing s_1(t) %windowing s_2(t) 5 Y1= f f t (y1)/sum(w); %FFT of the windowed signal %s_1(t) Y2= f f t (y2)/sum(w); %FFT of the windowed signal %s_2(t) plot(f,abs(x1(1:length(f))), b, LineWidth,6) %plot of S_1(f) (rectangular 10 %window) hold on Exercise 1 continued on next page... Page 10 of 19

Name Surname 90822 (Gianfranco Miele): Homeworks on FFT Exercise 1 (continued) Figure 10: S 1 (f) Figure 11: S 2 (f) plot(f,abs(y1(1:length(f))), r, LineWidth,6) 15 ylabel( Magnitude [V], FontSize,22) legend( Rectangular, Hanning ) %plot of S_1(f) (Hanning %window) %legend 20 plot(f,abs(x2(1:length(f))), b, LineWidth,6) %plot of S_2(f) (rectangular Exercise 1 continued on next page... Page 11 of 19

Name Surname 90822 (Gianfranco Miele): Homeworks on FFT Exercise 1 (continued) hold on plot(f,abs(y2(1:length(f))), r, LineWidth,6) %window) 25 %window) xlabel( Frequency [Hz] ) ylabel( Magnitude [V] ) legend( Rectangular, Hanning ) %legend 30 w=flattopwin(length(x1)) ; y1=x1.*w; y2=x2.*w; %plot of S_2(f) (Hanning %Flat-Top window %windowing s_1(t) %windowing s_2(t) 35 Y1= f f t (y1)/sum(w); %FFT of the windowed signal %s_1(t) Y2= f f t (y2)/sum(w); %FFT of the windowed signal %s_2(t) plot(f,abs(x1(1:length(f))), b, LineWidth,6) %plot of S_1(f) (rectangular 40 %window) hold on plot(f,abs(y1(1:length(f))), r, LineWidth,6) 45 ylabel( Magnitude [V], FontSize,22) legend( Rectangular, Flat-Top ) %plot of S_1(f) (Flat-top %window) 50 plot(f,abs(x2(1:length(f))), b, LineWidth,6) %plot of S_2(f) (rectangular %window) hold on plot(f,abs(y2(1:length(f))), r, LineWidth,6) %plot of S_1(f) (Flat-top 55 %window) ylabel( Magnitude [V], FontSize,22) legend( Rectangular, Flat-Top ) As the results depicted in s 12 and 13 concern, it is possible to note that the Hanning window allows to improve the magnitude estimate, reducing the scallop loss. These effect is clearly visibile when the flat-top window is applied. In fact, analyzing the plot depicted in 14 we can measure a magnitude value equal to 37.46 V with a very low scallop loss. On the other hand we have to highlight that this window has a large main lobe not allowing an accurate frequency measurement. Page 12 of 19

Name Surname 90822 (Gianfranco Miele): Homeworks on FFT Exercise 2 Figure 12: S 1 (f) evaluated considering two different windows (rectangular and Hanning windows). Figure 13: S 2 (f) evaluated considering two different windows (rectangular and Hanning windows). Exercise 2 (Solution) The listing below shows the correct MATLAB script. function varargout = homework(varargin) % HOMEWORK MATLAB code for homework.fig % HOMEWORK, by itself, creates a new HOMEWORK or raises the existing % singleton*. 5 % Exercise 2 continued on next page... Page 13 of 19

Name Surname 90822 (Gianfranco Miele): Homeworks on FFT Exercise 2 (continued) Figure 14: S 1 (f) evaluated considering two different windows (rectangular and flat-top windows). Figure 15: S 2 (f) evaluated considering two different windows (rectangular and flat-top windows). % H = HOMEWORK returns the handle to a new HOMEWORK or the handle to % the existing singleton*. % % HOMEWORK( CALLBACK,hObject,eventData,handles,...) calls the local 10 % function named CALLBACK in HOMEWORK.M with the given input arguments. % % HOMEWORK( Property, Value,...) creates a new HOMEWORK or raises the % existing singleton*. Starting from the left, property value pairs are Exercise 2 continued on next page... Page 14 of 19

Name Surname 90822 (Gianfranco Miele): Homeworks on FFT Exercise 2 (continued) % applied to the GUI before homework_openingfcn gets called. An 15 % unrecognized property name or invalid value makes property application % stop. All inputs are passed to homework_openingfcn via varargin. % % *See GUI Options on GUIDE s Tools menu. Choose "GUI allows only one % instance to run (singleton)". 20 % % See also: GUIDE, GUIDATA, GUIHANDLES % Edit the above text to modify the response to help homework 25 % Last Modified by GUIDE v2.5 07-Oct-2014 23:45:16 % Begin initialization code - DO NOT EDIT gui_singleton = 1; gui_state = struct( gui_name, mfilename,... 30 gui_singleton, gui_singleton,... gui_openingfcn, @homework_openingfcn,... gui_outputfcn, @homework_outputfcn,... gui_layoutfcn, [],... gui_callback, []); 35 i f nargin && ischar(varargin{1}) gui_state.gui_callback = str2func(varargin{1}); end i f nargout 40 [varargout{1:nargout}] = gui_mainfcn(gui_state, varargin{:}); else gui_mainfcn(gui_state, varargin{:}); end % End initialization code - DO NOT EDIT 45 % --- Executes just before homework is made visible. function homework_openingfcn(hobject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. 50 % hobject handle to % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to homework (see VARARGIN) 55 % Choose default command line output for homework handles.output = hobject; % Update handles structure guidata(hobject, handles); 60 % UIWAIT makes homework wait for user response (see UIRESUME) % uiwait(handles.1); 65 % --- Outputs from this function are returned to the command line. function varargout = homework_outputfcn(hobject, eventdata, handles) Exercise 2 continued on next page... Page 15 of 19

Name Surname 90822 (Gianfranco Miele): Homeworks on FFT Exercise 2 (continued) % varargout cell array for returning output args (see VARARGOUT); % hobject handle to 70 % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; 75 function A_Callback(hObject, eventdata, handles) % hobject handle to A (see GCBO) 80 % handles structure with handles and user data (see GUIDATA) % Hints: get(hobject, String ) returns contents of A as text % str2double(get(hobject, String )) returns contents of A as a double 85 % --- Executes during object creation, after setting all properties. function A_CreateFcn(hObject, eventdata, handles) % hobject handle to A (see GCBO) 90 % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. i f ispc && isequal(get(hobject, BackgroundColor ), get(0, defaultuicontrolbackgroundcolor )) 95 set(hobject, BackgroundColor, white ); end 100 function f0_callback(hobject, eventdata, handles) % hobject handle to f0 (see GCBO) % handles structure with handles and user data (see GUIDATA) 105 % Hints: get(hobject, String ) returns contents of f0 as text % str2double(get(hobject, String )) returns contents of f0 as a double % --- Executes during object creation, after setting all properties. 110 function f0_createfcn(hobject, eventdata, handles) % hobject handle to f0 (see GCBO) % handles empty - handles not created until after all CreateFcns called 115 % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. i f ispc && isequal(get(hobject, BackgroundColor ), get(0, defaultuicontrolbackgroundcolor )) set(hobject, BackgroundColor, white ); end Exercise 2 continued on next page... Page 16 of 19

Name Surname 90822 (Gianfranco Miele): Homeworks on FFT Exercise 2 (continued) 120 function fs_callback(hobject, eventdata, handles) % hobject handle to fs (see GCBO) 125 % handles structure with handles and user data (see GUIDATA) 130 % Hints: get(hobject, String ) returns contents of fs as text % str2double(get(hobject, String )) returns contents of fs as a double % --- Executes during object creation, after setting all properties. function fs_createfcn(hobject, eventdata, handles) % hobject handle to fs (see GCBO) 135 % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. 140 i f ispc && isequal(get(hobject, BackgroundColor ), get(0, defaultuicontrolbackgroundcolor )) set(hobject, BackgroundColor, white ); end 145 150 function deltaf_callback(hobject, eventdata, handles) % hobject handle to deltaf (see GCBO) % handles structure with handles and user data (see GUIDATA) % Hints: get(hobject, String ) returns contents of deltaf as text % str2double(get(hobject, String )) returns contents of deltaf as a double 155 % --- Executes during object creation, after setting all properties. function deltaf_createfcn(hobject, eventdata, handles) % hobject handle to deltaf (see GCBO) % handles empty - handles not created until after all CreateFcns called 160 % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. i f ispc && isequal(get(hobject, BackgroundColor ), get(0, defaultuicontrolbackgroundcolor )) set(hobject, BackgroundColor, white ); 165 end % --- Executes on button press in pushbutton1. function pushbutton1_callback(hobject, eventdata, handles) 170 % hobject handle to pushbutton1 (see GCBO) % handles structure with handles and user data (see GUIDATA) Exercise 2 continued on next page... Page 17 of 19

Name Surname 90822 (Gianfranco Miele): Homeworks on FFT Exercise 2 (continued) axes(handles.axes1); cla; 175 A=str2num(get(handles.A, String )); f0=str2num(get(handles.f0, String )); fs=str2num(get(handles.fs, String )); delta_f=str2num(get(handles.deltaf, String )); 180 t=str2num(get(handles.t, String )); Ts=1/fs; t1=[0:ts:t]; x=a*sin(2*pi*f0*t1).*exp(-j*2*pi*(delta_f)*t1); X=abs( f f t (x))/length(x); 185 df=fs/length(x); f=(0:round(length(x)/2))*df; plot(f,x(1:length(f)), LineWidth,6) ylabel( Magnitude [V], fontsize,22) 190 xlabel( Frequency [Hz], fontsize,22) function t_callback(hobject, eventdata, handles) 195 % hobject handle to t (see GCBO) % handles structure with handles and user data (see GUIDATA) % Hints: get(hobject, String ) returns contents of t as text 200 % str2double(get(hobject, String )) returns contents of t as a double % --- Executes during object creation, after setting all properties. function t_createfcn(hobject, eventdata, handles) 205 % hobject handle to t (see GCBO) % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. 210 % See ISPC and COMPUTER. i f ispc && isequal(get(hobject, BackgroundColor ), get(0, defaultuicontrolbackgroundcolor )) set(hobject, BackgroundColor, white ); end The GUI is depicted in 16. Page 18 of 19

Name Surname 90822 (Gianfranco Miele): Homeworks on FFT Exercise 2 Figure 16: GUI implementing the frequency shift of a sinusoidal signal. Page 19 of 19