GUI Development using MATLAB for FFT
-
Upload
binayakojha -
Category
Documents
-
view
149 -
download
7
description
Transcript of GUI Development using MATLAB for FFT
Development and Implementation of GUI using MATLABof GUI using MATLAB
for Fast Fourier Transformation
Presented by:
Binayak Ojha
Date: 09.05.2013
1. Motivation2. Objectives3. Discrete Fourier Transform (DFT)4. Fast Fourier Transform (FFT)5. Windowing5. Windowing
5.1 Rectangular Window5.2 Hamming Window5.3 Hanning Window
6. Some MATLAB Functions7. GUI-control Elements8. GUI-control Elements Properties9. GUIDE
9.1 Layout Editor9.2 Property Inspector9.3 Object Browser9.4 Menu Editor
10. GUI Layout Design10. GUI Layout Design11. Algorithm for designed GUI12. Use of CallBack Function13. MATLAB code for FFT14. Output Snapshots15. ConclusionReferences
•Need of some simulations for demonstration.
•To develop and implement GUI for FFT
Other requirements1.Two separte plots for input and output signal.2.Cosine signal as input signal.2.Cosine signal as input signal.3.Frequency spectrum of FFT of input as output.4.Demonstration of leakage effect.5.Windowing demonstration6.Sliders to change input and output signal characteristics.
• A signal can be collection of frequency components.•Extracts the signal component F(ω) at frequency ωMathematically represented as,
f[k] : discrete signalN: Number of samples
•Algorithm to calculate DFT fast and efficiently. •First published in 1965 by Cooley and Tuckey.•Applies only to signals with elements 2m.•FFT returns set of complex numbers.•But, real numbers for f=0 and f= fs /2.•But, real numbers for f=0 and f= fs /2.
•Output spectrum of DFT has spectral leakage.•Windowing minimize spectal leakage.•DFT of x[i]×w[i] is done. •Different types of window functions available.1.Rectangular Window2.Hanning Window1.Rectangular Window2.Hanning Window3.Hamming Window
W[n] = 1 for n ≤ N= 0 for n > N
^
Figure 1 : Cosine Signal in Rectangular Window
W[n] = 0.5- 0.5 cos for n ≤ N= 0 for n > N
Figure 2: Cosine Signal in Hanning Window
W[n] = 0.53836 - 0.46164 cos for n ≤ N= 0 for n > N
Figure 3: Cosine Signal in Hamming Window
Y = fft(x)returns the DFT of vector x, “[2]”.
w = hamming(L)returns an L-point symmetric Hamming window in returns an L-point symmetric Hamming window in the column vector w, “[2]”.
w = hann(L) returns an L-point symmetric Hann window in the column vector w, “[2]”.
Table 1: MATLAB GUI-Control Elements “[4]”
S.N UI Control Style Value Description
1 Check Box ‘checkbox’ Indicates the states of an option
2 Editable Text ‘edit’ User editable text box
3 Frame ‘frame’ Usedto groupthecontrols3 Frame ‘frame’ Usedto groupthecontrols
4 Pop-up Menu ‘popup’ Provides the list of options
5 List Box ‘listbox’ Shows scrollable list of options
6 Push Button ‘pushbutton’ Invokes an event immediately
7 Radio Button ‘radio’ Indicates selectable options
8 Toggle Button ‘toggle’ Two states, “ON” or “OFF”
9 Slider ‘slider’ Represents a range of values
10 Static Text ‘text’ Displays a string in a box
Table 2a:GUI-Control Elements Properties “[4]”
S.N. Property S.N. Property
1 BackgroundColor 8 FontName
2 ButtonDownFcn 9 FontSize
3 CData 10 FontUnits3 CData 10 FontUnits
4 CallBack 11 FontWeight
5 Enable 12 ForegroundColor
6 Extent 13 HorizontalAlignment
7 FontAngle 14 Interruptible
Table 2b: GUI-Control Elements Properties “[4]”
S.N. Property S.N. Property
15 ListBoxTop 22 TooltipString
16 Max 23 Units
17 Min 24 UIContextMenu17 Min 24 UIContextMenu
18 Position 25 Value
19 String 26 Tag
20 Style 27 UserData
21 SliderStep 28 Visible
•Stands for GUI Development Enviornment•MATLAB tool to create GUI•Easy to use
Components of GUIDE1.Layout EditorComponents of GUIDE1.Layout Editor2.Property Inspector3.Object Browser4.Menu Editor
Figure 4: GUIDE Layout Editor
Figure 5: GUIDE Property Inspector
Figure 6: GUIDE Object Browser
Figure 7: GUIDE Menu Editor
Figure 8: GUI Layout
Step 1: StartStep 2: Set the value of slider 1, slider 2, slider 3
and slider 4 to zero.Step 3: Reset Hanning and Hamming Window.Step 4: Compute FFT length using slider 4 value and
show in edit text box 4.Step 4: Compute FFT length using slider 4 value and
show in edit text box 4.Step 5: Set the rectangular window.Step 6: Show slider 1, slider 2, and slider 3 values in
edit text box 1, edit text box 2 and edit text box 3 respectively.
Step 7: Compute FFT length using slider 4 value and show in edit text box 4.
Step 8: Compute input signal array for currently active window and current sliders values.
Step 9: Compute FFT and output signal array.Step 10: Plot input signal in axes 1 and output signal
in axes 2.Step 11: If slider 1 or slider 2 or slider 3 or slider 4
in axes 2.Step 11: If slider 1 or slider 2 or slider 3 or slider 4
has new value then go to step 4.Step 12: If edit text box 1 or edit text box or edit text
box 3 or edit text box 4 have new value, set the value of respective slider. Go to step 6.
Step 13: If Hanning window is set, reset the hamming window and rectangular window.
Go to step 8.Step 14: If Hamming window is set, reset the
hanning window and rectangular window. Goto step 8.
Step 15: If hanning and hamming both are reset, compute rectangular window vector.
Step 15: If hanning and hamming both are reset, compute rectangular window vector. Goto step 8.
Step 16: Stop
•An important property of a GUI Element•Indicates actions to be performed when activated
function slider1_Callback(hObject, eventdata, handles)
set(handles.edit3,'string',(int32(get(handles.slider1,'value'))));
Figure 9: Implementation of Callback Function
set(handles.edit3,'string',(int32(get(handles.slider1,'value'))));
my_task(get(handles.slider1,'value'),get(handles.slider3,'value'),get(ha
ndles.slider6,'value'),get(handles.slider7,'value'));
k=fft_length(s3) ; % function fft_length() returns number of fft points
if k >1
fftval=fft(x,k); % calculate array of fft for k points
indexnyquist=(k/2)+1; %centre FFT point
fftval=fftval(1:indexnyquist); %truncate the negative parts
k=cast(k,'double');
Figure 10: Implementation of FFT
k=cast(k,'double');
fftval=fftval/k; %scale
%whos k
fftval(2:end)=2*fftval(2:end); %compensate for truncating
df=fs/k ; %discrete frequency interval
frequency_axis=(0:indexnyquist-1)*df; %array of frequency to plot
magnitude=abs(fftval); % magnitude of spectrum
plot_output(frequency_axis,magnitude); % plot the fft in frequency spectrum
Figure 11: Output snapshot 1
Figure 12: Output snapshot 2
•GUIDE is a good tool for GUI designing. •GUI for FFT was developed and implemented.•GUI for other complex processes can be developed.
1.www.mathworks.de/academia/student_center/tutorials2.www.mathworks.com3.Discrete Time Signal Processing, Second Edition, Allan V Oppenheim4.Graphics and GUIs with MATLAB, Third Edition, Patrick Marchand & O. Thomas HollandMarchand & O. Thomas Holland