I want to write a code in which i could generate the hanning window with any frequency entered by the user
5 views (last 30 days)
Show older comments
I want to develop a code in which if i put the frequency in khz then repective hanning window or hanning wave could be genrated and corresponding wave plot should also generate the excel file.
0 Comments
Answers (1)
Pratheek
on 27 Mar 2023
Hi Sanket Shivaji
You can use the below code to generate Hanning Window for a input wave form. You can go through the comments to understand the code.
f_khz = input('Enter the frequency in kHz: '); % Getting the frequency in kHz
Fs = 10 * f_khz; % Use Sampling frequency as 10 times that of input frequency
duration = 1; % Duration of the waveform in seconds
N = Fs * duration; % Number of samples
t = linspace(0, duration, N); % Generating the time vector
x = sin(2 * pi * f_khz * t); % Generating the waveform
w = hann(N); % Generating the Hanning window
x_w = x .* w'; % Applying Hanning window to waveform
% Ploting the waveform
subplot(2,1,1);
plot(t, x);
title('Original Waveform');
xlabel('Time (s)');
ylabel('Amplitude');
% Plotting the Hanning window
subplot(2,1,2);
plot(t, x_w);
title('Waveform with Hanning Window');
xlabel('Time (s)');
ylabel('Amplitude');
% Save the waveform data to an Excel file
filename = sprintf('waveform_%dkHz.xlsx', f_khz);
xlswrite(filename, x_w', 'Sheet1');
0 Comments
See Also
Categories
Find more on Measurements and Feature Extraction in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!