DSP Exp6
DSP Exp6
subplot(3,1,2);
plot(f(1:N/2), Y_mag); % Plot the magnitude spectrum
title('Spectral Analysis (FFT)');
xlabel('Frequency (Hz)');
ylabel('Magnitude');
grid on;
% Generate Spectrogram
subplot(3,1,3);
spectrogram(y, 256, 200, 256, fs, 'yaxis'); % Spectrogram plot
title('Spectrogram');
colorbar;
B. SQUARE WAVE
% Parameters
Fs = 1000; % Sampling frequency in Hz
T = 1; % Signal duration in seconds
f_square = 50; % Frequency of square wave in Hz
t = 0:1/Fs:T-1/Fs; % Time vector
C.AUDIO FILE
PROGRAM:
clc;
clear all;
close all;
% Read the audio file
[audio, fs] = audioread('sample.wav');
% Plot the audio input graph
t = (0:length(audio)-1)/fs;
figure;
plot(t, audio);
title('Audio Input Signal');
xlabel('Time (s)');
ylabel('Amplitude');
% Perform the Fast Fourier Transform (FFT)
n = length(audio);
f = (0:n-1)*(fs/n);
audio_fft = abs(fft(audio));
% Plot the spectral analysis
figure;
plot(f(1:n/2), audio_fft(1:n/2));
title('Spectral Analysis');
xlabel('Frequency (Hz)');
ylabel('Magnitude');
% Plot the spectrogram
figure;
spectrogram(audio(:,1), 256, 250, 256, fs, 'yaxis');
title('Spectrogram');